2.3.12 • Published 4 months ago
@yozora/markup-weaver v2.3.12
This package is designed to weave the markup-like AST into markup contents.
Install
npm
npm install --save @yozora/markup-weaver
yarn
yarn add @yozora/markup-weaver
Usage
@yozora/markup-weaver provide a DefaultMarkupWeaver
to weave markup-like AST into markup
contents.
BTW, You can convert a piece of text into markup AST via @yozora/parser or at https://yozora.guanghechen.com.
Here is a simple example to weave AST into markup contents, note that
position
is optional.import { DefaultMarkupWeaver } from '@yozora/markup-weaver' const weaver = new DefaultMarkupWeaver() weaver.weave({ "type": "root", "children": [ { "type": "paragraph", "children": [ { "type": "text", "value": "emphasis: " }, { "type": "strong", "children": [ { "type": "text", "value": "foo \"" }, { "type": "emphasis", "children": [ { "type": "text", "value": "bar" } ] }, { "type": "text", "value": "\" foo" } ] } ] }, { "type": "heading", "depth": 1, "children": [ { "type": "text", "value": "Setext headings" } ] } ] }) // => // emphasis: **foo "*bar*" foo** // # Setext headings
Use custom weaver
import type { Literal } from '@yozora/ast' import type { INodeMarkup, INodeWeaver } from '@yozora/markup-weaver' import { DefaultMarkupWeaver } from '@yozora/markup-weaver' type Mention = Literal<'mention'> class MentionWeaver implements INodeWeaver<Mention> { public readonly type = 'mention' public readonly isBlockLevel = (): boolean => false public weave(node: Mention): INodeMarkup { return { opener: '@' + node.value } } } const weaver = new DefaultMarkupWeaver() weaver.useWeaver(new MentionWeaver) weaver.weave({ "type": "root", "children": [ { "type": "paragraph", "children": [ { "type": "mention", "value": "guanghechen" } ] } ] }) // => @guanghechen
Related
2.3.12
4 months ago
2.3.11
5 months ago
2.3.10
5 months ago
2.3.9
6 months ago
2.3.8
7 months ago
2.3.7
7 months ago
2.3.6
8 months ago
2.3.4
9 months ago
2.3.5
8 months ago
2.3.3
9 months ago
2.3.2
1 year ago
2.3.1
1 year ago
2.3.0
2 years ago
2.2.0
2 years ago
2.1.5
2 years ago
2.1.2
2 years ago
2.1.1
2 years ago
2.1.4
2 years ago
2.1.3
2 years ago
2.0.6
2 years ago
2.1.0
2 years ago
2.0.5
2 years ago
2.0.5-alpha.0
2 years ago
2.0.4
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.2-alpha.0
3 years ago