1.0.0 • Published 9 years ago

retext-dom v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

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

1.0.0

9 years ago

0.3.2

9 years ago

0.3.1

9 years ago

0.3.0

9 years ago

0.2.4

9 years ago

0.2.3

10 years ago

0.2.2

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago