A compiler compiles the document into output usable by rendering programs. You can override the default compiler with custom compilers.
The default compiler, if not specified, compiles the content into stringified HTML.
<blockquote> <p><strong>some</strong> markdown content</p> </blockquote>
react
Use the rehype-react
compiler to compile to react.
some markdown content
A custom compiler can be applied using the PluggableList
interface e.g. [compiler]
or [[compiler, compilerOptions]]
. The following example demonstrates a custom compiler that returns the hast
tree in JSON format, overriding the default HTML string compiler.
{ "type": "root", "children": [ { "type": "element", "tagName": "blockquote", "properties": {}, "children": [ { "type": "text", "value": "\n" }, { "type": "element", "tagName": "p", "properties": {}, "children": [ { "type": "element", "tagName": "strong", "properties": {}, "children": [ { "type": "text", "value": "some", "position": { "start": { "line": 1, "column": 5, "offset": 4 }, "end": { "line": 1, "column": 9, "offset": 8 } } } ], "position": { "start": { "line": 1, "column": 3, "offset": 2 }, "end": { "line": 1, "column": 11, "offset": 10 } } }, { "type": "text", "value": " markdown content", "position": { "start": { "line": 1, "column": 11, "offset": 10 }, "end": { "line": 1, "column": 28, "offset": 27 } } } ], "position": { "start": { "line": 1, "column": 3, "offset": 2 }, "end": { "line": 1, "column": 28, "offset": 27 } } }, { "type": "text", "value": "\n" } ], "position": { "start": { "line": 1, "column": 1, "offset": 0 }, "end": { "line": 1, "column": 28, "offset": 27 } } } ], "position": { "start": { "line": 1, "column": 1, "offset": 0 }, "end": { "line": 1, "column": 28, "offset": 27 } } }