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: acdc1a772c16eac971b87d5c643eb2baa11b26f6
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

Commits on Dec 8, 2017

  1. Migrate to remarkjs

    wooorm committed Dec 8, 2017
    Copy the full SHA
    a331e1e View commit details
  2. Verified

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

Commits on Aug 10, 2018

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6b8997f View commit details
  2. Update Node in Travis

    wooorm committed Aug 10, 2018
    Copy the full SHA
    61f02fc View commit details
  3. Add .npmrc

    wooorm committed Aug 10, 2018
    Copy the full SHA
    a005c80 View commit details
  4. Add yarn.lock to .gitignore

    wooorm committed Aug 10, 2018
    Copy the full SHA
    0681def View commit details
  5. Fix typo

    wooorm committed Aug 10, 2018
    Copy the full SHA
    d7ebc1f View commit details
  6. Update build scripts

    wooorm committed Aug 10, 2018
    Copy the full SHA
    02d649b View commit details
  7. Update dev-dependencies

    wooorm committed Aug 10, 2018
    Copy the full SHA
    f1d8694 View commit details
  8. Refactor code-style

    wooorm committed Aug 10, 2018
    Copy the full SHA
    871283e View commit details
  9. Update remark-preset-wooorm

    wooorm committed Aug 10, 2018
    Copy the full SHA
    33258a2 View commit details
  10. Update hast-util-to-html

    wooorm committed Aug 10, 2018
    Copy the full SHA
    df4703d View commit details
  11. Add note about dangerous HTML and sanitation

    Closes GH-24.
    wooorm committed Aug 10, 2018
    Copy the full SHA
    22ac53c View commit details
  12. Fix token

    wooorm committed Aug 10, 2018
    Copy the full SHA
    883c68e View commit details
  13. 8.0.0

    wooorm committed Aug 10, 2018
    Copy the full SHA
    6b45f01 View commit details
  14. Add missing dev-dependency

    wooorm committed Aug 10, 2018
    Copy the full SHA
    05f8124 View commit details

Commits on Oct 22, 2018

  1. Move LICENSE > license

    wooorm committed Oct 22, 2018
    Copy the full SHA
    9442ec6 View commit details
  2. Update dev-dependencies

    wooorm committed Oct 22, 2018
    Copy the full SHA
    68e4449 View commit details

Commits on Nov 20, 2018

  1. Move URLs to HTTPS

    wooorm committed Nov 20, 2018
    Copy the full SHA
    2d15556 View commit details
  2. Add more badges

    wooorm committed Nov 20, 2018
    Copy the full SHA
    fee6e64 View commit details
  3. Copy the full SHA
    b350587 View commit details
  4. 9.0.0

    wooorm committed Nov 20, 2018
    Copy the full SHA
    41d0237 View commit details

Commits on Jun 16, 2019

  1. Update dev-dependencies

    wooorm committed Jun 16, 2019
    Copy the full SHA
    d0a73d8 View commit details
  2. Refactor comments

    wooorm committed Jun 16, 2019
    Copy the full SHA
    72b8661 View commit details
  3. Refactor to shout less

    wooorm committed Jun 16, 2019
    Copy the full SHA
    4bc5d7a View commit details
  4. Update Node in Travis

    wooorm committed Jun 16, 2019
    Copy the full SHA
    899f4a8 View commit details
  5. Fix typo

    wooorm committed Jun 16, 2019
    Copy the full SHA
    b3d4ebd View commit details
  6. Update package.json

    wooorm committed Jun 16, 2019
    Copy the full SHA
    12ceeb4 View commit details
  7. Refactor prose

    wooorm committed Jun 16, 2019
    Copy the full SHA
    b7a9bcd View commit details
  8. 9.0.1

    wooorm committed Jun 16, 2019
    Copy the full SHA
    402c422 View commit details
  9. Update mdast-util-to-hast

    wooorm committed Jun 16, 2019
    Copy the full SHA
    995b271 View commit details
  10. Update hast-util-to-html

    wooorm committed Jun 16, 2019
    Copy the full SHA
    04641d0 View commit details

