An open API service indexing awesome lists of open source software.

https://github.com/seangenabe/rubyfy

Easily write ruby annotations and output them as HTML.
https://github.com/seangenabe/rubyfy

html parser ruby-annotation

Last synced: 6 months ago
JSON representation

Easily write ruby annotations and output them as HTML.

Awesome Lists containing this project

README

        

# rubyfy

Easily write ruby annotations and output them as HTML.

[![npm](https://img.shields.io/npm/v/rubyfy.svg?style=flat-square)](https://www.npmjs.com/package/rubyfy)
[![node](https://img.shields.io/node/v/rubyfy.svg?style=flat-square)](https://nodejs.org/en/download/)

## Usage

```javascript
import { rubyfy } from "rubyfy"
```

Convert a string by wrapping the ruby text in full-width parentheses `()`:

```javascript
rubyfy('日(に)本(ほん)語(ご)')
// => 日(に)本(ほん)語(ご)
```

The type of the return value is an array of DOM `Node`s, which should be compatible with libraries like [bel](https://www.npmjs.com/package/bel).

Any string of numerals 0-9, CJK characters, and the characters `々` and `ヶ`, will be captured.

```javascript
rubyfy('今日(きょう)')
// => 今日(きょう)
```

Force a portion of the text to be the ruby body using double full-width parentheses `(())`:

```javascript
rubyfy('((Alice))(アリス)')
// => Alice(アリス)
```

## Advanced usage

You can take the parser and the renderer to use for yourself:

```javascript
import { parse } from "rubyfy/out/parser.js"
parse('漢(かん)字(じ)です')
```

Output:
```json
[
{ "rb": "漢", "rt": "かん" },
{ "rb": "字", "rt": "じ"},
"です"
]
```

Render using the parse result:
```javascript
import { render } from "rubyfy/out/render.js"
render(parseResult)
```

More details on the [API documentation](./API.md).