Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
rehype-template
Advanced tools
Rehype plugin to wrap contents with htm template
npm install remark-frontmatter remark-extract-frontmatter rehype-template
Say example.md
looks as follows;
---
title: Example
---
# Example
This is example
...and example.js
like this:
const vfile = require("to-vfile")
const report = require("vfile-report")
const unified = require("unified")
const remark = require("remark-parse")
const remark2rehype = require("remark-rehype")
const frontmatter = require("remark-frontmatter")
const extract = require("remark-extract-frontmatter")
const stringify = require("rehype-stringify")
const { parse } = require("yaml")
const { html, template, doctype } = require("rehype-template")
const t = (node, frontmatter) => html`
${doctype}
${comment("example")}
<html>
<head>
<title>${frontmatter.title}</title>
</head>
<body>${node}</body>
</html>
`
unified()
.use(remark)
.use(frontmatter)
.use(extract, {yaml: parse})
.use(remark2rehype)
.use(template, {template: t})
.use(stringify)
.process(vfile.readSync("example.md"), (err, file) => {
console.error(report(err || file))
console.log(String(file))
})
Now, running node example
yields:
<!doctype html><!--example--><html><head><title>Example</title></head><body><h1>Example</h1>
<p>This is example</p></body></html>
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 by remark-frontmatter
and remark-extract-frontmatter
.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`<p>hello, ${name}</p>`
The above code yields:
{
type: 'element',
tagName: 'p',
properties: {},
children: [
{ type: 'text', value: 'hello, ' },
{ type: 'text', value: 'world' }
]
}
Use of rehype-template
should be safe to use as htm
should be safe to use. When in doubt, use rehype-sanitize
.
MIT © TANIGUCHI Masaya
FAQs
Rehype plugin to wrap contents with htm template
We found that rehype-template demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.