1.1.2 • Published 7 months ago
markdown-it-ruby v1.1.2
markdown-it-ruby
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
ESM (Recommended)
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. |