-
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit 134ecad
authored
Add plugin input/output type parameters
This commit adds support for tracking the parse tree, current tree,
compile tree, and compile result as configured on unified processors.
Plugins can now configure what input and output they receive and yield:
```ts
// A parse plugin, that configures parser, defines what it receives as `string`
// and what it yields as a specific node.
const remarkParse: Plugin<void[], string, MdastRoot> = () => {}
// A transform plugin, that transforms a certain tree, defines what it receives
// (and yields) as a specific node.
const remarkTransformPlugin: Plugin<void[], MdastRoot> = () => {}
// A bridge plugin, that transforms a certain tree to another, defines what it
// receives as a specific node and yields as another node.
const remarkRehype: Plugin<void[], MdastRoot, HastRoot> = () => {}
// A compile plugin, that configures a compiler, defines what it receives as a
// specific node and yields as a non-node value (typically string, but could be
// a React node).
const rehypeStringify: Plugin<void[], HastRoot, string> = () => {}
```
Assuming the above plugins are used:
```js
const processor = unified()
.use(remarkParse)
.use(remarkTransformPlugin)
.use(remarkRehype)
.use(rehypeStringify)
```
Affects what the processor functions receive and yield:
```js
import {expectType} from 'tsd'
const tree: MdastRoot = {type: 'root', children: []}
expectType<MdastRoot>(processor.parse(''))
expectType<string>(processor.stringify(tree))
expectType<HastRoot>(processor.runSync(tree))
```
Closes GH-156.
Reviewed-by: Christian Murphy <[email protected]>1 parent cf8653b commit 134ecadCopy full SHA for 134ecad
File tree
Expand file treeCollapse file tree
5 files changed
+663
-78
lines changedFilter options
- test
Expand file treeCollapse file tree
5 files changed
+663
-78
lines changed
0 commit comments