markdown-it-ruby

1.1.2 • Public • Published

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

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.

License

MIT

Package Sidebar

Install

npm i markdown-it-ruby

Weekly Downloads

473

Version

1.1.2

License

MIT

Unpacked Size

21.3 kB

Total Files

11

Last publish

Collaborators

  • lost_and_found