Commits on Jul 1, 2019

  1. Update hast-util-sanitize

    wooorm committed Jul 1, 2019
    Copy the full SHA
    06628d8 View commit details

Commits on Jul 19, 2019

  1. Update dev-dependencies

    wooorm committed Jul 19, 2019
    Copy the full SHA
    e4442fe View commit details
  2. 10.0.0

    wooorm committed Jul 19, 2019
    Copy the full SHA
    0cd2dab View commit details

Commits on Jul 24, 2019

  1. Update dev-dependencies

    wooorm committed Jul 24, 2019
    Copy the full SHA
    81598c4 View commit details
  2. Fix wrong default description

    wooorm committed Jul 24, 2019
    Copy the full SHA
    fa0457b View commit details
  3. Add notes on security

    wooorm committed Jul 24, 2019
    Copy the full SHA
    3d726a4 View commit details

Commits on Mar 23, 2020

  1. Copy the full SHA
    3a263ef View commit details
  2. Add keyword

    wooorm committed Mar 23, 2020
    Copy the full SHA
    6f1ac2c View commit details
  3. Refactor prose

    wooorm committed Mar 23, 2020
    Copy the full SHA
    a58bda6 View commit details
  4. Update dev-dependencies

    wooorm committed Mar 23, 2020
    Copy the full SHA
    cd997a7 View commit details
  5. Update hast-util-to-html

    wooorm committed Mar 23, 2020
    Copy the full SHA
    558d4ad View commit details
  6. Update mdast-util-to-hast

    wooorm committed Mar 23, 2020
    Copy the full SHA
    7781ead View commit details
  7. 11.0.0

    wooorm committed Mar 23, 2020
    Copy the full SHA
    d2f4489 View commit details
  8. Fix releases

    wooorm committed Mar 23, 2020
    Copy the full SHA
    58bd10e View commit details
  9. Fix deprecation warning

    wooorm committed Mar 23, 2020
    Copy the full SHA
    e370aa5 View commit details
  10. 11.0.1

    wooorm committed Mar 23, 2020
    Copy the full SHA
    8a4d280 View commit details

