Skip to content

lostandfound/markdown-it-ruby

Repository files navigation

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

About

Ruby annotation plugin for markdown-it parser.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •