Skip to content

MyXoToD/eleventy-plugin-furigana

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eleventy-plugin-furigana

Eleventy plugin that adds a filter to parse content for kanji followed by []-brackets containing hiragana and converts it to furigana.

{{ '私[わたし]の名前[なまえ]はマックスです。' | furigana | safe }}

will produce this:

image

NPM Version NPM Downloads npm bundle size (scoped version)

Usage

Install this package

npm install --save-dev @myxotod/eleventy-plugin-furigana

Add and register the plugin inside your .eleventy.js config file

// .eleventy.js
const furigana = require("@myxotod/eleventy-plugin-furigana");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(furigana);
};

Finally use it in your code with the furigana-filter

{{ content | furigana | safe }}

Example

{{ '<p>私[わたし]<p>' | furigana | safe }}

<!-- will become -->

<p><ruby><rp>(</rp><rt>わたし</rt><rp>)</rp></ruby></p>

Options

You can pass several options when adding the plugin in your eleventy config file like so:

eleventyConfig.addPlugin(furigana, {
  verbose: false
});
Option Default Type Description
class furigana String Provide a custom class for the surrounding <ruby> tag
regex /([\u4E00-\u9FAF\u3040-\u3096\u30A1-\u30FA\uFF66-\uFF9D\u31F0-\u31FF]{1})\[(.*?)\]/g Regex Pattern Pattern to parse kanji
verbose false Boolean Output additional data to your terminal when an eleventy build happens

License

MIT @ Maximilian Boll