1.0.0-p4 • Published 8 years ago

@mizchi/mdast-util-to-hast v1.0.0-p4

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

mdast-util-to-hast Build Status Coverage Status

Transform MDAST to HAST.

Installation

npm:

npm install mdast-util-to-hast

Usage

Dependencies:

var inspect = require('unist-util-inspect');
var remark = require('remark');
var toHAST = require('@mizchi/mdast-util-to-hast');

Transform:

var hast = toHAST(remark().parse('## Hello **World**!'));

Yields:

root[1] (1:1-1:20, 0-19)
└─ element[3] (1:1-1:20, 0-19) [tagName="h2"]
   ├─ text: "Hello " (1:4-1:10, 3-9)
   ├─ element[1] (1:10-1:19, 9-18) [tagName="strong"]
   │  └─ text: "World" (1:12-1:17, 11-16)
   └─ text: "!" (1:19-1:20, 18-19)

API

toHAST(node[, options])

Transform the given MDAST tree to a HAST tree.

options.allowDangerousHTML

Whether to allow html nodes and inject them as raw HTML (boolean, default: false). Only do this when compiling later with hast-util-to-html.

Returns

HASTNode.

Note
  • yaml and html nodes are ignored;
  • positions are properly patched;
  • Unknown nodes with children are transformed to div elements;
  • Unknown nodes with value are transformed to text nodes;
  • If node.data.hName is set, it’s used as the HAST element’s tag-name;
  • If node.data.hProperties is set, it’s mixed into the HAST element’s properties;
  • If node.data.hChildren is set, it’s used as the element’s HAST children;

Related

License

MIT © Titus Wormer