@@ -56,7 +56,7 @@ turn HTML to markdown at a higher-level (easier) abstraction.
56
56
## Install
57
57
58
58
This package is [ ESM only] [ esm ] .
59
- In Node.js (version 14.14+ and 16.0 +), install with [ npm] [ ] :
59
+ In Node.js (version 16 +), install with [ npm] [ ] :
60
60
61
61
``` sh
62
62
npm install hast-util-to-mdast
@@ -108,8 +108,9 @@ console.log(markdown)
108
108
109
109
## API
110
110
111
- This package exports the identifiers [ ` defaultHandlers ` ] [ defaulthandlers ] ,
112
- [ ` defaultNodeHandlers ` ] [ defaultnodehandlers ] , and [ ` toMdast ` ] [ tomdast ] .
111
+ This package exports the identifiers [ ` defaultHandlers ` ] [ api-default-handlers ] ,
112
+ [ ` defaultNodeHandlers ` ] [ api-default-node-handlers ] , and
113
+ [ ` toMdast ` ] [ api-to-mdast ] .
113
114
There is no default export.
114
115
115
116
### ` toMdast(tree[, options]) `
@@ -120,7 +121,7 @@ Transform hast to mdast.
120
121
121
122
* ` tree ` ([ ` HastNode ` ] [ hast-node ] )
122
123
— hast tree to transform
123
- * ` options ` ([ ` Options ` ] [ options ] , optional)
124
+ * ` options ` ([ ` Options ` ] [ api- options] , optional)
124
125
— configuration
125
126
126
127
###### Returns
@@ -131,21 +132,21 @@ mdast tree ([`MdastNode`][mdast-node]).
131
132
132
133
Default handlers for elements (` Record<string, Handle> ` ).
133
134
134
- Each key is an element name, each value is a [ ` Handle ` ] [ handle ] .
135
+ Each key is an element name, each value is a [ ` Handle ` ] [ api- handle] .
135
136
136
137
### ` defaultNodeHandlers `
137
138
138
139
Default handlers for nodes (` Record<string, NodeHandle> ` ).
139
140
140
- Each key is a node type, each value is a [ ` NodeHandle ` ] [ nodehandle ] .
141
+ Each key is a node type, each value is a [ ` NodeHandle ` ] [ api-node-handle ] .
141
142
142
143
### ` Handle `
143
144
144
145
Handle a particular element (TypeScript type).
145
146
146
147
###### Parameters
147
148
148
- * ` state ` ([ ` State ` ] [ state ] )
149
+ * ` state ` ([ ` State ` ] [ api- state] )
149
150
— info passed around about the current state
150
151
* ` element ` ([ ` Element ` ] [ element ] )
151
152
— element to transform
@@ -154,15 +155,15 @@ Handle a particular element (TypeScript type).
154
155
155
156
###### Returns
156
157
157
- mdast node or nodes (` MdastNode | Array< MdastNode> | undefined ` ).
158
+ mdast node or nodes (` Array< MdastNode> | MdastNode | undefined` ).
158
159
159
160
### ` NodeHandle `
160
161
161
162
Handle a particular node (TypeScript type).
162
163
163
164
###### Parameters
164
165
165
- * ` state ` ([ ` State ` ] [ state ] )
166
+ * ` state ` ([ ` State ` ] [ api- state] )
166
167
— info passed around about the current state
167
168
* ` node ` (` any ` )
168
169
— node to transform
@@ -171,7 +172,7 @@ Handle a particular node (TypeScript type).
171
172
172
173
###### Returns
173
174
174
- mdast node or nodes (` MdastNode | Array< MdastNode> | undefined ` ).
175
+ mdast node or nodes (` Array< MdastNode> | MdastNode | undefined` ).
175
176
176
177
### ` Options `
177
178
@@ -213,7 +214,7 @@ guillemets, a fourth single, a fifth double again, etc.
213
214
214
215
###### ` document `
215
216
216
- Whether the given tree represents a complete document (` boolean? ` , default:
217
+ Whether the given tree represents a complete document (` boolean ` , default:
217
218
` undefined ` ).
218
219
219
220
Applies when the ` tree ` is a ` root ` node.
@@ -228,15 +229,15 @@ Object mapping tag names to functions handling the corresponding elements
228
229
(` Record<string, Handle> ` ).
229
230
230
231
Merged into the defaults.
231
- See [ ` Handle ` ] [ handle ] .
232
+ See [ ` Handle ` ] [ api- handle] .
232
233
233
234
###### ` nodeHandlers `
234
235
235
236
Object mapping node types to functions handling the corresponding nodes
236
237
(` Record<string, NodeHandle> ` ).
237
238
238
239
Merged into the defaults.
239
- See [ ` NodeHandle ` ] [ nodehandle ] .
240
+ See [ ` NodeHandle ` ] [ api-node-handle ] .
240
241
241
242
### ` State `
242
243
@@ -246,7 +247,7 @@ Info passed around about the current state (TypeScript type).
246
247
247
248
* ` patch ` (` (from: HastNode, to: MdastNode) => undefined ` )
248
249
— copy a node’s positional info
249
- * ` one ` (` (node: HastNode, parent: HastParent | undefined) => MdastNode | Array< MdastNode> | undefined ` )
250
+ * ` one ` (` (node: HastNode, parent: HastParent | undefined) => Array< MdastNode> | MdastNode | undefined ` )
250
251
— transform a hast node to mdast
251
252
* ` all ` (` (parent: HastParent) => Array<MdastContent> ` )
252
253
— transform the children of a hast parent to mdast
@@ -256,14 +257,14 @@ Info passed around about the current state (TypeScript type).
256
257
— turn arbitrary content into a list of a particular node type
257
258
* ` resolve ` (` (url: string | null | undefined) => string ` )
258
259
— resolve a URL relative to a base
259
- * ` options ` ([ ` Options ` ] [ options ] )
260
+ * ` options ` ([ ` Options ` ] [ api- options] )
260
261
— user configuration
261
262
* ` elementById ` (` Map<string, Element> ` )
262
263
— elements by their ` id `
263
264
* ` handlers ` (` Record<string, Handle> ` )
264
- — applied element handlers (see [ ` Handle ` ] [ handle ] )
265
+ — applied element handlers (see [ ` Handle ` ] [ api- handle] )
265
266
* ` nodeHandlers ` (` Record<string, NodeHandle> ` )
266
- — applied node handlers (see [ ` NodeHandle ` ] [ nodehandle ] )
267
+ — applied node handlers (see [ ` NodeHandle ` ] [ api-node-handle ] )
267
268
* ` baseFound ` (` boolean ` )
268
269
— whether a ` <base> ` element was seen
269
270
* ` frozenBaseUrl ` (` string | undefined ` )
@@ -331,8 +332,8 @@ This can be achieved with `example.js` like so:
331
332
332
333
import fs from ' node:fs/promises'
333
334
import {fromHtml } from ' hast-util-from-html'
334
- import {toMdast } from ' hast-util-to-mdast'
335
335
import {toHtml } from ' hast-util-to-html'
336
+ import {toMdast } from ' hast-util-to-mdast'
336
337
import {toMarkdown } from ' mdast-util-to-markdown'
337
338
338
339
const html = String (await fs .readFile (' example.html' ))
@@ -409,15 +410,20 @@ such as footnotes, frontmatter, or math.
409
410
## Types
410
411
411
412
This package is fully typed with [ TypeScript] [ ] .
412
- It exports the additional types [ ` Handle ` ] [ handle ] , [ ` NodeHandle ` ] [ nodehandle ] ,
413
- [ ` Options ` ] [ options ] , and [ ` State ` ] [ state ] .
413
+ It exports the additional types [ ` Handle ` ] [ api-handle ] ,
414
+ [ ` NodeHandle ` ] [ api-node-handle ] ,
415
+ [ ` Options ` ] [ api-options ] ,
416
+ and [ ` State ` ] [ api-state ] .
414
417
415
418
## Compatibility
416
419
417
- Projects maintained by the unified collective are compatible with all maintained
420
+ Projects maintained by the unified collective are compatible with maintained
418
421
versions of Node.js.
419
- As of now, that is Node.js 14.14+ and 16.0+.
420
- Our projects sometimes work with older versions, but this is not guaranteed.
422
+
423
+ When we cut a new major release, we drop support for unmaintained versions of
424
+ Node.
425
+ This means we try to keep the current release line, ` hast-util-to-mdast@^9 ` ,
426
+ compatible with Node.js 12.
421
427
422
428
## Security
423
429
@@ -458,9 +464,9 @@ abide by its terms.
458
464
459
465
[ downloads ] : https://www.npmjs.com/package/hast-util-to-mdast
460
466
461
- [ size-badge ] : https://img.shields.io/bundlephobia/minzip/ hast-util-to-mdast.svg
467
+ [ size-badge ] : https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q= hast-util-to-mdast
462
468
463
- [ size ] : https://bundlephobia .com/result?p =hast-util-to-mdast
469
+ [ size ] : https://bundlejs .com/?q =hast-util-to-mdast
464
470
465
471
[ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
466
472
@@ -516,16 +522,16 @@ abide by its terms.
516
522
517
523
[ rehype-remark ] : https://github.com/rehypejs/rehype-remark
518
524
519
- [ defaulthandlers ] : #defaulthandlers
525
+ [ api-default-handlers ] : #defaulthandlers
520
526
521
- [ defaultnodehandlers ] : #defaultnodehandlers
527
+ [ api-default-node-handlers ] : #defaultnodehandlers
522
528
523
- [ tomdast ] : #tomdasttree-options
529
+ [ api-to-mdast ] : #tomdasttree-options
524
530
525
- [ options ] : #options
531
+ [ api- options] : #options
526
532
527
- [ state ] : #state
533
+ [ api- state] : #state
528
534
529
- [ handle ] : #handle
535
+ [ api- handle] : #handle
530
536
531
- [ nodehandle ] : #nodehandle
537
+ [ api-node-handle ] : #nodehandle
0 commit comments