Commits on May 13, 2020

  1. Update dev-dependencies

    wooorm committed May 13, 2020
    Copy the full SHA
    4e47853 View commit details
  2. Rename internal method

    Closes GH-29.
    Closes GH-30.
    
    Co-authored-by: Cristiano Betta <cristiano@betta.io>
    Co-authored-by: Aaron Reisman <aaron@lifeiscontent.net>
    3 people committed May 13, 2020
    Copy the full SHA
    faf7d1f View commit details
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -5,3 +5,4 @@ coverage/
node_modules/
remark-html.js
remark-html.min.js
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
coverage/
remark-html.js
remark-html.min.js
*.html
*.json
*.md
31 changes: 11 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
language: node_js
node_js:
- '4.0'
- '9.0'
- lts/dubnium
- node
after_script: bash <(curl -s https://codecov.io/bash)
deploy:
- provider: npm
skip_cleanup: true
email: tituswormer@gmail.com
api_key:
secure: Mx+xbzp3lsuFaDw8kvcYtyC6FZxyQ/yn8fQTl/76QDBTncKcVnuEjhdP7P4fGjvUogvAKnvj66tmpBZUi+Jgua0lY8D1z0qK6ECmQ3QVHVOi1MrwUSJ4EwWgmfCI+Sy2SvWYOVMCF7K1eia6DFz9zVeRLSGF3L5adhRffLnSegD/rElt1XaTQFam7xlG3QoQ8M056GU7HHom88yhWauBXkAG1TWiSftcJYj0jkY37+PDHP8ejoiMeio249QJByW5QxgEfQ6DFgliw7h9JRhozX0W6N6hoVmQ3xiJINbTacJ2tBQgNxs9C9BltCo/jbqV2qw0Pczy57IA+KNUcfq0z9tOss7xp7y4/3Ii1zc7g8pi+WQ+EbtOqgOgm3VJr81In8IHb0+F58CWWL20Cxbvof4ryxFsCuQ/ajqso8faAQhd+X/1A6/nGKGI1V09juhpBgajAdRgsjhBaPXlwMbwct2scWPS4by6mFXfwUX1bLF9YJ8QetQD5eKbTkVZoYIMSokRtU0voE47Thg5CzdHvWpjHWS2SHoaZQtQ5yBNoBhVTJXdkPcjobJygu7D+YeBkkMCVFk8JapF+SHlVehjFf//p2y8cp3PGYNSViFURf3letPGDx7kndSqBfwA65gybrY6G3II74ox/+60rFnqJdb6GR451IkgcgFQAD4uhgk=
on:
tags: true
node: '9.0'
- provider: releases
skip_cleanup: true
api_key:
secure: UWoYUAQpsaIYjq9Xa3CYP1sjWkI3hBC0DbYr8fDCB2cM5gH3zxGBQvhzGSX8XMzuWkQJnWfU5LElifb1lKUPoIcErgny3qZG61pD8jwEo9NgMFRrHGW9dYEXXXbBDfz7wCn2GfIAhNfTZj9zNoS7BVwUgxmB/+7JtDGWehTb4MXLKHQ8ff41FcLwSFk9ynq40Pcmy4aMKb6IY9ijQvZ/E4ReSFeidm1o4XGyHKSZec6oIWKDYLVb/7LNUQZ8rIjl2KwXDK8cNCHNYLC9dQTpMiHNu+9hBxeYDIz+P5e9NTWsf9FQK5+at8zoxKx34ZZARaOti2z9vZXYSkp44X8CkpQ6hEnVc6zBP3+FfIFmBYpEwrB9XOT7Ib5TdROSmi0no6wXkKc+t4OOZ3hnCWZfEjbEtqBUrhEmfi5qccvcPy5KdCyLi26BAQFXimayjU/i7Z597+uX55H+P2hI3PyTELzoKpK6mdHb04D7Gep50Cdlayd9ZqkRxoLKNG3IpJkN1kz5UTCBXswe1S3m0pcyTNL8HwoIQ8U040O/4xmpUhWhWQn78zbunOYBJ+d2UhH04SckpFjBVpbx59BtuirkhQeClfByKy9LQZGUAk1VjByn6HMmerj0NIzfbkb4gEPAadpqF8o6ISmiNyKV8tK9z2wjEP48HfLm/KV/S6ne4+k=
file:
- "remark-html.js"
- "remark-html.min.js"
on:
tags: true
node: '9.0'
provider: releases
skip_cleanup: true
api_key:
secure: Dk+BizJGxzQopL8tVdknG6+dB/6QyruT2qlbNNT3RRiJNDuji8Ux3certNqclRe4NtxfU+haOZDcQ+7mdoMATP6zwFEG5IAOuUUA5JMxTyVfDHG/SErae1nq9w7U4JkpuKNu+pbQlxL+BjkJaqkPJexElYnGxjJgcnh3hGjEpU3cIk/QrthFYq9Bd0PbrpHsaopTwzAMz1uiqWIA/mF03I+l3FC+iRYRqK/9TOhecYiMV0PT027Q1gnYwpDGVAvrkoFqtXWnDZxYRWqguwQXbTUvcoL8KdSeJXslKiS9YiqW/4Q+x9sM1KuycQK1DZi23g733nKtfnUX0NTHuAZ+Kihsgn0ltikI9F9JiFwwJ5kB9sGpE34Xjflr2+bBCsnAfMwK4Ao5tgBKJrHupK+dw5yg53+KmBL/WZTj/xy5ygI1mqcJT+282RTr7J8XGsNLrQP0C+PExFQbBVdqdvN72d/BRnPoI8ubUdMB0dgffkKEQkzPlOyE1MwoOy9ZyI9O7XXgXxZCPPRQoTCZmKR4mRkBgd5k3ZuV5nQWIC7vNihfEeqABz0S7Ed3DWvmu0aworH2wsI3GGAMFs/Ssi0MjhlEBp6dJ+zhJ86p+FY1BzHer2FzG4b4ouZFBcKmY1SN00b8XW1UhHhA3LSYq8HsEAMcMuRGvAn0UZb7oGq7R6I=
file:
- 'remark-html.js'
- 'remark-html.min.js'
on:
tags: true
56 changes: 33 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
'use strict';
'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');
var toHast = require('mdast-util-to-hast')
var toHtml = require('hast-util-to-html')
var sanitize = require('hast-util-sanitize')

