Skip to content

Commit 0b1cd0a

Browse files
committed
Change to comply to CommonMark
* Change to comply to CommonMark — prefer the first when duplicate definitions are found * Replace `xtend` w/ `Object.assign` * Refactor old stuff in tests
1 parent 5fec432 commit 0b1cd0a

File tree

21 files changed

+141
-443
lines changed

21 files changed

+141
-443
lines changed

index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
var xtend = require('xtend')
43
var toHast = require('mdast-util-to-hast')
54
var toHtml = require('hast-util-to-html')
65
var sanitize = require('hast-util-sanitize')
@@ -17,7 +16,11 @@ function plugin(options) {
1716

1817
function compiler(node, file) {
1918
var root = node && node.type && node.type === 'root'
20-
var hast = toHast(node, {allowDangerousHtml: !clean, handlers: handlers})
19+
var hast = toHast(node, {
20+
allowDangerousHtml: !clean,
21+
handlers: handlers,
22+
commonmark: true
23+
})
2124
var result
2225

2326
if (file.extname) {
@@ -28,10 +31,13 @@ function plugin(options) {
2831
hast = sanitize(hast, schema)
2932
}
3033

31-
result = toHtml(hast, xtend(settings, {allowDangerousHtml: !clean}))
34+
result = toHtml(
35+
hast,
36+
Object.assign({}, settings, {allowDangerousHtml: !clean})
37+
)
3238

3339
// Add an eof eol.
34-
if (root && result.charAt(result.length - 1) !== '\n') {
40+
if (root && result && /[^\r\n]/.test(result.charAt(result.length - 1))) {
3541
result += '\n'
3642
}
3743

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,23 @@
3636
"dependencies": {
3737
"hast-util-sanitize": "^3.0.0",
3838
"hast-util-to-html": "^7.0.0",
39-
"mdast-util-to-hast": "^9.0.0",
40-
"xtend": "^4.0.1"
39+
"mdast-util-to-hast": "^9.0.0"
4140
},
4241
"devDependencies": {
4342
"browserify": "^16.0.0",
4443
"commonmark.json": "^0.29.0",
4544
"dtslint": "^4.0.0",
4645
"is-hidden": "^1.0.0",
46+
"not": "^0.1.0",
4747
"nyc": "^15.0.0",
4848
"prettier": "^2.0.0",
49-
"remark": "^12.0.0",
49+
"rehype-parse": "^7.0.0",
50+
"rehype-stringify": "^8.0.0",
51+
"remark": "^13.0.0-alpha.0",
5052
"remark-cli": "^8.0.0",
5153
"remark-github": "^9.0.0",
5254
"remark-preset-wooorm": "^7.0.0",
55+
"remark-slug": "^6.0.0",
5356
"remark-toc": "^7.0.0",
5457
"tape": "^5.0.0",
5558
"tinyify": "^3.0.0",
@@ -86,7 +89,8 @@
8689
"esnext": false,
8790
"rules": {
8891
"unicorn/no-fn-reference-in-iterator": "off",
89-
"unicorn/prefer-includes": "off"
92+
"unicorn/prefer-includes": "off",
93+
"unicorn/prefer-optional-catch-binding": "off"
9094
},
9195
"ignores": [
9296
"remark-html.js"

readme.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
> It’s probably smarter to use `remark-rehype` directly and benefit from the
1717
> [**rehype**][rehype] ecosystem.
1818
19+
## Note!
20+
21+
This plugin is ready for the new parser in remark
22+
([`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)).
23+
The current and previous version of the plugin works with the current and
24+
previous version of remark.
25+
1926
## Install
2027

2128
[npm][]:
@@ -79,7 +86,7 @@ All options except for `sanitize` and `handlers` are passed to
7986
###### `options.handlers`
8087

8188
Object mapping [mdast][] [nodes][mdast-node] to functions handling them.
82-
This option is passed to [`mdast-util-to-html`][to-mdast-handlers].
89+
This option is passed to [`mdast-util-to-hast`][to-hast-handlers].
8390

8491
###### `options.sanitize`
8592

@@ -264,7 +271,7 @@ abide by its terms.
264271

265272
[to-html]: https://github.com/syntax-tree/hast-util-to-html
266273

267-
[to-mdast-handlers]: https://github.com/syntax-tree/mdast-util-to-hast#optionshandlers
274+
[to-hast-handlers]: https://github.com/syntax-tree/mdast-util-to-hast#optionshandlers
268275

269276
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize
270277

test/fixtures/blockquote/output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ <h1>Block Quote</h1>
1010
</li>
1111
<li>
1212
<p>Normal list</p>
13-
<p>Paragraph.</p>
1413
</li>
1514
</ul>
15+
<p>Paragraph.</p>
1616
</blockquote>

test/fixtures/code/output.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ <h1>Code</h1>
77
</code></pre>
88
<pre><code class="language-empty"></code></pre>
99
<pre><code class="language-tabs"> two spaces
10-
one
11-
two
12-
one
13-
mixed.
10+
one
11+
two
12+
one
13+
mixed.
1414
</code></pre>

test/fixtures/entities-named/output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1>Entities</h1>
99
<pre><code class="language-AT&amp;T">Something in the AT&amp;T language
1010
</code></pre>
1111
<p>Automatic links:</p>
12-
<p><a href="http://at&amp;t.com">http://at&amp;t.com</a>, <a href="http://at&amp;t.com">http://at&amp;t.com</a>, and <a href="http://at&amp;t.com">http://at&amp;t.com</a>.</p>
12+
<p><a href="http://at&amp;amp;t.com">http://at&amp;amp;t.com</a>, <a href="http://at&amp;#x26;t.com">http://at&amp;#x26;t.com</a>, and <a href="http://at&amp;t.com">http://at&amp;t.com</a>.</p>
1313
<p>Link <code>href</code>:</p>
1414
<p><a href="http://at&amp;t.com">With entity</a>, <a href="http://at&amp;t.com">numeric entity</a>, <a href="http://at&amp;t.com">without entity</a>.</p>
1515
<p>Link <code>title</code>:</p>

test/fixtures/entities-numerical/output.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ <h1>Entities</h1>
99
<pre><code class="language-AT&#x26;T">Something in the AT&#x26;T language
1010
</code></pre>
1111
<p>Automatic links:</p>
12-
<p><a href="http://at&#x26;t.com">http://at&#x26;t.com</a>, <a href="http://at&#x26;t.com">http://at&#x26;t.com</a>, and <a href="http://at&#x26;t.com">http://at&#x26;t.com</a>.</p>
12+
<p><a href="http://at&#x26;amp;t.com">http://at&#x26;amp;t.com</a>, <a href="http://at&#x26;#x26;t.com">http://at&#x26;#x26;t.com</a>, and <a href="http://at&#x26;t.com">http://at&#x26;t.com</a>.</p>
1313
<p>Link <code>href</code>:</p>
1414
<p><a href="http://at&#x26;t.com">With entity</a>, <a href="http://at&#x26;t.com">numeric entity</a>, <a href="http://at&#x26;t.com">without entity</a>.</p>
1515
<p>Link <code>title</code>:</p>

test/fixtures/escape/output.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
<p>Pipe: |</p>
2020
<p>Tilde: ~</p>
2121
<p><strong>Commonmark:</strong></p>
22-
<p>Quote: \"</p>
23-
<p>Dollar: \$</p>
24-
<p>Percentage: \%</p>
25-
<p>Ampersand: \&#x26;</p>
26-
<p>Single quote: \'</p>
27-
<p>Comma: \,</p>
28-
<p>Forward slash: \/</p>
29-
<p>Colon: \:</p>
30-
<p>Semicolon: \;</p>
31-
<p>Less-than: \&#x3C;</p>
32-
<p>Equals: \=</p>
33-
<p>Question mark: \?</p>
34-
<p>At-sign: \@</p>
35-
<p>Caret: \^</p>
36-
<p>New line: \
22+
<p>Quote: "</p>
23+
<p>Dollar: $</p>
24+
<p>Percentage: %</p>
25+
<p>Ampersand: &#x26;</p>
26+
<p>Single quote: '</p>
27+
<p>Comma: ,</p>
28+
<p>Forward slash: /</p>
29+
<p>Colon: :</p>
30+
<p>Semicolon: ;</p>
31+
<p>Less-than: &#x3C;</p>
32+
<p>Equals: =</p>
33+
<p>Question mark: ?</p>
34+
<p>At-sign: @</p>
35+
<p>Caret: ^</p>
36+
<p>New line: <br>
3737
only works in paragraphs.</p>
3838
<p>Two spaces:<br>
3939
only works in paragraphs.</p>

test/fixtures/footnotes/config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/fixtures/footnotes/input.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)