Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: remarkjs/remark-html
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 12.0.0
Choose a base ref
...
head repository: remarkjs/remark-html
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 13.0.0
Choose a head ref
  • 5 commits
  • 21 files changed
  • 1 contributor

Commits on Aug 22, 2020

  1. Add Discussions

    wooorm authored Aug 22, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    db1a1d0 View commit details

Commits on Oct 2, 2020

  1. Update dev-dependencies

    wooorm committed Oct 2, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    5fec432 View commit details

Commits on Oct 3, 2020

  1. 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
    wooorm committed Oct 3, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    0b1cd0a View commit details
  2. Update docs

    wooorm committed Oct 3, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    efa1a5a View commit details
  3. 13.0.0

    wooorm committed Oct 3, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    wooorm Titus
    Copy the full SHA
    bdeeee5 View commit details
14 changes: 10 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

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

function compiler(node, file) {
var root = node && node.type && node.type === 'root'
var hast = toHast(node, {allowDangerousHtml: !clean, handlers: handlers})
var hast = toHast(node, {
allowDangerousHtml: !clean,
handlers: handlers,
commonmark: true
})
var result

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

result = toHtml(hast, xtend(settings, {allowDangerousHtml: !clean}))
result = toHtml(
hast,
Object.assign({}, settings, {allowDangerousHtml: !clean})
)

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

20 changes: 12 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-html",
"version": "12.0.0",
"version": "13.0.0",
"description": "remark plugin to compile Markdown to HTML",
"license": "MIT",
"keywords": [
@@ -36,26 +36,29 @@
"dependencies": {
"hast-util-sanitize": "^3.0.0",
"hast-util-to-html": "^7.0.0",
"mdast-util-to-hast": "^9.0.0",
"xtend": "^4.0.1"
"mdast-util-to-hast": "^9.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"commonmark.json": "^0.29.0",
"dtslint": "^3.0.0",
"dtslint": "^4.0.0",
"is-hidden": "^1.0.0",
"not": "^0.1.0",
"nyc": "^15.0.0",
"prettier": "^2.0.0",
"remark": "^12.0.0",
"rehype-parse": "^7.0.0",
"rehype-stringify": "^8.0.0",
"remark": "^13.0.0-alpha.0",
"remark-cli": "^8.0.0",
"remark-github": "^9.0.0",
"remark-preset-wooorm": "^7.0.0",
"remark-slug": "^6.0.0",
"remark-toc": "^7.0.0",
"tape": "^5.0.0",
"tinyify": "^2.0.0",
"tinyify": "^3.0.0",
"to-vfile": "^6.0.0",
"unified": "^9.0.0",
"xo": "^0.32.0"
"xo": "^0.33.0"
},
"scripts": {
"format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
@@ -86,7 +89,8 @@
"esnext": false,
"rules": {
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-includes": "off"
"unicorn/prefer-includes": "off",
"unicorn/prefer-optional-catch-binding": "off"
},
"ignores": [
"remark-html.js"
36 changes: 14 additions & 22 deletions readme.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,13 @@
> It’s probably smarter to use `remark-rehype` directly and benefit from the
> [**rehype**][rehype] ecosystem.
## Note!

This plugin is ready for the new parser in remark
([`remarkjs/remark#536`](https://github.com/remarkjs/remark/pull/536)).
The current and previous version of the plugin works with the current and
previous version of remark.

## Install

[npm][]:
@@ -47,7 +54,7 @@ var html = require('remark-html')
unified()
.use(markdown)
.use(html)
.process(fs.readFileSync('example.md'), function(err, file) {
.process(fs.readFileSync('example.md'), function (err, file) {
if (err) throw err
console.log(String(file))
})
@@ -79,7 +86,7 @@ All options except for `sanitize` and `handlers` are passed to
###### `options.handlers`

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

###### `options.sanitize`

@@ -88,8 +95,8 @@ How to sanitize the output (`Object` or `boolean`, default: `true`):
* `false`
— HTML is not sanitized, dangerous HTML persists
* `true`
— HTML is [`hast-util-sanitize`][sanitize] according to [GitHub’s sanitation
rules][github], dangerous HTML is dropped
— HTML is sanitized according to [GitHub’s sanitation rules][github],
dangerous HTML is dropped
* `Object`
— the object is treated as a `schema` for how to sanitize with
[`hast-util-sanitize`][sanitize], dangerous HTML is dropped
@@ -114,17 +121,6 @@ remark()
.processSync(/**/)
```

## CommonMark

> You still need to set `commonmark: true` in [`remark-parse`s
> options][remark-options].
[CommonMark][] support is a goal but not (yet) a necessity.
There are some (roughly 115 of 550, relating to inline precedence, lists,
emphasis and importance) issues which I’d like to cover in the future.
Note that this sounds like a lot, but they have to do with obscure differences
which do not often occur in the real world.

## Integrations

`remark-html` works great with:
@@ -224,9 +220,9 @@ abide by its terms.

[collective]: https://opencollective.com/unified

[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg

[chat]: https://spectrum.chat/unified/remark
[chat]: https://github.com/remarkjs/remark/discussions

[npm]: https://docs.npmjs.com/cli/install

@@ -244,8 +240,6 @@ abide by its terms.

[remark]: https://github.com/remarkjs/remark

[remark-options]: https://github.com/remarkjs/remark/tree/HEAD/packages/remark-parse#options

[remark-plugins]: https://github.com/remarkjs/remark/blob/HEAD/doc/plugins.md#list-of-plugins

[remark2rehype]: https://github.com/remarkjs/remark-rehype
@@ -264,16 +258,14 @@ abide by its terms.

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

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

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

[github]: https://github.com/syntax-tree/hast-util-sanitize#schema

[to-hast]: https://github.com/syntax-tree/mdast-util-to-hast#note

[commonmark]: https://commonmark.org

[integrations]: #integrations

[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
2 changes: 1 addition & 1 deletion test/fixtures/blockquote/output.html
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ <h1>Block Quote</h1>
</li>
<li>
<p>Normal list</p>
<p>Paragraph.</p>
</li>
</ul>
<p>Paragraph.</p>
</blockquote>
8 changes: 4 additions & 4 deletions test/fixtures/code/output.html
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@ <h1>Code</h1>
</code></pre>
<pre><code class="language-empty"></code></pre>
<pre><code class="language-tabs"> two spaces
one
two
one
mixed.
one
two
one
mixed.
</code></pre>
2 changes: 1 addition & 1 deletion test/fixtures/entities-named/output.html
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ <h1>Entities</h1>
<pre><code class="language-AT&amp;T">Something in the AT&amp;T language
</code></pre>
<p>Automatic links:</p>
<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>
<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>
<p>Link <code>href</code>:</p>
<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>
<p>Link <code>title</code>:</p>
2 changes: 1 addition & 1 deletion test/fixtures/entities-numerical/output.html
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ <h1>Entities</h1>
<pre><code class="language-AT&#x26;T">Something in the AT&#x26;T language
</code></pre>
<p>Automatic links:</p>
<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>
<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>
<p>Link <code>href</code>:</p>
<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>
<p>Link <code>title</code>:</p>
30 changes: 15 additions & 15 deletions test/fixtures/escape/output.html
Original file line number Diff line number Diff line change
@@ -19,21 +19,21 @@
<p>Pipe: |</p>
<p>Tilde: ~</p>
<p><strong>Commonmark:</strong></p>
<p>Quote: \"</p>
<p>Dollar: \$</p>
<p>Percentage: \%</p>
<p>Ampersand: \&#x26;</p>
<p>Single quote: \'</p>
<p>Comma: \,</p>
<p>Forward slash: \/</p>
<p>Colon: \:</p>
<p>Semicolon: \;</p>
<p>Less-than: \&#x3C;</p>
<p>Equals: \=</p>
<p>Question mark: \?</p>
<p>At-sign: \@</p>
<p>Caret: \^</p>
<p>New line: \
<p>Quote: "</p>
<p>Dollar: $</p>
<p>Percentage: %</p>
<p>Ampersand: &#x26;</p>
<p>Single quote: '</p>
<p>Comma: ,</p>
<p>Forward slash: /</p>
<p>Colon: :</p>
<p>Semicolon: ;</p>
<p>Less-than: &#x3C;</p>
<p>Equals: =</p>
<p>Question mark: ?</p>
<p>At-sign: @</p>
<p>Caret: ^</p>
<p>New line: <br>
only works in paragraphs.</p>
<p>Two spaces:<br>
only works in paragraphs.</p>
3 changes: 0 additions & 3 deletions test/fixtures/footnotes/config.json

This file was deleted.

83 changes: 0 additions & 83 deletions test/fixtures/footnotes/input.md

This file was deleted.

84 changes: 0 additions & 84 deletions test/fixtures/footnotes/output.html

This file was deleted.

8 changes: 4 additions & 4 deletions test/fixtures/images/output.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p><img src="http://example.com/favicon.ico" alt="Example" title="Example Image"></p>
<p><img src="http://example.com/favicon.ico" alt="Example"></p>
<p><img src="http://example.com/favicon.ico"></p>
<p><img src="" title="Example Image"></p>
<p><img src=""></p>
<p><img src=""></p>
<p><img src="http://example.com/favicon.ico" alt=""></p>
<p><img src="" alt="" title="Example Image"></p>
<p><img src="" alt=""></p>
<p><img src="" alt=""></p>
34 changes: 12 additions & 22 deletions test/fixtures/list/output.html
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
<h1>List</h1>
<ul>
<li>
<p><strong>One</strong>;</p>
</li>
<li>
<p><em>Two</em>;</p>
</li>
<li>
<p><del>Three</del>.</p>
</li>
<li>
<p>One;</p>
</li>
<li>
<p>Two;</p>
</li>
<li><strong>One</strong>;</li>
<li><em>Two</em>;</li>
<li>~~Three~~.</li>
</ul>
<ol>
<li>One;</li>
<li>Two;</li>
</ol>
<!-- -->
<ol start="4">
<li>
<p>Four.</p>
</li>
<li>
<p>Five.</p>
</li>
<li>Four.</li>
<li>Five.</li>
</ol>
<ul>
<li>
<p>Loose:</p>
<ul>
@@ -40,7 +30,7 @@ <h1>List</h1>
<li>Foxtrot.</li>
</ul>
</li>
</ol>
</ul>
<hr>
<pre><code>And a rule.
</code></pre>
6 changes: 3 additions & 3 deletions test/fixtures/references/output.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1>References</h1>
<p>Entities contains some serious entity tests relating to titles and links
in definitions.</p>
<p>However, the [missing], <a href="">missing</a>, and <a href="">missing</a> are omitted.</p>
<p>However, the ![missing], <img src="" alt="missing">, and <img src="" alt="missing"> are omitted.</p>
<p>Same goes for <a href=""></a> and <img src="">.</p>
<p>However, the [missing], [missing][], and [missing][missing] are omitted.</p>
<p>However, the ![missing], ![missing][], and ![missing][missing] are omitted.</p>
<p>Same goes for [][empty] and ![][empty].</p>
3 changes: 0 additions & 3 deletions test/fixtures/tables/config.json

This file was deleted.

7 changes: 0 additions & 7 deletions test/fixtures/tables/input.md

This file was deleted.

42 changes: 0 additions & 42 deletions test/fixtures/tables/output.html

This file was deleted.

3 changes: 0 additions & 3 deletions test/fixtures/yaml/config.json

This file was deleted.

5 changes: 0 additions & 5 deletions test/fixtures/yaml/input.md

This file was deleted.

1 change: 0 additions & 1 deletion test/fixtures/yaml/output.html

This file was deleted.

224 changes: 73 additions & 151 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -2,118 +2,29 @@

var path = require('path')
var fs = require('fs')
var assert = require('assert')
var test = require('tape')
var remark = require('remark')
var slug = require('remark-slug')
var toc = require('remark-toc')
var github = require('remark-github')
var commonmark = require('commonmark.json')
var vfile = require('to-vfile')
var hidden = require('is-hidden')
var not = require('not')
var unified = require('unified')
var parse = require('remark-parse')
var rehypeParse = require('rehype-parse')
var rehypeStringify = require('rehype-stringify')
var all = require('mdast-util-to-hast/lib/all')
var html = require('..')

var read = fs.readFileSync
var exists = fs.existsSync
var join = path.join

// By default, CommonMark failures are accepted.
// To fail on CommonMark exceptions, set the `CMARK` environment variable.
var ignoreCommonMarkException = !('CMARK' in global.process.env)

var integrationMap = {github: github, toc: toc}
var integrationRoot = join(__dirname, 'integrations')
var fixtureRoot = join(__dirname, 'fixtures')

var commonmarkOptions = {
entities: {escapeOnly: true, useNamedReferences: true},
commonmark: true,
yaml: false,
closeSelfClosing: true,
sanitize: false
}

// List of CommonMark tests I dissagree with.
// For reasoning, see `doc/commonmark.md`.
// Note that these differences have to do with not puting more time into
// features which IMHO produce less quality HTML.
// So if you’d like to write the features, I’ll gladly merge!
var commonmarkIgnore = [
// Exception 1.
247,
248,

// Exception 2.
3,
50,
76,
77,
80,
86,
89,
98,
118,
176,
230,
231,
233,
236,
257,
258,
261,
262,
263,
264,
265,
266,
267,
268,
269,
270,
395,
396,
433,
445,
520,
522,
551,

// Exception 3.
428,
477,
478,
479,
480,
481,
489,
493
]

var fixtures = fs.readdirSync(fixtureRoot)
var integrations = fs.readdirSync(integrationRoot)

fixtures = fixtures.filter(hidden)
integrations = integrations.filter(hidden)

var section
var start

commonmark.forEach(function (test, position) {
if (section !== test.section) {
section = test.section
start = position
}

test.relative = position - start + 1
})

test('remark-html()', function (t) {
var processor

t.equal(typeof html, 'function', 'should be a function')

t.doesNotThrow(function () {
html.call(remark())
remark().use(html).freeze()
}, 'should not throw if not passed options')

t.throws(
@@ -315,93 +226,104 @@ test('remark-html()', function (t) {

// Assert fixtures.
test('Fixtures', function (t) {
fixtures.forEach(function (fixture) {
var filepath = join(fixtureRoot, fixture)
var output = read(join(filepath, 'output.html'), 'utf-8')
var input = read(join(filepath, 'input.md'), 'utf-8')
var config = join(filepath, 'config.json')
var file = vfile(fixture + '.md')
var base = path.join(__dirname, 'fixtures')

fs.readdirSync(base).filter(not(hidden)).forEach(each)

t.end()

function each(name) {
var output = String(fs.readFileSync(path.join(base, name, 'output.html')))
var input = String(fs.readFileSync(path.join(base, name, 'input.md')))
var config = {}
var file = vfile(name + '.md')
var result

file.contents = input

config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {}
result = processSync(file, config)
try {
config = JSON.parse(fs.readFileSync(path.join(base, name, 'config.json')))
} catch (_) {}

t.equal(result, output, 'should work on `' + fixture + '`')
})
result = processSync(file, config)

t.end()
t.equal(result, output, 'should work on `' + name + '`')
}
})

// Assert CommonMark.
test('CommonMark', function (t) {
commonmark.forEach(function (test, n) {
var name = test.section + ' ' + test.relative
var file = vfile(name + '.md')
var result
var message
var exception
var start = 0
var section

file.contents = test.markdown
result = processSync(file, commonmarkOptions)
commonmark.forEach(each)

n += 1
t.end()

try {
assert.strictEqual(result, test.html)
} catch (error) {
exception = error
function each(example, index) {
if (section !== example.section) {
section = example.section
start = index
}

message = '(' + n + ') should work on ' + name

if (
commonmarkIgnore.indexOf(n) !== -1 ||
(ignoreCommonMarkException && exception)
) {
t.skip(message)
} else {
t.equal(result, test.html, message)
}
})
var actual = unified()
.use(parse)
.use(html)
.processSync(example.markdown)
.toString()

t.end()
var reformat = unified()
.use(rehypeParse, {fragment: true})
.use(rehypeStringify)

// Normalize meaningless stuff, like character references, `<hr />` is `<hr>`,
// etc.
t.equal(
String(reformat.processSync(actual)),
String(reformat.processSync(example.html)),
index + ': ' + example.section + ' (' + (index - start + 1) + ')'
)
}
})

// Assert integrations.
test('Integrations', function (t) {
integrations.forEach(function (integration) {
var filepath = join(integrationRoot, integration)
var output = read(join(filepath, 'output.html'), 'utf-8')
var input = read(join(filepath, 'input.md'), 'utf-8')
var config = join(filepath, 'config.json')
var file = vfile(integration + '.md')
var integrationMap = {github: github, toc: [slug, toc]}
var base = path.join(__dirname, 'integrations')

fs.readdirSync(base)
.filter(not(hidden))
// Ignore `github` for now, which needs to be updated for remark@next.
// To do: add gfm, footnotes, frontmatter integrations.
.filter((d) => d !== 'github')
.forEach(each)

t.end()

function each(name) {
var output = String(fs.readFileSync(path.join(base, name, 'output.html')))
var input = String(fs.readFileSync(path.join(base, name, 'input.md')))
var file = vfile(name + '.md')
var config = {}
var result

file.contents = input

config = exists(config) ? JSON.parse(read(config, 'utf-8')) : {}
try {
config = JSON.parse(fs.readFileSync(path.join(base, name, 'config.json')))
} catch (_) {}

config.sanitize = false

result = remark()
.data('settings', config)
.use(html, config)
.use(integrationMap[integration], config)
.use(integrationMap[name], config)
.processSync(file)
.toString()

t.equal(result, output, 'should work on `' + integration + '`')
})

t.end()
t.equal(result, output, 'should work on `' + name + '`')
}
})

function processSync(file, config) {
return remark()
.data('settings', config)
.use(html, config)
.processSync(file)
.toString()
return remark().use(html, config).processSync(file).toString()
}