1.2.2 • Published 16 days ago

react-furigana v1.2.2

Weekly downloads
-
License
MIT
Repository
gitlab
Last release
16 days ago

react-furigana

A simple React component designed for handling Japanese text with furigana annotations.

Usage

import ReactFurigana from 'react-furigana';

function MyComponent() {
    return <ReactFurigana text="漢[かん]字[じ]は難[むずか]しい。"/>;
}

renders

かんむずかしい。

<ruby>
    漢
    <rt>
        かん
    </rt>
    字
    <rt>
        じ
    </rt>
</ruby>
は
<ruby>
    難
    <rt>
        むずか
    </rt>
</ruby>
しい。

You can use a space ' ' to force split the input into individual tokens, e.g.

import ReactFurigana from 'react-furigana';

function MyComponent() {
    return <ReactFurigana text="日本 語[ご]"/>;
}

will render

日本

日本
<ruby>
    語
    <rt>
        ご
    </rt>
</ruby>

Props

  • text (required): the Japanese text to be processed.
  • separator (optional, default: ' '): used to force split the input text into individual tokens.
  • leftBracket (optional, default: '['): used to indicate the start of furigana.
  • rightBracket (optional, default: ']'): used to indicate the end of furigana.
  • render (optional): custom rendering of each token.

Custom render function

Don't want to use ruby? You can provide a custom render function to control how tokens are displayed, e.g.

<ReactFurigana
    text="日本語[にほんご]"
    render={token => (
        <div>
            <span className="kanji">
                {token.kanji}
            </span>
            <span className="furigana">
                {token.furigana}
            </span>
        </div>
    )}
/>

License

This project is licensed under a MIT License.

1.2.2

16 days ago

1.2.1

3 months ago

1.2.0

5 months ago

1.1.3

5 months ago

1.1.1

5 months ago

1.1.2

5 months ago

1.1.0

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago