Socket
Socket
Sign inDemoInstall

remark-html

Package Overview
Dependencies
Maintainers
2
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-html - npm Package Compare versions

Comparing version 15.0.2 to 16.0.0

lib/index.d.ts

47

index.d.ts

@@ -1,29 +0,22 @@

export default function remarkHtml(
this: import('unified').Processor<
void,
import('mdast').Root,
import('mdast').Root,
string
>,
...settings: [(Options | undefined)?] | []
): void
export type Root = import('mdast').Root
export type Schema = import('hast-util-sanitize').Schema
import type {Root} from 'mdast'
import type {Plugin} from 'unified'
import type {Options} from './lib/index.js'
export type {Options} from './lib/index.js'
/**
* Configuration (optional).
* Add support for serializing to HTML.
*
* @this
* Unified processor.
* @param
* Configuration (optional).
* @returns
* Nothing.
*/
export type ExtraOptionsFields = {
/**
* How to sanitize the output.
*/
sanitize?:
| boolean
| import('hast-util-sanitize/lib').Schema
| null
| undefined
/**
* Object mapping mdast nodes to functions handling them.
*/
handlers?: import('mdast-util-to-hast').Handlers | undefined
}
export type Options = import('hast-util-to-html').Options & ExtraOptionsFields
declare const remarkHtml: Plugin<
[(Readonly<Options> | null | undefined)?],
Root,
string
>
export default remarkHtml

@@ -1,70 +0,2 @@

/**
* @typedef {import('mdast').Root} Root
* @typedef {import('hast-util-sanitize').Schema} Schema
*
* @typedef ExtraOptionsFields
* Configuration (optional).
* @property {boolean|Schema|null} [sanitize]
* How to sanitize the output.
* @property {import('mdast-util-to-hast').Handlers} [handlers={}]
* Object mapping mdast nodes to functions handling them.
*
* @typedef {import('hast-util-to-html').Options & ExtraOptionsFields} Options
*/
import {toHtml} from 'hast-util-to-html'
import {sanitize} from 'hast-util-sanitize'
import {toHast} from 'mdast-util-to-hast'
/**
* Plugin to serialize markdown as HTML.
*
* @this {import('unified').Processor}
* @type {import('unified').Plugin<[Options?] | [], Root, string>}
*/
export default function remarkHtml(settings = {}) {
const options = {...settings}
/** @type {boolean|undefined} */
let clean
if (typeof options.sanitize === 'boolean') {
clean = options.sanitize
options.sanitize = undefined
}
if (typeof clean !== 'boolean') {
clean = true
}
Object.assign(this, {Compiler: compiler})
/**
* @type {import('unified').CompilerFunction<Root, string>}
*/
function compiler(node, file) {
const hast = toHast(node, {
allowDangerousHtml: !clean,
handlers: options.handlers
})
// @ts-expect-error: assume root.
const cleanHast = clean ? sanitize(hast, options.sanitize) : hast
const result = toHtml(
// @ts-expect-error: assume root.
cleanHast,
Object.assign({}, options, {allowDangerousHtml: !clean})
)
if (file.extname) {
file.extname = '.html'
}
// Add an eof eol.
return node &&
node.type &&
node.type === 'root' &&
result &&
/[^\r\n]/.test(result.charAt(result.length - 1))
? result + '\n'
: result
}
}
// Note: types exposed from `index.d.ts`.
export {default} from './lib/index.js'
{
"name": "remark-html",
"version": "15.0.2",
"version": "16.0.0",
"description": "remark plugin to compile Markdown to HTML",
"license": "MIT",
"keywords": [
"unified",
"compile",
"html",
"markdown",
"mdast",
"plugin",
"remark",
"remark-plugin",
"plugin",
"mdast",
"markdown",
"html",
"stringify",
"compile"
"unified"
],

@@ -33,5 +33,5 @@ "repository": "remarkjs/remark-html",

"type": "module",
"main": "index.js",
"types": "index.d.ts",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",

@@ -41,52 +41,47 @@ "index.js"

"dependencies": {
"@types/mdast": "^3.0.0",
"hast-util-sanitize": "^4.0.0",
"hast-util-to-html": "^8.0.0",
"mdast-util-to-hast": "^12.0.0",
"unified": "^10.0.0"
"@types/mdast": "^4.0.0",
"hast-util-sanitize": "^5.0.0",
"mdast-util-to-hast": "^13.0.0",
"unified": "^11.0.0"
},
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
"@types/hast": "^3.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"commonmark.json": "^0.30.0",
"is-hidden": "^2.0.0",
"prettier": "^2.0.0",
"rehype-parse": "^8.0.0",
"rehype-stringify": "^9.0.0",
"remark": "^14.0.0",
"remark-cli": "^10.0.0",
"remark-frontmatter": "^4.0.0",
"remark-gfm": "^3.0.0",
"remark-github": "^11.0.0",
"hast-util-from-html": "^2.0.0",
"hast-util-to-html": "^9.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-frontmatter": "^5.0.0",
"remark-gfm": "^4.0.0",
"remark-github": "^12.0.0",
"remark-parse": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-slug": "^7.0.0",
"remark-toc": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"to-vfile": "^7.0.0",
"remark-toc": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.47.0"
"typescript": "^5.0.0",
"vfile": "^6.0.0",
"xo": "^0.56.0"
},
"scripts": {
"build": "rimraf \"test/**/*.d.ts\" \"*.d.ts\" && tsc && type-coverage",
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && xo --fix",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . --frail --output --quiet && prettier . --log-level warn --write && xo --fix",
"prepack": "npm run build && npm run format",
"test": "npm run build && npm run format && npm run test-coverage",
"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"
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
"remark-preset-wooorm"
]

