Rehype Template
Rehype plugin to wrap contents with htm template
Installation
npm install remark-frontmatter remark-extract-frontmatter rehype-template
Usage
Say example.md
looks as follows;
---title: Example---# ExampleThis is example
...and example.js
like this:
const vfile = const report = const unified = const remark = const remark2rehype = const frontmatter = const extract = const stringify = const parse = const html template doctype = const t = html` `
Now, running node example
yields:
<!--example-->ExampleExampleThis is example
API
rehype().use(template[, options])
Wrap the content with options.template
, which uses template literal.
options.template(node, frontmatter)
node
Syntax treefrontmatter
Object as frontmatter parsed byremark-frontmatter
andremark-extract-frontmatter
.- This function returns new syntax tree.
doctype
Insert a doctype element into a template like the above.
comment(value)
Insert a comment element into a template like the above.
html
Template literal function defined as htm.bind(h)
where h
is hastscript.
> const name = "world"> html`hello, `
The above code yields:
type: 'element' tagName: 'p' properties: {} children: type: 'text' value: 'hello, ' type: 'text' value: 'world'
Security
Use of rehype-template
should be safe to use as htm
should be safe to use. When in doubt, use rehype-sanitize
.
License
MIT © TANIGUCHI Masaya