Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit b3f407d

Browse files
committed
Rewrite module
1 parent 091546d commit b3f407d

File tree

12 files changed

+432
-922
lines changed

12 files changed

+432
-922
lines changed

.jscs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"excludeFiles": [
33
"coverage/",
44
"node_modules/",
5+
"example.js",
56
"hast-to-hyperscript.js",
67
"hast-to-hyperscript.min.js"
78
],
89
"preset": "crockford",
910
"requireMultipleVarDecl": false,
1011
"disallowDanglingUnderscores": false,
11-
"requireQuotedKeysInObjects": true,
1212
"disallowKeywords": [
1313
"with"
1414
],

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ node_js:
44
- '0.12'
55
- '4.0'
66
- '5.0'
7-
after_script: npm install codecov.io && cat ./coverage/lcov.info | codecov
7+
- '6.0'
8+
after_success: bash <(curl -s https://codecov.io/bash)
89
deploy:
910
- provider: npm
1011
email: tituswormer@gmail.com
@@ -21,3 +22,4 @@ deploy:
2122
- "hast-to-hyperscript.min.js"
2223
on:
2324
tags: true
25+
node: '6.0'

example.js

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,25 @@
11
// Dependencies:
2-
var toHyperscript = require('./index.js');
3-
var React = require('react');
2+
var toH = require('./index.js');
43
var h = require('hyperscript');
5-
var v = require('virtual-dom/h');
64

7-
// HAST Tree:
8-
var tree = {
9-
'type': 'element',
10-
'tagName': 'a',
11-
'properties': {
12-
'href': 'http://alpha.com',
13-
'id': 'bravo',
14-
'className': ['charlie', 'delta'],
15-
'download': true
16-
},
17-
'children': [{
18-
'type': 'text',
19-
'value': 'Echo'
20-
}]
21-
};
5+
// AST:
6+
var tree = { type: 'element',
7+
tagName: 'p',
8+
properties: { id: 'alpha', className: [ 'bravo' ] },
9+
children:
10+
[ { type: 'text',
11+
value: 'charlie ' },
12+
{ type: 'element',
13+
tagName: 'strong',
14+
properties: { style: 'color: red;' },
15+
children:
16+
[ { type: 'text',
17+
value: 'delta' } ] },
18+
{ type: 'text',
19+
value: ' echo.' } ] }
2220

23-
// Compiling with `hyperscript`:
24-
var result = toHyperscript(tree, h).outerHTML;
21+
// Transform (`hyperscript` needs `outerHTML` to stringify):
22+
var doc = toH(h, tree).outerHTML;
2523

2624
// Yields:
27-
console.log('html', result);
28-
29-
// Or with `virtual-dom/h`:
30-
result = toHyperscript(tree, v);
31-
32-
// Yields:
33-
console.log('js', require('util').inspect(result));
34-
35-
// Or `React.createElement`:
36-
result = toHyperscript(tree, React.createElement);
37-
38-
// Yields:
39-
console.log('js', require('util').inspect(result));
25+
console.log('html', doc);

0 commit comments

Comments
 (0)