module.exports = plugin;
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

this.Compiler = compiler;
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 result;
var root = node && node.type && node.type === 'root'
var hast = toHast(node, {
allowDangerousHtml: !clean,
handlers: settings.handlers
})
var result

if (file.extname) {
file.extname = '.html';
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 a final newline. */
if (root && result.charAt(result.length - 1) !== '\n') {
result += '\n';
// Add an eof eol.
if (root && result && /[^\r\n]/.test(result.charAt(result.length - 1))) {
result += '\n'
}

return result;
return result
}
}
File renamed without changes.
99 changes: 65 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,104 @@
{
"name": "remark-html",
"version": "7.0.0",
"description": "Compile Markdown to HTML with remark",
"version": "13.0.2",
"description": "remark plugin to compile Markdown to HTML",
"license": "MIT",
"keywords": [
"unified",
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"html",
"stringify",
"compile",
"remark"
"compile"
],
"repository": "https://github.com/wooorm/remark-html",
"bugs": "https://github.com/wooorm/remark-html/issues",
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"repository": "remarkjs/remark-html",
"bugs": "https://github.com/remarkjs/remark-html/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"Ben Briggs <beneb.info@gmail.com>",
"Seth Vincent <sethvincent@gmail.com>",
"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": "^1.0.0",
"hast-util-to-html": "^3.0.0",
"mdast-util-to-hast": "^3.0.0",
"xtend": "^4.0.1"
"hast-util-sanitize": "^3.0.0",
"hast-util-to-html": "^7.0.0",
"mdast-util-to-hast": "^10.0.0"
},
"devDependencies": {
"browserify": "^14.0.0",
"commonmark.json": "^0.27.0",
"esmangle": "^1.0.0",
"is-hidden": "^1.0.1",
"nyc": "^11.0.0",
"remark": "^8.0.0",
"remark-cli": "^4.0.0",
"remark-github": "^7.0.0",
"remark-preset-wooorm": "^3.0.0",
"remark-toc": "^4.0.0",
"tape": "^4.0.0",
"to-vfile": "^2.0.0",
"xo": "^0.18.0"
"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",
"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": "^3.0.0",
"to-vfile": "^6.0.0",
"unified": "^9.0.0",
"xo": "^0.33.0"
},
"scripts": {
"build-md": "remark *.md doc/*.md -qfo",
"build-bundle": "browserify index.js --bare -s remarkHTML > remark-html.js",
"build-mangle": "esmangle remark-html.js > remark-html.min.js",
"build": "npm run build-md && npm run build-bundle && npm run build-mangle",
"lint": "xo",
"test-api": "node test/index.js",
"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 build && npm run lint && 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,
"lines": 100,
"functions": 100,
"branches": 100
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"space": true,
"prettier": true,
"esnext": false,
"rules": {
"unicorn/no-fn-reference-in-iterator": "off",
"unicorn/prefer-includes": "off",
"unicorn/prefer-optional-catch-binding": "off"
},
"ignores": [
"remark-html.js"
]
},
"remarkConfig": {
"plugins": ["preset-wooorm"]
"plugins": [
"preset-wooorm"
]
}
}
225 changes: 142 additions & 83 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
# remark-html [![Build Status][build-badge]][build-status] [![Coverage Status][coverage-badge]][coverage-status] [![Chat][chat-badge]][chat]
# remark-html

