hast-to-hyperscript
Advanced tools
Comparing version 3.0.2 to 3.1.0
25
index.js
@@ -21,6 +21,2 @@ 'use strict'; | ||
if (!is('element', node)) { | ||
throw new Error('Expected element, not `' + node + '`'); | ||
} | ||
r = react(h); | ||
@@ -33,2 +29,17 @@ v = vdom(h); | ||
if (is('root', node)) { | ||
if (node.children.length === 1 && is('element', node.children[0])) { | ||
node = node.children[0]; | ||
} else { | ||
node = { | ||
type: 'element', | ||
tagName: 'div', | ||
properties: {}, | ||
children: node.children | ||
}; | ||
} | ||
} else if (!is('element', node)) { | ||
throw new Error('Expected root or element, not `' + ((node && node.type) || node) + '`'); | ||
} | ||
return toH(h, node, { | ||
@@ -116,7 +127,3 @@ prefix: prefix, | ||
* void elements having children passed in. */ | ||
if (elements.length === 0) { | ||
elements = undefined; | ||
} | ||
return h(selector, attributes, elements); | ||
return elements.length === 0 ? h(selector, attributes) : h(selector, attributes, elements); | ||
} | ||
@@ -123,0 +130,0 @@ |
{ | ||
"name": "hast-to-hyperscript", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Transform HAST to something else through a hyperscript DSL", | ||
@@ -39,4 +39,4 @@ "license": "MIT", | ||
"nyc": "^11.0.0", | ||
"react": "^15.1.0", | ||
"react-dom": "^15.5.4", | ||
"react": "^16.1.1", | ||
"react-dom": "^16.1.1", | ||
"rehype": "^5.0.0", | ||
@@ -43,0 +43,0 @@ "remark-cli": "^4.0.0", |
@@ -81,8 +81,21 @@ # hast-to-hyperscript [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
Although there are lots of libs mentioning support for this interface, | ||
there are significant differences between them. For example, hyperscript | ||
doesn’t support classes in `attrs`, `virtual-dom/h` needs an `attributes` | ||
object inside `attrs` most of the time. `hast-to-hyperscript` works | ||
around these differences for: | ||
**Nodes**: Most hyperscript implementations only support elements and text (as | ||
leave nodes). HAST supports `doctype`, `comment`, and `root` as well. | ||
* If anything other than an `element` or `root` node is given, | ||
`hast-to-hyperscript` throws | ||
* If a `root` is given with one element child, that element is | ||
transformed | ||
* If a `root` with no children, a non-element only child, or more than one | ||
children, the children are wrapped in a `div` element | ||
If unknown nodes are found deeper in the tree, they are ignored: only `text` | ||
and `element` nodes are transformed. | ||
**Support**: Although there are lots of libs mentioning support for this | ||
interface, there are significant differences between them. For example, | ||
hyperscript doesn’t support classes in `attrs`, `virtual-dom/h` needs an | ||
`attributes` object inside `attrs` most of the time. `hast-to-hyperscript` | ||
works around these differences for: | ||
* [`React.createElement`][react] | ||
@@ -96,2 +109,10 @@ * [`virtual-dom/h`][vdom] | ||
## Contribute | ||
See [`contribute.md` in `syntax-tree/hast`][contribute] for ways to get | ||
started. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
## License | ||
@@ -130,1 +151,5 @@ | ||
[hastscript]: https://github.com/syntax-tree/hastscript | ||
[contribute]: https://github.com/syntax-tree/hast/blob/master/contributing.md | ||
[coc]: https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md |
13098
195
153