mdast-util-to-hast
Advanced tools
Comparing version 2.4.0 to 2.4.1
@@ -13,3 +13,3 @@ 'use strict'; | ||
if (def && def.title != null) { | ||
if (def && def.title !== null && def.title !== undefined) { | ||
props.title = def.title; | ||
@@ -16,0 +16,0 @@ } |
@@ -11,3 +11,3 @@ 'use strict'; | ||
if (node.title != null) { | ||
if (node.title !== null && node.title !== undefined) { | ||
props.title = node.title; | ||
@@ -14,0 +14,0 @@ } |
@@ -14,3 +14,3 @@ 'use strict'; | ||
if (def && def.title != null) { | ||
if (def && def.title !== null && def.title !== undefined) { | ||
props.title = def.title; | ||
@@ -17,0 +17,0 @@ } |
@@ -12,3 +12,3 @@ 'use strict'; | ||
if (node.title != null) { | ||
if (node.title !== null && node.title !== undefined) { | ||
props.title = node.title; | ||
@@ -15,0 +15,0 @@ } |
@@ -35,3 +35,3 @@ 'use strict'; | ||
/* according to github-markdown-css, this class hides bullet. */ | ||
/* According to github-markdown-css, this class hides bullet. */ | ||
props.className = ['task-list-item']; | ||
@@ -38,0 +38,0 @@ } |
@@ -36,3 +36,3 @@ 'use strict'; | ||
/* handle `data.hName`, `data.hProperties, `hChildren`. */ | ||
/* Handle `data.hName`, `data.hProperties, `hChildren`. */ | ||
if (left && 'data' in left) { | ||
@@ -69,3 +69,3 @@ data = left.data; | ||
if ( | ||
children == null && | ||
(children === undefined || children === null) && | ||
typeof props === 'object' && | ||
@@ -72,0 +72,0 @@ 'length' in props |
@@ -6,5 +6,6 @@ 'use strict'; | ||
var u = require('unist-builder'); | ||
var has = require('has'); | ||
var all = require('./all'); | ||
var own = {}.hasOwnProperty; | ||
/* Transform an unknown node. */ | ||
@@ -22,3 +23,3 @@ function unknown(h, node) { | ||
var type = node && node.type; | ||
var fn = has(h.handlers, type) ? h.handlers[type] : null; | ||
var fn = own.call(h.handlers, type) ? h.handlers[type] : null; | ||
@@ -37,3 +38,3 @@ /* Fail on non-nodes. */ | ||
if (has(data, 'hName') || has(data, 'hProperties') || has(data, 'hChildren')) { | ||
if (own.call(data, 'hName') || own.call(data, 'hProperties') || own.call(data, 'hChildren')) { | ||
return false; | ||
@@ -40,0 +41,0 @@ } |
{ | ||
"name": "mdast-util-to-hast", | ||
"version": "2.4.0", | ||
"version": "2.4.1", | ||
"description": "Transform MDAST to HAST", | ||
@@ -11,7 +11,3 @@ "license": "MIT", | ||
], | ||
"files": [ | ||
"lib", | ||
"index.js" | ||
], | ||
"repository": "https://github.com/syntax-tree/mdast-util-to-hast", | ||
"repository": "syntax-tree/mdast-util-to-hast", | ||
"bugs": "https://github.com/syntax-tree/mdast-util-to-hast/issues", | ||
@@ -22,6 +18,9 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
], | ||
"files": [ | ||
"lib", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"collapse-white-space": "^1.0.0", | ||
"detab": "^2.0.0", | ||
"has": "^1.0.1", | ||
"mdast-util-definitions": "^1.2.0", | ||
@@ -40,7 +39,7 @@ "normalize-uri": "^1.0.0", | ||
"esmangle": "^1.0.1", | ||
"nyc": "^10.0.0", | ||
"nyc": "^11.0.0", | ||
"remark-cli": "^3.0.0", | ||
"remark-preset-wooorm": "^2.0.0", | ||
"remark-preset-wooorm": "^3.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.17.1" | ||
"xo": "^0.18.0" | ||
}, | ||
@@ -59,9 +58,5 @@ "scripts": { | ||
"space": true, | ||
"esnext": false, | ||
"rules": { | ||
"guard-for-in": "off", | ||
"eqeqeq": [ | ||
"off", | ||
"allow-null" | ||
], | ||
"no-eq-null": "off" | ||
"guard-for-in": "off" | ||
}, | ||
@@ -73,4 +68,6 @@ "ignores": [ | ||
"remarkConfig": { | ||
"plugins": ["preset-wooorm"] | ||
"plugins": [ | ||
"preset-wooorm" | ||
] | ||
} | ||
} |
@@ -5,2 +5,4 @@ # mdast-util-to-hast [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
> **Note** You probably want to use [remark-rehype][]. | ||
## Installation | ||
@@ -16,15 +18,26 @@ | ||
Say we have the following `example.md`: | ||
```markdown | ||
## Hello **World**! | ||
``` | ||
...and next to it, `example.js`: | ||
```javascript | ||
var inspect = require('unist-util-inspect'); | ||
var remark = require('remark'); | ||
var unified = require('unified'); | ||
var parse = require('remark-parse'); | ||
var vfile = require('to-vfile'); | ||
var toHAST = require('mdast-util-to-hast'); | ||
var hast = toHAST(remark().parse('## Hello **World**!')); | ||
console.log(inspect(hast)); | ||
var tree = unified().use(parse).parse(vfile.readSync('example.md')); | ||
console.log(inspect(toHAST(tree))); | ||
``` | ||
Yields: | ||
Which when running with `node example` yields: | ||
```txt | ||
root[1] (1:1-1:20, 0-19) | ||
root[1] (1:1-2:1, 0-20) | ||
└─ element[3] (1:1-1:20, 0-19) [tagName="h2"] | ||
@@ -56,3 +69,3 @@ ├─ text: "Hello " (1:4-1:10, 3-9) | ||
Object mapping [MDAST nodes][mdast] to functions | ||
Object mapping [MDAST nodes][mdast] to functions | ||
handling those elements. | ||
@@ -67,15 +80,24 @@ Take a look at [`lib/handlers/`][handlers] for examples. | ||
* [`yaml`][mdast-yaml] and [`html`][mdast-html] nodes are ignored; | ||
* [`position`][unist-position]s 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; | ||
* [`yaml`][mdast-yaml] and [`html`][mdast-html] nodes are ignored | ||
* [`position`][unist-position]s 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; | ||
properties | ||
* If `node.data.hChildren` is set, it’s used as the element’s HAST | ||
children; | ||
children | ||
## Related | ||
* [`hast-util-sanitize`][hast-util-sanitize] | ||
* [`mdast-util-to-nlcst`](https://github.com/syntax-tree/mdast-util-to-nlcst) | ||
— Transform MDAST to NLCST | ||
* [`hast-util-sanitize`](https://github.com/syntax-tree/hast-util-sanitize) | ||
— Sanitize HAST nodes | ||
* [`hast-util-to-mdast`](https://github.com/syntax-tree/hast-util-to-mdast) | ||
— Transform HAST to MDAST | ||
* [`remark-rehype`](https://github.com/wooorm/remark-rehype) | ||
— rehype support for remark | ||
* [`rehype-remark`](https://github.com/wooorm/remark-remark) | ||
— remark support for rehype | ||
@@ -112,4 +134,4 @@ ## License | ||
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize | ||
[handlers]: lib/handlers | ||
[handlers]: lib/handlers | ||
[remark-rehype]: https://github.com/wooorm/remark-rehype |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
21759
11
133
- Removedhas@^1.0.1
- Removedhas@1.0.4(transitive)