@@ -97,5 +92,29 @@ },

"detail": true,
"strict": true,
"ignoreCatch": true
"ignoreCatch": true,
"strict": true
},
"xo": {
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/ban-types": "off"
}
},
{
"files": [
"test/**/*.js"
],
"rules": {
"no-await-in-loop": "off"
}
}
],
"prettier": true,
"rules": {
"unicorn/prefer-at": "off"
}
}
}

@@ -21,2 +21,3 @@ # remark-html

* [`unified().use(remarkHtml[, options])`](#unifieduseremarkhtml-options)
* [`Options`](#options)
* [Types](#types)

@@ -34,15 +35,7 @@ * [Compatibility](#compatibility)

**unified** is a project that transforms content with abstract syntax trees
(ASTs).
**remark** adds support for markdown to unified.
**rehype** adds support for HTML to unified.
**mdast** is the markdown AST that remark uses.
**hast** is the HTML AST that rehype uses.
This is a remark plugin that adds a compiler to compile mdast to hast and then
to a string.
## When should I use this?
This plugin is useful when you want to turn markdown into HTML.
It’s a shortcut for `.use(remarkRehype).use(rehypeStringify)`.
It’s a shortcut for
`.use(remarkRehype).use(rehypeSanitize).use(rehypeStringify)`.

@@ -76,4 +69,4 @@ The reason that there are different ecosystems for markdown and HTML is that

This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]:
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:

@@ -87,3 +80,3 @@ ```sh

```js
import remarkHtml from 'https://esm.sh/remark-html@15'
import remarkHtml from 'https://esm.sh/remark-html@16'
```

@@ -95,3 +88,3 @@

<script type="module">
import remarkHtml from 'https://esm.sh/remark-html@15?bundle'
import remarkHtml from 'https://esm.sh/remark-html@16?bundle'
</script>

@@ -105,39 +98,32 @@ ```

```markdown
# Hello & World
# Pluto
> A block quote.
* Some _emphasis_, **importance**, and `code`.
**Pluto** (minor-planet designation: **134340 Pluto**) is a
[dwarf planet](https://en.wikipedia.org/wiki/Dwarf_planet) in the
[Kuiper belt](https://en.wikipedia.org/wiki/Kuiper_belt).
```
And our module `example.js` looks as follows:
…and a module `example.js`:
```js
import remarkHtml from 'remark-html'
import remarkParse from 'remark-parse'
import {read} from 'to-vfile'
import {unified} from 'unified'
import remarkParse from 'remark-parse'
import remarkHtml from 'remark-html'
main()
const file = await unified()
.use(remarkParse)
.use(remarkHtml)
.process(await read('example.md'))
async function main() {
const file = await unified()
.use(remarkParse)
.use(remarkHtml)
.process(await read('example.md'))
console.log(String(file))
}
console.log(String(file))
```
Now running `node example.js` yields:
…then running `node example.js` yields:
```html
<h1>Hello &#x26; World</h1>
<blockquote>
<p>A block quote.</p>
</blockquote>
<ul>
<li>Some <em>emphasis</em>, <strong>importance</strong>, and <code>code</code>.</li>
</ul>
<h1>Pluto</h1>
<p><strong>Pluto</strong> (minor-planet designation: <strong>134340 Pluto</strong>) is a
<a href="https://en.wikipedia.org/wiki/Dwarf_planet">dwarf planet</a> in the
<a href="https://en.wikipedia.org/wiki/Kuiper_belt">Kuiper belt</a>.</p>
```

@@ -148,54 +134,62 @@

This package exports no identifiers.
The default export is `remarkHtml`.
The default export is [`remarkHtml`][api-remark-html].
### `unified().use(remarkHtml[, options])`
Add support for serializing HTML.
Serialize markdown as HTML.
##### `options`
###### Parameters
Configuration (optional).
All options other than `sanitize` and `handlers` are passed to
[`hast-util-to-html`][hast-util-to-html].
* `options` ([`Options`][api-options], optional)
— configuration
###### `options.handlers`
###### Returns
This option is a bit advanced as it requires knowledge of ASTs, so we defer
to the documentation available in
[`mdast-util-to-hast`][mdast-util-to-hast].
Transform ([`Transformer`][unified-transformer]).
###### `options.sanitize`
###### Notes
How to sanitize the output (`Object` or `boolean`, default: `true`):
Passing `sanitize: false` is dangerous.
It allows arbitrary HTML and does not sanitize elements.
* `false`
— output is not sanitized, dangerous raw HTML persists
* `true`
— output is sanitized according to [GitHub’s sanitation rules][github],
dangerous raw HTML is dropped
* `Object`
— `schema` that defines how to sanitize output with
[`hast-util-sanitize`][sanitize], dangerous raw HTML is dropped
### `Options`
Configuration (TypeScript type).
###### Fields
* `handlers` ([`Handlers` from
`mdast-util-to-hast`][mdast-util-to-hast-handlers], optional)
— how to turn mdast nodes into hast nodes
* `sanitize` ([`Schema` from
`hast-util-sanitize`][hast-util-sanitize-schema] or `boolean`, default:
`true`)
— sanitize the output, and how
* `...toHtmlOptions` ([`Options` from
`hast-util-to-html`][hast-util-to-html-options], optional)
— other options are passed to `hast-util-to-html`
## Types
This package is fully typed with [TypeScript][].
It exports an `Options` type, which specifies the interface of the accepted
options.
It exports the additional type [`Options`][api-options].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
This plugin works with `unified` version 6+ and `remark` version 7+.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `remark-html@^16`,
compatible with Node.js 16.
This plugin works with `unified` version 6+ and `remark` version 15+.
## Security
Use of `remark-html` is **unsafe** by default and opens you up to
[cross-site scripting (XSS)][xss] attacks.
Pass `sanitize: true` to prevent attacks.
Setting `sanitize` to anything else can be unsafe.
Use of `remark-html` is safe by default.
Passing `sanitize: false` is unsafe and opens you up to
[cross-site scripting (XSS)][wiki-xss] attacks.
A safe schema is used by default, but passing an unsafe schema is unsafe.

@@ -237,5 +231,5 @@ ## Related

[size-badge]: https://img.shields.io/bundlephobia/minzip/remark-html.svg
[size-badge]: https://img.shields.io/bundlejs/size/remark-html
[size]: https://bundlephobia.com/result?p=remark-html
[size]: https://bundlejs.com/?q=remark-html

@@ -254,2 +248,4 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg

[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh

@@ -269,28 +265,32 @@

[unified]: https://github.com/unifiedjs/unified
[hast-util-sanitize-schema]: https://github.com/syntax-tree/hast-util-sanitize#schema
[remark]: https://github.com/remarkjs/remark
[hast-util-to-html-options]: https://github.com/syntax-tree/hast-util-to-html#options
[github]: https://github.com/syntax-tree/hast-util-sanitize#schema
[mdast-util-to-hast-handlers]: https://github.com/syntax-tree/mdast-util-to-hast#handlers
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[rehype-format]: https://github.com/rehypejs/rehype-format
[typescript]: https://www.typescriptlang.org
[rehype-highlight]: https://github.com/rehypejs/rehype-highlight
[remark-rehype]: https://github.com/remarkjs/remark-rehype
[rehype-meta]: https://github.com/rehypejs/rehype-meta
[rehype-minify]: https://github.com/rehypejs/rehype-minify
[rehype-format]: https://github.com/rehypejs/rehype-format
[rehype-stringify]: https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify
[rehype-highlight]: https://github.com/rehypejs/rehype-highlight
[remark]: https://github.com/remarkjs/remark
[rehype-meta]: https://github.com/rehypejs/rehype-meta
[remark-rehype]: https://github.com/remarkjs/remark-rehype
[rehype-stringify]: https://github.com/rehypejs/rehype/tree/main/packages/rehype-stringify
[typescript]: https://www.typescriptlang.org
[sanitize]: https://github.com/syntax-tree/hast-util-sanitize
[unified]: https://github.com/unifiedjs/unified
[hast-util-to-html]: https://github.com/syntax-tree/hast-util-to-html
[unified-transformer]: https://github.com/unifiedjs/unified#transformer
[mdast-util-to-hast]: https://github.com/syntax-tree/mdast-util-to-hast
[wiki-xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[api-options]: #options
[api-remark-html]: #unifieduseremarkhtml-options
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc