Have ideas to improve npm?Join in the discussion! »

    rehype-retext

    2.0.4 • Public • Published

    rehype-retext

    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.

    Install

    npm:

    npm install rehype-retext

    Use

    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:

    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')
     
    unified()
      .use(parse)
      .use(
        rehype2retext,
        unified()
          .use(english)
          .use(indefinite)
          .use(repeated)
      )
      .use(minify)
      .use(stringify)
      .process(vfile.readSync('example.html'), function(err, file) {
        console.error(report(err || 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       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>

    API

    origin.use(rehype2retext, destination)

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

    destination

    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.

    Security

    rehype-retext does not change the syntax tree so there are no openings for cross-site scripting (XSS) attacks.

    Related

    Contribute

    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.

    License

    MIT © Titus Wormer

    Install

    npm i rehype-retext

    DownloadsWeekly Downloads

    13,517

    Version

    2.0.4

    License

    MIT

    Unpacked Size

    9.73 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar
    • avatar