@paulbarre/wc-furigana
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Furigana

Built With Stencil

This Web Component is the easiest way to write japanese with furigana.

In HTML if you want to display (かん)() you need to write:

<ruby><rp>(</rp>
  <rt>かん</rt>
  <rp>)</rp>
</ruby>
<ruby><rp>(</rp>
  <rt></rt>
  <rp>)</rp>
</ruby>

Disclaimer
Yes. rp tags are not a compulsory. 😀

With Furigana Web Component, things become easy:

<wc-furigana value="漢[かん]字[じ]" />

Check out how to use the component in details here: Furigana.

TL;DR

  1. Write furigana inside square brackets: 桜[さくら].
  2. Spaces will indicate which characters the furigana are above: 私[わたし]はフランス 人[じん]です。.
  3. Double spaces if you want to display a space character: 一 二 三.

Framework integrations

Note
The following applies the support for IE11, see below if you don't care about it.

Vue

The following consider an application created with Vue CLI.

  1. Install the package
npm i @paulbarre/wc-furigana
  1. Modify the main file of your application to import the package:

main.js or main.ts if you are using TypeScript

import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'

// The following can be set into your `vue.config.js` file
Vue.config.ignoredElements = [/wc-furigana/]

applyPolyfills().then(() => {
  defineCustomElements(window)
})
  1. Add a wc-furigana to App.vue to see if the component is correctly loaded

If the above doesn't work, check out Stencil documentation about integration into a Vue app.

Vuepress

  1. Install the package
npm i @paulbarre/wc-furigana
  1. If you don't have it already, create a configuration file. From root folder add a .vuepress subfolder and create config.js.

  2. Add headers to this configuration file.

module.exports = {
    head: [
        ['script', {
            type: 'module',
            src: 'https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.esm.js'
        }],
        ['script', {
            nomodule: true,
            src: 'https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.js'
        }]
    ]
}

Example
You can run the example in examples folder with npm run serve.

Angular

The following consider an application created with Angular CLI.

  1. Install the package
npm i @paulbarre/wc-furigana
  1. You first need to add CUSTOM_ELEMENTS_SCHEMA to your application:

app.module.ts

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

@NgModule({
  ...

  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
  1. Modify the main file to import the package:

main.ts

import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'

applyPolyfills().then(() => {
  defineCustomElements(window)
})
  1. Add a wc-furigana to app.component.html to see if the component is correctly loaded

If the above doesn't work, check out Stencil documentation about integration into an Angular app.

React

The following consider an application created with Create React App.

  1. Install the package
npm i @paulbarre/wc-furigana
  1. Import the package into index.js
import { applyPolyfills, defineCustomElements } from '@paulbarre/wc-furigana/loader'

applyPolyfills().then(() => {
  defineCustomElements(window)
})
  1. Add a wc-furigana to App.js to see if the component is correctly loaded

If the above doesn't work, check out Stencil documentation about integration into a React app.

I don't care about IE11

If you don't need to support IE11, no need to apply Polyfills:

import { defineCustomElements } from '@paulbarre/wc-furigana/loader'
defineCustomElements(window)

I don't use a framework

Adding the Web Component into a single file without any framework is also possible

<!DOCTYPE html>
<html lang="en">
<head>
  <script type="module" src="https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.esm.js"></script>
  <script nomodule src="https://unpkg.com/@paulbarre/wc-furigana@latest/dist/furigana/furigana.js"></script>
</head>
<body>
  <wc-furigana value="漢[かん]字[じ]" />
</body>
</html>

Examples

Check out the folder examples to see how to integrate the component.

Package Sidebar

Install

npm i @paulbarre/wc-furigana

Weekly Downloads

16

Version

1.0.1

License

MIT

Unpacked Size

660 kB

Total Files

62

Last publish

Collaborators

  • paulbarre