33[ ![ Build] [ build-badge ]] [ build ]
44[ ![ Coverage] [ coverage-badge ]] [ coverage ]
55[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6+ [ ![ Size] [ size-badge ]] [ size ]
7+ [ ![ Sponsors] [ sponsors-badge ]] [ collective ]
8+ [ ![ Backers] [ backers-badge ]] [ collective ]
69[ ![ Chat] [ chat-badge ]] [ chat ]
710
8- Transform [ hast] [ ] (HTML) to [ mdast] [ ] (markdown) .
11+ [ ** hast** ] [ hast ] utility to transform to [ ** mdast** ] [ mdast ] .
912
1013> ** Note** : You probably want to use [ rehype-remark] [ ] .
1114
12- ## Installation
15+ ## Install
1316
1417[ npm] [ ] :
1518
16- ``` bash
19+ ``` sh
1720npm install hast-util-to-mdast
1821```
1922
@@ -27,7 +30,7 @@ Say we have the following `example.html`:
2730
2831…and next to it, ` example.js ` :
2932
30- ``` javascript
33+ ``` js
3134var unified = require (' unified' )
3235var parse = require (' rehype-parse' )
3336var stringify = require (' remark-stringify' )
@@ -57,59 +60,67 @@ Now, running `node example.js` yields:
5760
5861## API
5962
60- ### ` toMdast(node [, options]) `
63+ ### ` toMdast(tree [, options]) `
6164
62- Transform the given [ hast] [ ] tree to [ mdast] [ ] .
65+ Transform the given [ ** hast** ] [ hast ] [ * tree* ] [ tree ] to [ ** mdast** ] [ mdast ] .
6366
6467##### Options
6568
6669###### ` options.handlers `
6770
68- Object mapping tag-names to functions handling those elements.
69- Take a look at [ ` handlers/ ` ] [ handlers ] for examples.
71+ Object mapping tag names or [ * types* ] [ type ] to functions handling those
72+ [ * elements* ] [ element ] or [ * nodes* ] [ hast-node ] .
73+ See [ ` handlers/ ` ] [ handlers ] for examples.
7074
7175###### ` options.document `
7276
73- Whether the given tree is a complete document. If ` document: true ` ,
74- implicit paragraphs are added in the ` root ` node around inline mdast nodes.
75- Otherwise, inline mdast nodes are wrapped when needed.
77+ Whether the given [ * tree* ] [ tree ] is a complete document.
78+ Applies if the given ` tree ` is a [ ` root ` ] [ hast-root ] .
79+ First its [ * children* ] [ child ] are transformed to [ ** mast** ] [ mdast ] .
80+ By default, if one or more of the new mdast children are [ * phrasing* ] [ phrasing ]
81+ nodes, and one or more are not, the phrasing nodes are wrapped in
82+ [ * paragraphs* ] [ mdast-paragraph ] .
83+ If ` document: true ` , all mdast phrasing children are wrapped in paragraphs.
7684
7785###### ` options.newlines `
7886
79- Whether to collapse to a newline (` \n ` ) instead of a single space (default) if
87+ Whether to collapse to a line feed (` \n ` ) instead of a single space (default) if
8088a streak of white-space in a text node contains a newline.
8189
8290##### Returns
8391
84- [ ` MDASTNode ` ] [ mdast ] .
92+ [ ` MDASTNode ` ] [ mdast-node ] .
8593
8694##### Notes
8795
88- ###### Implied sentences
96+ ###### Implied paragraphs
8997
90- The algorithm supports implicit and explicit paragraphs, such as:
98+ The algorithm supports implicit and explicit paragraphs (see [ HTML Standard,
99+ A. van Kesteren; et al. WHATWG § 3.2.5.4 Paragraphs] [ spec ] ), such as:
91100
92101``` html
93102<article >
94- An implicit sentence .
95- <h1 >An explicit sentence .</h1 >
103+ An implicit paragraphs .
104+ <h1 >An explicit paragraphs .</h1 >
96105</article >
97106```
98107
99108Yields:
100109
101110``` markdown
102- An implicit sentence .
111+ An implicit paragraphs .
103112
104- # An explicit sentence .
113+ # An explicit paragraphs .
105114```
106115
107116###### Ignoring nodes
108117
109- Some nodes are ignored and their content will not be present in mdast.
110- To ignore custom elements, configure a handler for their tag-name or type that
111- returns nothing.
112- For example, to ignore ` em ` elements, pass ` handlers: {'em': function () {}} ` :
118+ Some [ * nodes* ] [ hast-node ] are ignored and their content will not be present in
119+ the [ ** mdast** ] [ mdast ] [ * tree* ] [ tree ] .
120+ To ignore nodes, configure a [ handler] [ ] for their tag name or [ * type* ] [ type ]
121+ that returns nothing.
122+ For example, to ignore ` em ` [ * elements* ] [ element ] , pass `handlers: {'em':
123+ function () {}}`:
113124
114125``` html
115126<p ><strong >Importance</strong > and <em >emphasis</em >.</p >
@@ -121,7 +132,8 @@ Yields:
121132**Importance** and .
122133```
123134
124- To ignore a specific element from HTML, set ` data-mdast ` to ` ignore ` :
135+ To ignore a specific element from the HTML source, set ` data-mdast ` to
136+ ` ignore ` :
125137
126138``` html
127139<p ><strong >Importance</strong > and <em data-mdast =" ignore" >emphasis</em >.</p >
@@ -148,11 +160,13 @@ Yields:
148160
149161## Contribute
150162
151- See [ ` contributing.md ` in ` syntax-tree/hast ` ] [ contributing ] for ways to get
163+ See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
152164started.
165+ See [ ` support.md ` ] [ support ] for ways to get help.
153166
154- This organisation has a [ Code of Conduct] [ coc ] . By interacting with this
155- repository, organisation, or community you agree to abide by its terms.
167+ This project has a [ Code of Conduct] [ coc ] .
168+ By interacting with this repository, organisation, or community you agree to
169+ abide by its terms.
156170
157171## License
158172
@@ -172,24 +186,58 @@ repository, organisation, or community you agree to abide by its terms.
172186
173187[ downloads ] : https://www.npmjs.com/package/hast-util-to-mdast
174188
189+ [ size-badge ] : https://img.shields.io/bundlephobia/minzip/hast-util-to-mdast.svg
190+
191+ [ size ] : https://bundlephobia.com/result?p=hast-util-to-mdast
192+
193+ [ sponsors-badge ] : https://opencollective.com/unified/sponsors/badge.svg
194+
195+ [ backers-badge ] : https://opencollective.com/unified/backers/badge.svg
196+
197+ [ collective ] : https://opencollective.com/unified
198+
175199[ chat-badge ] : https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg
176200
177- [ chat ] : https://spectrum.chat/unified/rehype
201+ [ chat ] : https://spectrum.chat/unified/syntax-tree
178202
179203[ npm ] : https://docs.npmjs.com/cli/install
180204
181205[ license ] : license
182206
183207[ author ] : https://wooorm.com
184208
209+ [ contributing ] : https://github.com/syntax-tree/.github/blob/master/contributing.md
210+
211+ [ support ] : https://github.com/syntax-tree/.github/blob/master/support.md
212+
213+ [ coc ] : https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md
214+
215+ [ tree ] : https://github.com/syntax-tree/unist#tree
216+
217+ [ child ] : https://github.com/syntax-tree/unist#child
218+
219+ [ type ] : https://github.com/syntax-tree/unist#type
220+
185221[ mdast ] : https://github.com/syntax-tree/mdast
186222
223+ [ mdast-paragraph ] : https://github.com/syntax-tree/mdast#paragraph
224+
225+ [ mdast-node ] : https://github.com/syntax-tree/mdast#nodes
226+
227+ [ phrasing ] : https://github.com/syntax-tree/mdast#phrasingcontent
228+
187229[ hast ] : https://github.com/syntax-tree/hast
188230
231+ [ hast-node ] : https://github.com/syntax-tree/hast#nodes
232+
233+ [ hast-root ] : https://github.com/syntax-tree/hast#root
234+
235+ [ element ] : https://github.com/syntax-tree/hast#element
236+
189237[ rehype-remark ] : https://github.com/rehypejs/rehype-remark
190238
191- [ handlers ] : https://github.com/syntax-tree/hast-util-to-mdast/tree/master/lib/handlers
239+ [ handler ] : #optionshandlers
192240
193- [ contributing ] : https://github.com/syntax-tree/hast/blob /master/contributing.md
241+ [ handlers ] : https://github.com/syntax-tree/hast-util-to-mdast/tree /master/lib/handlers
194242
195- [ coc ] : https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md
243+ [ spec ] : https://html.spec.whatwg.org/#paragraphs
0 commit comments