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.
- Host: GitHub
- URL: https://github.com/seangenabe/rubyfy
- Owner: seangenabe
- License: mit
- Created: 2014-05-08T07:32:02.000Z (about 11 years ago)
- Default Branch: main
- Last Pushed: 2024-02-16T12:47:49.000Z (over 1 year ago)
- Last Synced: 2024-11-27T13:38:39.825Z (6 months ago)
- Topics: html, parser, ruby-annotation
- Language: TypeScript
- Homepage:
- Size: 252 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: license.txt
Awesome Lists containing this project
README
# rubyfy
Easily write ruby annotations and output them as HTML.
[](https://www.npmjs.com/package/rubyfy)
[](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).