Skip to content

Commit 475366c

Browse files
committed
Add support for implicit paragraphs
Closes GH-27.
1 parent 5d2d603 commit 475366c

File tree

11 files changed

+124
-9
lines changed

11 files changed

+124
-9
lines changed

handlers/blockquote.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
module.exports = blockquote;
44

55
var all = require('../all');
6+
var wrap = require('../wrap');
67

78
function blockquote(h, node) {
8-
return h(node, 'blockquote', all(h, node));
9+
return h(node, 'blockquote', wrap(all(h, node)));
910
}

handlers/list-item.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module.exports = listItem;
44

55
var is = require('hast-util-is-element');
66
var all = require('../all');
7+
var wrap = require('../wrap');
78

89
function listItem(h, node) {
910
var children = node.children;
@@ -26,7 +27,7 @@ function listItem(h, node) {
2627
}
2728
}
2829

29-
content = all(h, node);
30+
content = wrap(all(h, node));
3031

3132
/* Remove initial spacing if we previously found a checkbox. */
3233
if (checked !== null) {
@@ -49,11 +50,7 @@ function listItem(h, node) {
4950
} else if (content.length === 1) {
5051
head = content[0];
5152

52-
if (head.type === 'text') {
53-
/* Wrap `text` in `paragraph` (always tight). */
54-
content = [{type: 'paragraph', children: content}];
55-
loose = false;
56-
} else if (head.type === 'paragraph') {
53+
if (head.type === 'paragraph') {
5754
/* One `paragraph`, always tight. Ensure it isn’t empty. */
5855
loose = false;
5956

handlers/root.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
module.exports = root;
44

55
var all = require('../all');
6+
var wrap = require('../wrap');
67

78
function root(h, node) {
8-
return h(node, 'root', all(h, node));
9+
return h(node, 'root', wrap.optional(all(h, node)));
910
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"handlers",
1616
"index.js",
1717
"one.js",
18-
"all.js"
18+
"all.js",
19+
"wrap.js"
1920
],
2021
"repository": "https://github.com/syntax-tree/hast-util-to-mdast",
2122
"bugs": "https://github.com/syntax-tree/hast-util-to-mdast/issues",
@@ -31,6 +32,7 @@
3132
"hast-util-is-element": "^1.0.0",
3233
"hast-util-to-string": "^1.0.0",
3334
"rehype-minify-whitespace": "^2.0.0",
35+
"unist-util-is": "^2.1.0",
3436
"unist-util-visit": "^1.1.1",
3537
"xtend": "^4.0.1"
3638
},

tests/fixtures/gh-27/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<ol>
2+
<li><code>something</code> Hello World? And now <code>channel</code>.</li>
3+
</ol>
4+
5+
A <code>for</code> loop… ye?

tests/fixtures/gh-27/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/gh-27/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1. `something` Hello World? And now `channel`.
2+
3+
A `for` loop… ye?
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<article>
2+
An <strong>implicit</strong> paragraph.
3+
<h1>An <em>explicit</em> paragraph</h1>
4+
</article>
5+
6+
<ol>
7+
<li><em>Emphasis</em> and <strong>importance</strong>.</li>
8+
</ol>
9+
10+
<blockquote>
11+
<h1>Heading</h1>
12+
Another <em>implicit</em> paragraph.
13+
</blockquote>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"fragment": true
3+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
An **implicit** paragraph.
2+
3+
# An _explicit_ paragraph
4+
5+
1. _Emphasis_ and **importance**.
6+
7+
> # Heading
8+
>
9+
> Another _implicit_ paragraph.

0 commit comments

Comments
 (0)