retext-dom

1.0.0 • Public • Published

retext-dom Build Status Coverage Status

Create a DOM tree from a retext document.

Note: retext-dom only works in the browser (d’oh), or with a Node.js DOM such as jsdom.

Installation

npm:

npm install retext-dom

retext-dom is also available for bower, component, and duo, and as an AMD, CommonJS, and globals module, uncompressed and compressed.

Usage

var retext = require('retext');
var dom = require('retext-dom');
var processor = retext().use(dom);
 
processor.process('A simple English sentence.', function (err, file, $node) {
    console.log($node.outerHTML);
});

Yields (Note: White-space between nodes added for readability, this is not actually inserted!):

<div>
  <p>
    <span>
      <span>A</span>
      <span> </span>
      <span>simple</span>
      <span> </span>
      <span>English</span>
      <span> </span>
      <span>sentence</span>
      <span>.</span>
    </span>
  </p>
</div>

API

retext.use(dom[, options])

Instead of compiling to text, generate a DOM-node.

Parameters:

  • dom — This module;

  • options (Object, optional):

    • tags (Object, optional) — Object of nlcst types mapping to HTML tags. The initial values look as follows:

      {
          'WhiteSpaceNode': 'span',
          'PunctuationNode': 'span',
          'SymbolNode': 'span',
          'ParagraphNode': 'p',
          'RootNode': 'div'
      }

      When omitted, the default is a #text for nodes with a value, and a span for all others.

Integrations

All nlcst nodes can be re-created as DOM-nodes. In addition, retext-dom looks for an attributes object on each node it compiles and adds the found properties as HTML attributes on the generated DOM node.

License

MIT © Titus Wormer

Readme

Keywords

Package Sidebar

Install

npm i retext-dom

Weekly Downloads

3

Version

1.0.0

License

MIT

Last publish

Collaborators

  • wooorm