Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/laysent/remark-ruby
Custom syntax for remarkjs, adding ruby (furigana) to markdown.
https://github.com/laysent/remark-ruby
furigana remark-plugin remarkjs
Last synced: 14 days ago
JSON representation
Custom syntax for remarkjs, adding ruby (furigana) to markdown.
- Host: GitHub
- URL: https://github.com/laysent/remark-ruby
- Owner: laysent
- License: mit
- Created: 2019-03-17T05:45:32.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-19T01:11:39.000Z (over 1 year ago)
- Last Synced: 2024-10-01T10:16:38.339Z (about 1 month ago)
- Topics: furigana, remark-plugin, remarkjs
- Language: JavaScript
- Size: 916 KB
- Stars: 25
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# remark-ruby
This [remark][remark] plugin parses custom Markdown syntax to produce (HTML) ruby.
It introduces a new [MDAST][mdast] node type: "ruby".
```javascript
interface ruby <: Node {
type: "ruby";
base: string;
text: string;
data: {
hName: "ruby";
hChildren: [
{
type: 'text',
value: string,
},
{
type: 'element',
children: [
{ type: 'text', value: string }
],
tagName: 'rp',
},
{
type: 'element',
children: [
{ type: 'text', value: string }
],
tagName: 'rt',
},
{
type: 'element',
children: [
{ type: 'text', value: string },
],
tagName: 'rp',
}
],
},
}
```## Syntax
Ruby is defined in the following way:
```markdown
This plugin works on {Markdown AST}^(MDAST).
```This would compile to the following HTML:
```html
This plugin works on Markdown AST(MDAST)
```### Text Delimitation
You could also use `[]` to delimit text:
```markdown
{[紳][士]}^([へん][たい])
```This would compile to the following HTML:
```html
紳士(へんたい)
```Notice that this requires the usage of `rb` tag, which is not supported by most of the browsers
except Firefox. Check [caniuse](https://caniuse.com/#search=ruby) for details.## Installation
[npm][npm]:
```bash
npm install remark-ruby
```## Usage
Dependencies:
```javascript
const unified = require('unified')
const remarkParse = require('remark-parse')
const remarkRuby = require('remark-ruby')
const stringify = require('rehype-stringify')
const remark2rehype = require('remark-rehype')```
Usage:
```javascript
unified()
.use(remarkParse)
.use(remarkRuby)
.use(remark2rehype)
.use(stringify)
```## Options
### options.parenthesis
Ruby fallback parenthesis which will be used in `rp` tag. It should be a string with at most two characters. The first will be used as left parenthesis, the last will be used as right parenthesis.
By default, it's value is `()`.
**example**
```javascript
.use(remarkAbbr, { parenthesis: '「」' })
```**given**
```markdown
This plugin works on {Markdown AST}^(MDAST).
```**produces**
```html
This plugin works on Markdown AST「MDAST」
```## License
[MIT][license] © [LaySent][homepage]
[license]: https://github.com/laysent/remark-ruby/blob/master/LICENSE
[homepage]: https://github.com/laysent
[npm]: https://www.npmjs.com/package/remark-ruby
[mdast]: https://github.com/syntax-tree/mdast/blob/master/readme.md
[remark]: https://github.com/remarkjs/remark