Compile markdown to HTML with [**remark**][remark].
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]

> :warning: This package essentially packs [`remark-rehype`][remark2rehype] and
[**remark**][remark] plugin to serialize Markdown as HTML.

> ⚠️ This package essentially packs [`remark-rehype`][remark2rehype] and
> [`rehype-stringify`][rehype-stringify], and although it does support some
> customisation, it isn’t very pluggable. It’s probably smarter to use
> `remark-rehype` directly and benefit from the [**rehype**][rehype]
> ecosystem.
> customisation, it isn’t very pluggable.
> 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.

## Installation
## Install

[npm][]:

```bash
```sh
npm install remark-html
```

## Usage
## Use

Say we have the following file, `example.md`:

@@ -30,19 +45,19 @@ Say we have the following file, `example.md`:

And our script, `example.js`, looks as follows:

```javascript
var fs = require('fs');
var unified = require('unified');
var markdown = require('remark-parse');
var html = require('remark-html');
```js
var fs = require('fs')
var unified = require('unified')
var markdown = require('remark-parse')
var html = require('remark-html')

unified()
.use(markdown)
.use(html)
.process(fs.readFileSync('example.md'), function (err, file) {
if (err) throw err;
console.log(String(file));
});
if (err) throw err
console.log(String(file))
})
```

Now, running `node example` yields:
@@ -59,79 +74,86 @@ Now, running `node example` yields:

## API

### `remark.use(html[, options])`
### `remark().use(html[, options])`

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.handlers`

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

###### `options.sanitize`

How to sanitise the output (`Object` or `boolean`, default: `false`).
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 `sanitize`. If `true`, input is sanitised
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

For example, to add strict sanitation but allowing `className`s, use
something like:
> 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][]
> though.
> To support HTML in Markdown, use [`rehype-raw`][raw].
For example, to add strict sanitation but allowing `className`s, use something
like:

```js
// ...
var merge = require('deepmerge');
var github = require('hast-util-sanitize/lib/github');
var merge = require('deepmerge')
var github = require('hast-util-sanitize/lib/github')

var schema = merge(github, {attributes: {'*': ['className']}});
var schema = merge(github, {attributes: {'*': ['className']}})

remark().use(html, {sanitize: schema}).processSync(/*...*/);
remark()
.use(html, {sanitize: schema})
.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:

