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: 9ca09cf077fc5cad349f8fd0b32434a65ab1b3a6
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: 2133d209ab423ead9c6360ab93850f03a1101d8a
Choose a head ref
  • 15 commits
  • 26 files changed
  • 3 contributors

Commits on Jun 23, 2020

  1. Change master in links

    wooorm committed Jun 23, 2020

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2d05989 View commit details
  2. Update dev-dependencies

    wooorm committed Jun 23, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    Copy the full SHA
    f59c15d View commit details

Commits on Jul 11, 2020

  1. Add docs for handlers to readme.md

    Closes GH-33.
    
    Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
    Reviewed-by: Titus Wormer <tituswormer@gmail.com>
    muescha authored Jul 11, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    Copy the full SHA
    3806b30 View commit details

Commits on Jul 14, 2020

  1. Refactors docs on options.sanitize in readme.md

    Closes GH-35.
    
    Reviewed-by: Titus Wormer <tituswormer@gmail.com>
    muescha authored Jul 14, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    Copy the full SHA
    3126be4 View commit details

Commits on Jul 23, 2020

  1. Add types

    Closes GH-28.
    Closes GH-32.
    
    Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
    Reviewed-by: Jonathan Haines <jonno.haines@gmail.com>
    Reviewed-by: Junyoung Choi <fluke8259@gmail.com>
    Reviewed-by: Titus Wormer <tituswormer@gmail.com>
    TaylorBeeston authored Jul 23, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    Copy the full SHA
    87d88f7 View commit details
  2. 12.0.0

    wooorm committed Jul 23, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    Copy the full SHA
    60841bf View commit details

Commits on Aug 22, 2020

  1. Add Discussions

    wooorm authored Aug 22, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    zimme Simon Fridlund
    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.
    zimme Simon Fridlund
    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.
    zimme Simon Fridlund
    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.
    zimme Simon Fridlund
    Copy the full SHA
    efa1a5a View commit details
  3. 13.0.0

    wooorm committed Oct 3, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    bdeeee5 View commit details
  4. Update mdast-util-to-hast

    wooorm committed Oct 3, 2020

    Verified

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

    wooorm committed Oct 3, 2020

    Verified

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

Commits on Sep 7, 2021

  1. Fix to sanitize by default

    The docs have always said `remark-html` is safe by default.
    It wasn’t and this patches that.
    
    If you do want to be unsafe, use `remark-html` with `sanitize: false`:
    
    ```diff
      -.use(remarkHtml)
      +.use(remarkHtml, {sanitize: false})
    ```
    wooorm committed Sep 7, 2021

    Verified

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

    wooorm committed Sep 7, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2133d20 View commit details
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
coverage/
remark-html.js
remark-html.min.js
*.html
*.json
*.md
30 changes: 21 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
'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')

module.exports = plugin

function plugin(options) {
var settings = options || {}
var clean = settings.sanitize
var schema = clean && typeof clean === 'object' ? clean : null
var handlers = settings.handlers || {}
var settings = Object.assign({}, options || {})
let clean

if (typeof settings.sanitize === 'boolean') {
clean = settings.sanitize
settings.sanitize = undefined
}

if (typeof clean !== 'boolean') {
clean = true
}

this.Compiler = compiler

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: settings.handlers
})
var result

if (file.extname) {
file.extname = '.html'
}

if (clean) {
hast = sanitize(hast, schema)
hast = sanitize(hast, settings.sanitize)
}

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'
}

29 changes: 19 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "remark-html",
"version": "11.0.2",
"version": "13.0.2",
"description": "remark plugin to compile Markdown to HTML",
"license": "MIT",
"keywords": [
@@ -28,39 +28,47 @@
"Junyoung Choi <fluke8259@gmail.com>",
"Jonathan Soeder <jonathan.soeder@gmail.com>"
],
"types": "types/index.d.ts",
"files": [
"types/index.d.ts",
"index.js"
],
"dependencies": {
"hast-util-sanitize": "^2.0.0",
"hast-util-sanitize": "^3.0.0",
"hast-util-to-html": "^7.0.0",
"mdast-util-to-hast": "^8.2.0",
"xtend": "^4.0.1"
"mdast-util-to-hast": "^10.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"commonmark.json": "^0.29.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",
"xo": "^0.30.0"
"unified": "^9.0.0",
"xo": "^0.33.0"
},
"scripts": {
"format": "remark *.md -qfo && prettier --write \"**/*.js\" && xo --fix",
"format": "remark . -qfo --ignore-pattern test/ && prettier . --write && xo --fix",
"build-bundle": "browserify . -s remarkHtml > remark-html.js",
"build-mangle": "browserify . -s remarkHtml -p tinyify > remark-html.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test/index.js",
"test": "npm run format && npm run build && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
@@ -81,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"
68 changes: 36 additions & 32 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))
})
@@ -73,18 +80,26 @@ Serialize Markdown as HTML.

##### `options`

All options except for `sanitize` are passed to
All options except for `sanitize` and `handlers` are passed to
[`hast-util-to-html`][to-html].

###### `options.sanitize`
###### `options.handlers`

How to sanitize the output (`Object` or `boolean`, default: `true`).
Object mapping [mdast][] [nodes][mdast-node] to functions handling them.
This option is passed to [`mdast-util-to-hast`][to-hast-handlers].

If `false`, no HTML is sanitized, and dangerous HTML is left unescaped.
###### `options.sanitize`

How to sanitize the output (`Object` or `boolean`, default: `true`):

If `true` or an `object`, sanitation is done by [`hast-util-sanitize`][sanitize]
If an object is passed in, it’s given as a schema to `hast-util-sanitize`.
If `true`, input is sanitized according to [GitHub’s sanitation rules][github].
* `false`
— HTML is not sanitized, dangerous HTML persists
* `true`
— 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

> Note that raw HTML in Markdown cannot be sanitized, so it’s removed.
> A schema can still be used to allow certain values from [integrations][]
@@ -106,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:
@@ -129,7 +133,7 @@ which do not often occur in the real world.
— Highlight code blocks
* [`remark-html-emoji-image`](https://github.com/jackycute/remark-html-emoji-image)
— Transform emoji unicodes into html images
* [`remark-html-katex`](https://github.com/rokt33r/remark-math/blob/master/packages/remark-html-katex/readme.md)
* [`remark-html-katex`](https://github.com/remark/remark-math/blob/HEAD/packages/remark-html-katex/readme.md)
— Transform math to HTML with KaTeX
* [`remark-math`](https://github.com/rokt33r/remark-math)
— Math support for Markdown (inline and block)
@@ -194,7 +198,7 @@ abide by its terms.

<!-- Definitions -->

[build-badge]: https://img.shields.io/travis/remarkjs/remark-html/master.svg
[build-badge]: https://img.shields.io/travis/remarkjs/remark-html/main.svg

[build]: https://travis-ci.org/remarkjs/remark-html

@@ -216,52 +220,52 @@ 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

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

[contributing]: https://github.com/remarkjs/.github/blob/master/contributing.md
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md

[support]: https://github.com/remarkjs/.github/blob/master/support.md
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md

[coc]: https://github.com/remarkjs/.github/blob/master/code-of-conduct.md
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md

[license]: license

[author]: https://wooorm.com

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

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

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

[remark2rehype]: https://github.com/remarkjs/remark-rehype

[rehype]: https://github.com/rehypejs/rehype

[rehype-stringify]: https://github.com/rehypejs/rehype/tree/master/packages/rehype-stringify
[rehype-stringify]: https://github.com/rehypejs/rehype/tree/HEAD/packages/rehype-stringify

[raw]: https://github.com/rehypejs/rehype-raw

[mdast]: https://github.com/syntax-tree/mdast

[mdast-node]: https://github.com/syntax-tree/mdast#nodes

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

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

[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.

Loading