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:
Install this package
npm install --save-dev @myxotod/eleventy-plugin-furiganaAdd 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 }}{{ '<p>私[わたし]<p>' | furigana | safe }}
<!-- will become -->
<p><ruby>私 <rp>(</rp><rt>わたし</rt><rp>)</rp></ruby></p>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 |
