1.1.0 • Published 3 years ago
@handbook/remark-magic-comments v1.1.0
@handbook/remark-magic-comments
How to usage
import unified from 'unified';
export const processor = unified()
.use(require('remark-parse'))
.use(require('@handbook/remark-split-html-lines'))
.use(require('@handbook/remark-magic-comments'))
.use(require('remark-stringify'), {
listItemIndent: 1,
});
What does this do?
When you have an AST tree like below.
[
{
"type": "html",
"value": "<!-- source test.ts -->"
},
{
"type": "html",
"value": "<!-- /source -->"
}
]
It converted to like below.
[
{
"type": "html",
"value": "<!-- source test.ts -->",
"command": "source",
"phase": "start",
"filePatterns": ["source/typescript.ts"]
},
{
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "source/test.ts",
"children": [
{
"type": "text",
"value": "source/test.ts"
}
]
}
]
},
{
"type": "code",
"lang": "ts",
"meta": null,
"value": "/**\n * interface\n */\nexport interface Interface {\n /** a */\n a: string;\n /** b */\n b: number;\n}\n\n/**\n * class\n */\nexport class Class {\n}\n\n/**\n * currying\n */\nexport const currying = (a: number) => (b: number): number => { };"
},
{
"type": "html",
"value": "<!-- /source -->",
"command": "source",
"phase": "end"
}
]
Magic Comments
# Import Source
## Single file
<!-- source file.ts -->
<!-- /source -->
## Multiple files
<!-- source file1.ts file2.ts file3.ts -->
<!-- /source -->
## Glob
<!-- source tests/*.ts -->
<!-- /source -->
## `--pick` (only support js, jsx, ts, tsx)
<!-- source file.ts --pick "someFunction SomeType SomeClass" -->
<!-- /source -->
# Create Index
<!-- index src/**/*.md -->
<!-- /index -->
See more
@handbook/*
This package is one of@handbook/*
packages. Go to the project home and see more details.