17
17
* [ Install] ( #install )
18
18
* [ Use] ( #use )
19
19
* [ API] ( #api )
20
- * [ ` toHast(tree[, options]) ` ] ( #tohasttree-options )
21
20
* [ ` defaultHandlers ` ] ( #defaulthandlers )
21
+ * [ ` toHast(tree[, options]) ` ] ( #tohasttree-options )
22
22
* [ ` Handler ` ] ( #handler )
23
23
* [ ` Handlers ` ] ( #handlers )
24
24
* [ ` Options ` ] ( #options )
@@ -62,7 +62,7 @@ turn markdown to HTML at a higher-level (easier) abstraction.
62
62
## Install
63
63
64
64
This package is [ ESM only] [ esm ] .
65
- In Node.js (version 14.14+ and 16.0 +), install with [ npm] [ ] :
65
+ In Node.js (version 16 +), install with [ npm] [ ] :
66
66
67
67
``` sh
68
68
npm install mdast-util-to-hast
@@ -94,9 +94,9 @@ Say we have the following `example.md`:
94
94
95
95
``` js
96
96
import {fs } from ' node:fs/promises'
97
+ import {toHtml } from ' hast-util-to-html'
97
98
import {fromMarkdown } from ' mdast-util-from-markdown'
98
99
import {toHast } from ' mdast-util-to-hast'
99
- import {toHtml } from ' hast-util-to-html'
100
100
101
101
const markdown = String (await fs .readFile (' example.md' ))
102
102
const mdast = fromMarkdown (markdown)
@@ -118,6 +118,10 @@ This package exports the identifiers [`defaultHandlers`][api-default-handlers]
118
118
and [ ` toHast ` ] [ api-to-hast ] .
119
119
There is no default export.
120
120
121
+ ### ` defaultHandlers `
122
+
123
+ Default handlers for nodes ([ ` Handlers ` ] [ api-handlers ] ).
124
+
121
125
### ` toHast(tree[, options]) `
122
126
123
127
Transform mdast to hast.
@@ -200,10 +204,6 @@ The default behavior for unknown nodes is:
200
204
201
205
This behavior can be changed by passing an ` unknownHandler ` .
202
206
203
- ### ` defaultHandlers `
204
-
205
- Default handlers for nodes ([ ` Handlers ` ] [ api-handlers ] ).
206
-
207
207
### ` Handler `
208
208
209
209
Handle a node (TypeScript).
@@ -346,11 +346,11 @@ The following example passes `allowDangerousHtml` to this utility
346
346
(` hast-util-sanitize ` ):
347
347
348
348
``` js
349
- import {fromMarkdown } from ' mdast-util-from-markdown'
350
- import {toHast } from ' mdast-util-to-hast'
351
349
import {raw } from ' hast-util-raw'
352
350
import {sanitize } from ' hast-util-sanitize'
353
351
import {toHtml } from ' hast-util-to-html'
352
+ import {fromMarkdown } from ' mdast-util-from-markdown'
353
+ import {toHast } from ' mdast-util-to-hast'
354
354
355
355
const markdown = ' It <i>works</i>! <img onerror="alert(1)">'
356
356
const mdast = fromMarkdown (markdown)
@@ -380,11 +380,11 @@ should translate the labels associated with them.
380
380
Let’s first set the stage:
381
381
382
382
``` js
383
- import {fromMarkdown } from ' mdast -util-from-markdown '
383
+ import {toHtml } from ' hast -util-to-html '
384
384
import {gfm } from ' micromark-extension-gfm'
385
+ import {fromMarkdown } from ' mdast-util-from-markdown'
385
386
import {gfmFromMarkdown } from ' mdast-util-gfm'
386
387
import {toHast } from ' mdast-util-to-hast'
387
- import {toHtml } from ' hast-util-to-html'
388
388
389
389
const markdown = ' Bonjour[^1]\n\n [^1]: Monde!'
390
390
const mdast = fromMarkdown (markdown, {
@@ -457,8 +457,8 @@ For example, when we represent a mark element in markdown and want to turn it
457
457
into a ` <mark> ` element in HTML, we can use a handler:
458
458
459
459
``` js
460
- import {toHast } from ' mdast-util-to-hast'
461
460
import {toHtml } from ' hast-util-to-html'
461
+ import {toHast } from ' mdast-util-to-hast'
462
462
463
463
const mdast = {
464
464
type: ' paragraph' ,
@@ -484,8 +484,8 @@ console.log(toHtml(hast))
484
484
We can do the same through certain fields on nodes:
485
485
486
486
``` js
487
- import {toHast } from ' mdast-util-to-hast'
488
487
import {toHtml } from ' hast-util-to-html'
488
+ import {toHast } from ' mdast-util-to-hast'
489
489
490
490
const mdast = {
491
491
type: ' paragraph' ,
@@ -1365,10 +1365,13 @@ visit(tree, function (node) {
1365
1365
1366
1366
## Compatibility
1367
1367
1368
- Projects maintained by the unified collective are compatible with all maintained
1368
+ Projects maintained by the unified collective are compatible with maintained
1369
1369
versions of Node.js.
1370
- As of now, that is Node.js 14.14+ and 16.0+.
1371
- Our projects sometimes work with older versions, but this is not guaranteed.
1370
+
1371
+ When we cut a new major release, we drop support for unmaintained versions of
1372
+ Node.
1373
+ This means we try to keep the current release line, ` mdast-util-to-hast@^12 ` ,
1374
+ compatible with Node.js 12.
1372
1375
1373
1376
## Security
1374
1377
@@ -1476,9 +1479,9 @@ abide by its terms.
1476
1479
1477
1480
[ downloads ] : https://www.npmjs.com/package/mdast-util-to-hast
1478
1481
1479
- [ size-badge ] : https://img.shields.io/bundlephobia/minzip/ mdast-util-to-hast.svg
1482
+ [ size-badge ] : https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q= mdast-util-to-hast
1480
1483
1481
- [ size ] : https://bundlephobia .com/result?p =mdast-util-to-hast
1484
+ [ size ] : https://bundlejs .com/?q =mdast-util-to-hast
1482
1485
1483
1486
[ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
1484
1487
0 commit comments