$ cnpm install rehype-retext
rehype plugin to bridge or mutate to retext.
Uses hast-util-to-nlcst under the hood.
See its documentation to learn how to ignore nodes.
This package is ESM only:
Node 12+ is needed to use it and it must be imported instead of required.
npm:
npm install rehype-retext
Say example.html looks as follows:
<!doctype html>
<meta charset=utf8>
<title>Hello!</title>
<article>
A implicit sentence.
<h1>This and and that.</h1>
</article>
…and example.js like this:
import {readSync} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {unified} from 'unified'
import rehypeParse from 'rehype-parse'
import rehypePresetMinify from 'rehype-preset-minify'
import rehypeStringify from 'rehype-stringify'
import rehypeRetext from 'rehype-retext'
import retextEnglish from 'retext-english'
import retextIndefiniteArticle from 'retext-indefinite-article'
import retextRepeatedWords from 'retext-repeated-words'
const file = readSync('example.html')
unified()
.use(rehypeParse)
.use(
rehypeRetext,
unified()
.use(retextEnglish)
.use(retextIndefiniteArticle)
.use(retextRepeatedWords)
)
.use(rehypePresetMinify)
.use(rehypeStringify)
.process(file)
.then((file) => {
console.error(reporter(file))
console.log(String(file))
})
Now, running node example yields:
example.html
5:3-5:4 warning Use `An` before `implicit`, not `A` retext-indefinite-article retext-indefinite-article
6:12-6:19 warning Expected `and` once, not twice and retext-repeated-words
⚠ 2 warnings
<!doctypehtml><meta charset=utf8><title>Hello!</title><article>A implicit sentence.<h1>This and and that.</h1></article>
This package exports no identifiers.
The default export is rehypeRetext.
unified().use(rehypeRetext, destination)rehype (hast) plugin to bridge or mutate to retext (nlcst).
destinationdestination is either a parser or a processor.
If a processor (Unified) is given, runs the destination
processor with the new nlcst tree, then, after running discards that tree and
continues on running the origin processor with the original tree
(bridge-mode).
If a parser (such as parse-latin, parse-english, or parse-dutch) is given, passes the tree to further plugins (mutate-mode).
As HTML defines paragraphs, that definition is used for
Paragraphs: <p> and <h1-6> are explicitly
supported, and implicit paragraphs in flow content are also supported.
rehype-retext does not change the syntax tree so there are no openings for
cross-site scripting (XSS) attacks.
rehype-remark
— Transform HTML (hast) to Markdown (mdast)remark-retext
— Transform Markdown (mdast) to natural language
(nlcst)remark-rehype
— Transform Markdown (mdast) to HTML (hast)See contributing.md in rehypejs/.github for ways
to get started.
See support.md for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.
Copyright 2013 - present © cnpmjs.org | Home |