Project: rehypejs/rehype-retext

Package: rehype-retext@2.0.4

  1. Dependents: 8
  2. rehype plugin to transform to retext
  1. unified 173
  2. html 112
  3. rehype 78
  4. hast 61
  5. rehype-plugin 54
  6. retext 38
  7. retext-plugin 25
  8. nlcst 14
  9. natural 10


Build Coverage Downloads Size Sponsors Backers Chat

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.



npm install rehype-retext


Say example.html looks as follows:

<!doctype html>
<meta charset=utf8>
  A implicit sentence.
  <h1>This and and that.</h1>

…and example.js like this:

var vfile = require('to-vfile')
var report = require('vfile-reporter')
var unified = require('unified')
var parse = require('rehype-parse')
var minify = require('rehype-preset-minify')
var stringify = require('rehype-stringify')
var rehype2retext = require('rehype-retext')
var english = require('retext-english')
var indefinite = require('retext-indefinite-article')
var repeated = require('retext-repeated-words')

  .process(vfile.readSync('example.html'), function(err, file) {
    console.error(report(err || file))

Now, running node example yields:

    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       retext-repeated-words      retext-repeated-words

⚠ 2 warnings
<!doctype html><meta charset=utf8><title>Hello!</title><article>A implicit sentence.<h1>This and and that.</h1></article>


origin.use(rehype2retext, destination)

rehype (hast) plugin to bridge or mutate to retext (nlcst).


destination 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.


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.


MIT © Titus Wormer