* [`remark-autolink-headings`](https://github.com/ben-eb/remark-autolink-headings)
— Automatically add links to headings in Markdown
* [`remark-github`](https://github.com/wooorm/remark-github)
* [`remark-github`](https://github.com/remarkjs/remark-github)
— Generate references to GitHub issues, PRs, users, and more
* [`remark-highlight.js`](https://github.com/ben-eb/remark-highlight.js)
— 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)
— Math support for Markdown (inline and block)
* [`remark-midas`](https://github.com/ben-eb/remark-midas)
— Highlight CSS code with [midas](https://github.com/ben-eb/midas)
* [`remark-toc`](https://github.com/wooorm/remark-toc)
* [`remark-toc`](https://github.com/remarkjs/remark-toc)
— Generate a Tables of Contents
* ...and [more][remark-plugins]
* and [more][remark-plugins]

All [**MDAST** nodes][mdast] can be compiled to HTML. Unknown **MDAST**
nodes are compiled to `div` nodes if they have `children` or `text` nodes
if they have `value`.
All [**mdast** nodes][mdast] can be compiled to HTML.
Unknown **mdast** nodes are compiled to `div` nodes if they have `children` or
`text` nodes if they have `value`.

In addition, **remark-html** can be told how to compile nodes through
three `data` properties ([more information][to-hast]):

* `hName` — Tag-name to compile as
* `hChildren` — HTML content to add (instead of `children` and `value`),
in [`HAST`][hast]
* `hProperties` — Map of attributes to add
* `hName` — Tag name to compile as
* `hChildren` — HTML content to add (instead of `children` and `value`), in
[`hast`][hast]
* `hProperties` — Map of properties to add

For example, the following node:

@@ -140,73 +162,110 @@ For example, the following node:
type: 'emphasis',
data: {
hName: 'i',
hProperties: {
className: 'foo'
},
hChildren: [{
type: 'text',
value: 'bar'
}]
hProperties: {className: 'foo'},
hChildren: [{type: 'text', value: 'bar'}]
},
children: [{
type: 'text',
value: 'baz',
}]
children: [{type: 'text', value: 'baz'}]
}
```

...would yield:
would yield:

```markdown
<i class="foo">bar</i>
```

## Security

Use of `remark-html` is *unsafe* by default and opens you up to a
[cross-site scripting (XSS)][xss] attack.
Pass `sanitize: true` to prevent attacks.
Settings `sanitize` to anything else may be unsafe.

## Contribute

See [`contributing.md`][contributing] in [`remarkjs/.github`][health] for ways
to get started.
See [`support.md`][support] for ways to get help.

This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.

## License

[MIT][license] © [Titus Wormer][author]

<!-- Definitions -->

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

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

[coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-html.svg

[build-status]: https://travis-ci.org/wooorm/remark-html
[coverage]: https://codecov.io/github/remarkjs/remark-html

[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/remark-html.svg
[downloads-badge]: https://img.shields.io/npm/dm/remark-html.svg

[coverage-status]: https://codecov.io/github/wooorm/remark-html
[downloads]: https://www.npmjs.com/package/remark-html

[chat-badge]: https://img.shields.io/gitter/room/wooorm/remark.svg
[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-html.svg

[chat]: https://gitter.im/wooorm/remark
[size]: https://bundlephobia.com/result?p=remark-html

[license]: LICENSE
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[author]: http://wooorm.com
[backers-badge]: https://opencollective.com/unified/backers/badge.svg

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

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

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

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

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

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

[support]: https://github.com/remarkjs/.github/blob/HEAD/support.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/wooorm/remark/tree/master/packages/remark-parse#options
[remark-plugins]: https://github.com/remarkjs/remark/blob/HEAD/doc/plugins.md#list-of-plugins

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

[remark-plugins]: https://github.com/wooorm/remark/blob/master/doc/plugins.md#list-of-plugins
[rehype]: https://github.com/rehypejs/rehype

[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

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

[rehype-stringify]: https://github.com/wooorm/rehype/tree/master/packages/rehype-stringify
[integrations]: #integrations

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

[hast]: https://github.com/syntax-tree/hast
[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.

443 changes: 185 additions & 258 deletions test/index.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// TypeScript Version: 3.5

import {Plugin} from 'unified'
import {HastUtilToHtmlOptions} from 'hast-util-to-html'
import {Schema} from 'hast-util-sanitize'
import {Handlers} from 'mdast-util-to-hast'

interface htmlOptions extends HastUtilToHtmlOptions {
/**
* How to sanitize the output
*/
sanitize?: boolean | Schema

/**
* Object mapping mdast nodes to functions handling them
*/
handlers?: Handlers
}

declare const html: Plugin<[htmlOptions?]>
export = html
9 changes: 9 additions & 0 deletions types/remark-html-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import unified = require('unified')
import html = require('remark-html')

unified().use(html)
unified().use(html, {preferUnquoted: true})
unified().use(html, {sanitize: false})
unified().use(html, {sanitize: false})
unified().use(html, {sanitize: {allowComments: false}})
unified().use(html, {handlers: {hr: (h, node) => h(node, 'hr')}})
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"remark-html": ["index.d.ts"]
}
}
}
7 changes: 7 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"semicolon": false,
"whitespace": false
}
}