Package Exports
- mdast-util-jaruby
- mdast-util-jaruby/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mdast-util-jaruby) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mdast-util-jaruby
mdast extension to support Japanese ruby.
Feature
- compatible with latest mdast ecosystem
- add custom mdast node type (see
ruby.d.ts) - fully typed
- ESM only
Install
npm install mdast-util-jarubyUsage
Markdown => MDAST
import { fromMarkdown } from "mdast-util-from-markdown";
import { jarubyFromMarkdown } from "mdast-util-jaruby";
import { jaruby } from "micromark-extension-jaruby";
const markdown = `
{聖剣}^(エクスカリバー)
`;
console.dir(
fromMarkdown(markdown, {
extensions: [jaruby()],
mdastExtensions: [jarubyFromMarkdown()],
}),
{ depth: null },
);generates...
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "ruby",
"base": "聖剣",
"text": "エクスカリバー",
"children": [],
"data": {
"hName": "ruby",
"hChildren": [
{ "type": "text", "value": "聖剣" },
{
"type": "element",
"children": [{ "type": "text", "value": "(" }],
"tagName": "rp"
},
{
"type": "element",
"children": [{ "type": "text", "value": "エクスカリバー" }],
"tagName": "rt"
},
{
"type": "element",
"children": [{ "type": "text", "value": ")" }],
"tagName": "rp"
}
]
},
"position": {
"start": { "line": 2, "column": 1, "offset": 1 },
"end": { "line": 2, "column": 15, "offset": 15 }
}
}
],
"position": {
"start": { "line": 2, "column": 1, "offset": 1 },
"end": { "line": 2, "column": 15, "offset": 15 }
}
}
],
"position": {
"start": { "line": 1, "column": 1, "offset": 0 },
"end": { "line": 3, "column": 1, "offset": 16 }
}
}MDAST => Markdown
import { fromMarkdown } from "mdast-util-from-markdown";
import { toMarkdown } from "mdast-util-to-markdown";
import { jarubyFromMarkdown, jarubyToMarkdown } from "./index.js";
import { jaruby } from "../micromark-extension-jaruby/index.js";
const mdast = {
type: "root",
children: [
{
type: "paragraph",
children: [
{
type: "ruby",
base: "excalibur",
text: "the holy sword",
children: [],
data: {
hName: "ruby",
hChildren: [
{ type: "text", value: "excalibur" },
{
type: "element",
children: [{ type: "text", value: "(" }],
tagName: "rp",
},
{
type: "element",
children: [{ type: "text", value: "the holy sword" }],
tagName: "rt",
},
{
type: "element",
children: [{ type: "text", value: ")" }],
tagName: "rp",
},
],
},
position: {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 29, offset: 28 },
},
},
],
position: {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 29, offset: 28 },
},
},
],
position: {
start: { line: 1, column: 1, offset: 0 },
end: { line: 1, column: 29, offset: 28 },
},
};
console.dir(
toMarkdown(mdast, {
extensions: [jarubyToMarkdown()],
}),
{ depth: null },
);generates...
'{excalibur}^(the holy sword)\n'Note
- This package is almost a refactoring of remark-ruby. Original package is licensed under MIT License.
- Support for text delimitation &
<rb>tag in original package was omitted, since only few browsers can display it.