2.3.12 • Published 10 months ago
@yozora/ast-util v2.3.12
Utility functions to handle Yozora markdown ast.
Install
npm
npm install --save @yozora/ast-utilyarn
yarn add @yozora/ast-util
Usage
| Name | Description |
|---|---|
calcDefinitionMap | Traverse yozora ast and generate a link reference definition map. |
calcExcerptAst | Calc excerpt ast from the original ast. |
calcFootnoteDefinitionMap | Traverse yozora ast and generate a footnote reference definition map. |
calcHeadingToc | Generate heading toc, and update the referenced Heading.identifier simultaneously |
collectDefinitions | Collect link reference definitions in a pre-order traversal. |
collectFootnoteDefinitions | Collect footnote reference definitions in a pre-order traversal. |
defaultUrlResolver | Default url resolver |
replaceFootnotesInReferences | Replace inline footnotes into footnote references and footnote reference definitions (irreversible) |
resolveUrlsForAst | Traverse Yozora AST and resolve urls for aim nodes (irreversible) |
searchNode | Search a node from Yozora AST in pre-order traversing |
shallowCloneAst | Shallow clone the Yozora AST until the match reaches the termination condition. |
shallowMutateAstInPostorder | Traverse AST and replace nodes in post-order. |
shallowMutateAstInPreorder | Traverse AST and replace nodes in pre-order. |
traverseAst | Traverse Yozora AST and perform a mutating operation for each matched node |
Example
import { ImageType, BlockquoteType } from '@yozora/ast'
import {
collectDefinitions,
collectFootnoteDefinitions,
calcHeadingToc,
replaceAST,
traverseAst,
} from '@yozora/ast-util'
// Collect definitions.
collectDefinitions(
root, // Yozora ast root
[DefinitionType], // aim Yast types, optional
[], // preset definitions, optional
)
// Collect footnote definitions.
collectFootnoteDefinitions(
root, // Yozora ast root
[FootnoteDefinitionType], // aim Yast types, optional
[], // preset footnote definitions, optional
true, // prefer reference type footnotes, optional.
)
// traverse the Yozora AST and set the image title to the image alt
traverseAst(
root, // Yozora ast root
[ImageType], // aim Yast types, required
(node) => node.title = node.alt // mutating operation, required
)
// Generate heading toc, each toc node's identifier will with the prefix 'custom-identifier-prefix-'.
// The default prefix is 'heading-'
calcHeadingToc(root, 'custom-identifier-prefix-')
// shallow clone the Yozora AST until a blockquote type node with a blockquote
// type parent and in addition it is not the first child of its parent encountered.
const root2 = shallowCloneAst(
root,
(node, parent, childIndex) => (
parent.type === BlockquoteType &&
childIndex > 0 &&
node.type === BlockquoteType
)
)Related
2.3.12
10 months ago
2.3.11
11 months ago
2.3.10
11 months ago
2.3.9
1 year ago
2.3.8
1 year ago
2.3.7
1 year ago
2.3.6
1 year ago
2.3.4
1 year ago
2.3.5
1 year ago
2.3.3
1 year ago
2.3.2
1 year ago
2.3.1
2 years ago
2.2.0
2 years ago
2.3.0
2 years ago
2.1.5
3 years ago
2.0.6
3 years ago
2.1.2
3 years ago
2.1.1
3 years ago
2.1.4
3 years ago
2.1.3
3 years ago
2.1.0
3 years ago
2.0.5-alpha.0
3 years ago
2.0.3
3 years ago
2.0.2
3 years ago
2.0.5
3 years ago
2.0.4
3 years ago
2.0.2-alpha.0
4 years ago
2.0.1
4 years ago
2.0.0-alpha.3
4 years ago
2.0.0-alpha.0
4 years ago
2.0.0-alpha.1
4 years ago
2.0.0-alpha.2
4 years ago
2.0.0
4 years ago
1.3.0
4 years ago
1.2.2
4 years ago
1.2.1
4 years ago
1.2.0
4 years ago
1.2.0-alpha.1
4 years ago
1.2.0-alpha.0
4 years ago
1.1.0
4 years ago
1.1.0-alpha.2
4 years ago
1.1.0-alpha.1
4 years ago
1.1.0-alpha.0
4 years ago
1.0.0
4 years ago
1.0.0-1.0.0-beta.0.0
4 years ago
1.0.0-beta.0
4 years ago
1.0.0-alpha.29
4 years ago
1.0.0-alpha.27
4 years ago
1.0.0-alpha.28
4 years ago
1.0.0-alpha.26
4 years ago
1.0.0-alpha.25
4 years ago
1.0.0-alpha.23
5 years ago
1.0.0-alpha.24
5 years ago
1.0.0-alpha.21
5 years ago
1.0.0-alpha.20
5 years ago
1.0.0-alpha.22
5 years ago
1.0.0-alpha.19
5 years ago
1.0.0-alpha.18
5 years ago
1.0.0-alpha.17
5 years ago
1.0.0-alpha.16
5 years ago
1.0.0-alpha.15
5 years ago
1.0.0-alpha.14
5 years ago
1.0.0-alpha.13
5 years ago