remark-html
Advanced tools
Comparing version 13.0.1 to 14.0.0
74
index.js
@@ -1,21 +0,44 @@ | ||
'use strict' | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('hast-util-sanitize').Schema} Schema | ||
* @typedef {import('mdast-util-to-hast').Handlers} Handlers | ||
* | ||
* @typedef Options | ||
* Configuration. | ||
* @property {boolean|Schema|null} [sanitize] | ||
* How to sanitize the output. | ||
* @property {Handlers} [handlers={}] | ||
* Object mapping mdast nodes to functions handling them. | ||
*/ | ||
var toHast = require('mdast-util-to-hast') | ||
var toHtml = require('hast-util-to-html') | ||
var sanitize = require('hast-util-sanitize') | ||
import {toHtml} from 'hast-util-to-html' | ||
import {sanitize} from 'hast-util-sanitize' | ||
import {toHast} from 'mdast-util-to-hast' | ||
module.exports = plugin | ||
/** | ||
* Plugin to serialize markdown as HTML. | ||
* | ||
* @type {import('unified').Plugin<[Options?]|void[], Root, string>} | ||
*/ | ||
export default function remarkHtml(options = {}) { | ||
const handlers = options.handlers || {} | ||
const schema = | ||
options.sanitize && typeof options.sanitize === 'object' | ||
? options.sanitize | ||
: undefined | ||
function plugin(options) { | ||
var settings = options || {} | ||
var clean = settings.sanitize | ||
var schema = clean && typeof clean === 'object' ? clean : null | ||
var handlers = settings.handlers || {} | ||
Object.assign(this, {Compiler: compiler}) | ||
this.Compiler = compiler | ||
/** | ||
* @type {import('unified').CompilerFunction<Root, string>} | ||
*/ | ||
function compiler(node, file) { | ||
var root = node && node.type && node.type === 'root' | ||
var hast = toHast(node, {allowDangerousHtml: !clean, handlers: handlers}) | ||
var result | ||
const hast = toHast(node, {allowDangerousHtml: !options.sanitize, handlers}) | ||
// @ts-expect-error: assume root. | ||
const cleanHast = options.sanitize ? sanitize(hast, schema) : hast | ||
const result = toHtml( | ||
// @ts-expect-error: assume root. | ||
cleanHast, | ||
Object.assign({}, options, {allowDangerousHtml: !options.sanitize}) | ||
) | ||
@@ -26,18 +49,11 @@ if (file.extname) { | ||
if (clean) { | ||
hast = sanitize(hast, schema) | ||
} | ||
result = toHtml( | ||
hast, | ||
Object.assign({}, settings, {allowDangerousHtml: !clean}) | ||
) | ||
// Add an eof eol. | ||
if (root && result && /[^\r\n]/.test(result.charAt(result.length - 1))) { | ||
result += '\n' | ||
} | ||
return result | ||
return node && | ||
node.type && | ||
node.type === 'root' && | ||
result && | ||
/[^\r\n]/.test(result.charAt(result.length - 1)) | ||
? result + '\n' | ||
: result | ||
} | ||
} |
{ | ||
"name": "remark-html", | ||
"version": "13.0.1", | ||
"version": "14.0.0", | ||
"description": "remark plugin to compile Markdown to HTML", | ||
@@ -31,50 +31,48 @@ "license": "MIT", | ||
], | ||
"types": "types/index.d.ts", | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"types/index.d.ts", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"hast-util-sanitize": "^3.0.0", | ||
"hast-util-to-html": "^7.0.0", | ||
"mdast-util-to-hast": "^10.0.0" | ||
"@types/mdast": "^3.0.0", | ||
"hast-util-sanitize": "^4.0.0", | ||
"hast-util-to-html": "^8.0.0", | ||
"mdast-util-to-hast": "^11.0.0", | ||
"unified": "^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", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"commonmark.json": "^0.30.0", | ||
"is-hidden": "^2.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", | ||
"rehype-parse": "^8.0.0", | ||
"rehype-stringify": "^9.0.0", | ||
"remark": "^14.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-footnotes": "^4.0.0", | ||
"remark-frontmatter": "^4.0.0", | ||
"remark-gfm": "^1.0.0", | ||
"remark-github": "^10.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-slug": "^6.0.0", | ||
"remark-toc": "^7.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^3.0.0", | ||
"to-vfile": "^6.0.0", | ||
"unified": "^9.0.0", | ||
"xo": "^0.33.0" | ||
"to-vfile": "^7.0.0", | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.43.0" | ||
}, | ||
"scripts": { | ||
"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-types": "dtslint types", | ||
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types" | ||
"build": "rimraf \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -89,12 +87,3 @@ "tabWidth": 2, | ||
"xo": { | ||
"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" | ||
] | ||
"prettier": true | ||
}, | ||
@@ -105,3 +94,9 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -28,2 +28,5 @@ # remark-html | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -47,15 +50,17 @@ | ||
And our script, `example.js`, looks as follows: | ||
And our module, `example.js`, looks as follows: | ||
```js | ||
var fs = require('fs') | ||
var unified = require('unified') | ||
var markdown = require('remark-parse') | ||
var html = require('remark-html') | ||
import fs from 'node:fs' | ||
import {unified} from 'unified' | ||
import remarkParse from 'remark-parse' | ||
import remarkHtml from 'remark-html' | ||
const buf = fs.readFileSync('example.md') | ||
unified() | ||
.use(markdown) | ||
.use(html) | ||
.process(fs.readFileSync('example.md'), function (err, file) { | ||
if (err) throw err | ||
.use(remarkParse) | ||
.use(remarkHtml) | ||
.process(buf) | ||
.then((file) => { | ||
console.log(String(file)) | ||
@@ -79,4 +84,7 @@ }) | ||
### `remark().use(html[, options])` | ||
This package exports no identifiers. | ||
The default export is `remarkHtml`. | ||
### `unified().use(remarkHtml[, options])` | ||
Serialize Markdown as HTML. | ||
@@ -141,3 +149,3 @@ | ||
— Transform math to HTML with KaTeX | ||
* [`remark-math`](https://github.com/rokt33r/remark-math) | ||
* [`remark-math`](https://github.com/remarkjs/remark-math) | ||
— Math support for Markdown (inline and block) | ||
@@ -205,5 +213,5 @@ * [`remark-midas`](https://github.com/ben-eb/remark-midas) | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-html/main.svg | ||
[build-badge]: https://github.com/remarkjs/remark-html/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/remarkjs/remark-html | ||
[build]: https://github.com/remarkjs/remark-html/actions | ||
@@ -210,0 +218,0 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-html.svg |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13948
78
280
Yes
5
22
+ Added@types/mdast@^3.0.0
+ Addedunified@^10.0.0
+ Added@types/hast@2.3.10(transitive)
+ Added@types/mdurl@1.0.5(transitive)
+ Added@types/parse5@6.0.3(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedccount@2.0.1(transitive)
+ Addedcharacter-entities-html4@2.1.0(transitive)
+ Addedcharacter-entities-legacy@3.0.0(transitive)
+ Addedcomma-separated-tokens@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhast-util-from-parse5@7.1.2(transitive)
+ Addedhast-util-parse-selector@3.1.1(transitive)
+ Addedhast-util-raw@7.2.3(transitive)
+ Addedhast-util-sanitize@4.1.0(transitive)
+ Addedhast-util-to-html@8.0.4(transitive)
+ Addedhast-util-to-parse5@7.1.0(transitive)
+ Addedhast-util-whitespace@2.0.1(transitive)
+ Addedhastscript@7.2.0(transitive)
+ Addedhtml-void-elements@2.0.1(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedmdast-util-definitions@5.1.2(transitive)
+ Addedmdast-util-to-hast@11.3.0(transitive)
+ Addedparse5@6.0.1(transitive)
+ Addedproperty-information@6.5.0(transitive)
+ Addedspace-separated-tokens@2.0.2(transitive)
+ Addedstringify-entities@4.0.4(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-builder@3.0.1(transitive)
+ Addedunist-util-generated@2.0.1(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-position@4.0.4(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-location@4.1.0(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedweb-namespaces@2.0.1(transitive)
+ Addedzwitch@2.0.4(transitive)
- Removedccount@1.1.0(transitive)
- Removedcharacter-entities-html4@1.1.4(transitive)
- Removedcharacter-entities-legacy@1.1.4(transitive)
- Removedcomma-separated-tokens@1.0.8(transitive)
- Removedhast-util-is-element@1.1.0(transitive)
- Removedhast-util-sanitize@3.0.2(transitive)
- Removedhast-util-to-html@7.1.3(transitive)
- Removedhast-util-whitespace@1.0.4(transitive)
- Removedhtml-void-elements@1.0.5(transitive)
- Removedmdast-util-definitions@4.0.0(transitive)
- Removedmdast-util-to-hast@10.2.0(transitive)
- Removedproperty-information@5.6.0(transitive)
- Removedspace-separated-tokens@1.1.5(transitive)
- Removedstringify-entities@3.1.0(transitive)
- Removedunist-builder@2.0.3(transitive)
- Removedunist-util-generated@1.1.6(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-position@3.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
- Removedxtend@4.0.2(transitive)
Updatedhast-util-sanitize@^4.0.0
Updatedhast-util-to-html@^8.0.0
Updatedmdast-util-to-hast@^11.0.0