Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information