Skip to content

Commit b28f105

Browse files
committed
Add more nodes, and refactor tests to be more scalable
1 parent 884d299 commit b28f105

33 files changed

+123
-55
lines changed

handlers/emphasis.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = emphasis
2+
3+
var u = require('unist-builder')
4+
var all = require('../all')
5+
6+
function emphasis (h, node) {
7+
return h(node, 'emphasis', all(h, node))
8+
}

handlers/heading.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
module.exports = function (depth) {
2-
return heading(depth)
3-
}
1+
module.exports = heading
42

53
var u = require('unist-builder')
64
var all = require('../all')
75

8-
function heading (depth) {
9-
return function (h, node) {
10-
return h(node, 'heading', { depth: depth }, all(h, node))
11-
}
6+
function heading (h, node) {
7+
var depth = Number(node.tagName.charAt(1)) || 1;
8+
return h(node, 'heading', {depth: depth}, all(h, node))
129
}

handlers/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
module.exports = {
2-
heading: require('./heading'),
3-
text: require('./text'),
4-
root: require('./root'),
5-
strong: require('./strong'),
6-
p: require('./p')
7-
}
1+
exports.root = require('./root')
2+
3+
exports.text = require('./text')
4+
5+
exports.strong = exports.b = require('./strong')
6+
exports.em = exports.i = require('./emphasis')
7+
exports.code = exports.kbd = exports.samp = exports.var = require('./inline-code')
8+
9+
exports.p = require('./paragraph')
10+
exports.h1 = exports.h2 = exports.h3 =
11+
exports.h4 = exports.h5 = exports.h6 = require('./heading')

handlers/inline-code.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = inlineCode
2+
3+
var toString = require('hast-util-to-string');
4+
var u = require('unist-builder')
5+
var all = require('../all')
6+
7+
function inlineCode (h, node) {
8+
return h(node, 'inlineCode', toString(node))
9+
}
File renamed without changes.

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@
2626
"homepage": "https://github.com/syntax-tree/hast-util-to-mdast#readme",
2727
"dependencies": {
2828
"has": "^1.0.1",
29+
"hast-util-to-string": "^1.0.0",
2930
"trim": "0.0.1",
3031
"trim-lines": "^1.1.0",
3132
"unist-builder": "^1.0.2",
3233
"xtend": "^4.0.1"
3334
},
3435
"devDependencies": {
36+
"is-hidden": "^1.1.0",
37+
"mdast-util-assert": "^1.0.0",
38+
"negate": "^1.0.0",
3539
"rehype-parse": "^2.0.1",
40+
"remark-parse": "^2.2.0",
3641
"remark-stringify": "^2.3.0",
3742
"tape": "^4.6.3",
38-
"unified": "^5.1.0"
43+
"unified": "^5.1.0",
44+
"unist-util-remove-position": "^1.1.0"
3945
}
4046
}

tests/fixtures/b/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p><b>Hello World.</b></p>

tests/fixtures/b/index.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fragment": true
3+
}

tests/fixtures/b/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**Hello World.**

tests/fixtures/code/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Regular. <code>toString()</code>. Regular.</p>

0 commit comments

Comments
 (0)