npm.io
1.1.2 • Published 1 year ago

markdown-it-ruby

Licence
MIT
Version
1.1.2
Deps
0
Size
21 kB
Vulns
0
Weekly
0
Stars
36

markdown-it-ruby

NPM version

Ruby annotations (<ruby>) tag plugin for markdown-it markdown parser.

{ruby base|ruby text} => <ruby>ruby base<rt>ruby text</rt></ruby>

Markup is based on DenDenMarkdown definition.

Install

npm install markdown-it-ruby --save

Usage

import MarkdownIt from 'markdown-it';
import rubyPlugin from 'markdown-it-ruby';

const md = new MarkdownIt().use(rubyPlugin);
md.render('{ruby base|ruby text}'); // => '<p><ruby>ruby base<rt>ruby text</rt></ruby></p>'
CommonJS
const MarkdownIt = require('markdown-it');
const rubyPlugin = require('markdown-it-ruby');

const md = new MarkdownIt().use(rubyPlugin);
md.render('{ruby base|ruby text}'); // => '<p><ruby>ruby base<rt>ruby text</rt></ruby></p>'
Options

You can pass options to the plugin:

const md = new MarkdownIt().use(rubyPlugin, {
  rp: ['(', ')'] // Add parentheses around ruby text
});

// Output: <ruby>漢字<rp>(</rp><rt>かんじ</rt><rp>)</rp></ruby>
md.render('{漢字|かんじ}');
Available Options
Option Type Default Description
rp [string, string] ['', ''] Array of opening and closing parentheses to wrap around ruby text. When both values are empty strings, no rp elements will be output.

License

MIT

Keywords