8
8
[ ![ Backers] [ backers-badge ]] [ collective ]
9
9
[ ![ Chat] [ chat-badge ]] [ chat ]
10
10
11
- [ ** mdast** ] [ mdast ] utility to get the style of a heading.
11
+ [ mdast] [ ] utility to get the style of a heading.
12
12
13
- ## Install
13
+ ## Contents
14
+
15
+ * [ What is this?] ( #what-is-this )
16
+ * [ When should I use this?] ( #when-should-i-use-this )
17
+ * [ Install] ( #install )
18
+ * [ Use] ( #use )
19
+ * [ API] ( #api )
20
+ * [ ` headingStyle(node[, relative]) ` ] ( #headingstylenode-relative )
21
+ * [ Types] ( #types )
22
+ * [ Compatibility] ( #compatibility )
23
+ * [ Security] ( #security )
24
+ * [ Related] ( #related )
25
+ * [ Contribute] ( #contribute )
26
+ * [ License] ( #license )
27
+
28
+ ## What is this?
29
+
30
+ This package is a tiny utility to figure out if a heading was written as ATX or
31
+ as setext.
32
+
33
+ ``` markdown
34
+ ## ATX uses hashes
35
+
36
+ Setext uses an underline
37
+ ------------------------
38
+ ```
14
39
15
- This package is [ ESM only] ( https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c ) :
16
- Node 12+ is needed to use it and it must be ` import ` ed instead of ` require ` d.
40
+ ## When should I use this?
17
41
18
- [ npm] [ ] :
42
+ Probably not a lot!
43
+ It’s used in [ ` remark-lint ` ] [ remark-lint ] .
44
+
45
+ ## Install
46
+
47
+ This package is [ ESM only] [ esm ] .
48
+ In Node.js (version 12.20+, 14.14+, or 16.0+), install with [ npm] [ ] :
19
49
20
50
``` sh
21
51
npm install mdast-util-heading-style
22
52
```
23
53
54
+ In Deno with [ ` esm.sh ` ] [ esmsh ] :
55
+
56
+ ``` js
57
+ import {headingStyle } from ' https://esm.sh/mdast-util-heading-style@2'
58
+ ```
59
+
60
+ In browsers with [ ` esm.sh ` ] [ esmsh ] :
61
+
62
+ ``` html
63
+ <script type =" module" >
64
+ import {headingStyle } from ' https://esm.sh/mdast-util-heading-style@2?bundle'
65
+ </script >
66
+ ```
67
+
24
68
## Use
25
69
26
70
``` js
27
71
import {unified } from ' unified'
72
+ import {fromMarkdown } from ' mdast-util-from-markdown'
28
73
import {headingStyle } from ' mdast-util-heading-style'
29
- import remarkParse from ' remark-parse'
30
-
31
- const processor = unified ().use (remarkParse)
32
74
33
- headingStyle (processor . parse (' # ATX' ).children [0 ]) // => 'atx'
34
- headingStyle (processor . parse (' # ATX #\n ' ).children [0 ]) // => 'atx-closed'
35
- headingStyle (processor . parse (' ATX\n ===' ).children [0 ]) // => 'setext'
75
+ headingStyle (fromMarkdown (' # ATX' ).children [0 ]) // => 'atx'
76
+ headingStyle (fromMarkdown (' # ATX #\n ' ).children [0 ]) // => 'atx-closed'
77
+ headingStyle (fromMarkdown (' ATX\n ===' ).children [0 ]) // => 'setext'
36
78
37
- headingStyle (processor . parse (' ### ATX' ).children [0 ]) // => null
38
- headingStyle (processor . parse (' ### ATX' ).children [0 ], ' setext' ) // => 'setext'
79
+ headingStyle (fromMarkdown (' ### ATX' ).children [0 ]) // => null
80
+ headingStyle (fromMarkdown (' ### ATX' ).children [0 ], ' setext' ) // => 'setext'
39
81
```
40
82
41
83
## API
42
84
43
- This package exports the following identifiers: ` headingStyle ` .
85
+ This package exports the identifier ` headingStyle ` .
44
86
There is no default export.
45
87
46
88
### ` headingStyle(node[, relative]) `
47
89
48
- Get the heading style of a node.
90
+ Get the heading style of a node ([ ` Node ` ] [ node ] ), optionally ` relative ` to
91
+ a preferred style (` 'atx' ` , ` 'atx-closed' ` , ` 'setext' ` , optional).
92
+ This is because ATX headings with a depth of three or more could be considered
93
+ setext.
49
94
50
- ###### Parameters
95
+ ###### Returns
51
96
52
- * ` node ` ([ ` Node ` ] [ node ] ) — Node to parse
53
- * ` relative ` (` string ` , optional) — Style to use for ambiguous headings
54
- (atx-headings with a level of three or more could also be setext)
97
+ Style (` 'atx' ` , ` 'atx-closed' ` , or ` 'setext' ` ).
98
+ When an ambiguous heading is found, either ` relative ` or ` null ` is returned.
55
99
56
- ###### Returns
100
+ ## Types
101
+
102
+ This package is fully typed with [ TypeScript] [ ] .
103
+ It exports the type ` Style ` .
57
104
58
- ` string ` (` 'atx' ` , ` 'atx-closed' ` , or ` 'setext' ` ) — When an ambiguous
59
- heading is found, either ` relative ` or ` null ` is returned.
105
+ ## Compatibility
106
+
107
+ Projects maintained by the unified collective are compatible with all maintained
108
+ versions of Node.js.
109
+ As of now, that is Node.js 12.20+, 14.14+, and 16.0+.
110
+ Our projects sometimes work with older versions, but this is not guaranteed.
60
111
61
112
## Security
62
113
63
- Use of ` mdast-util-heading-style ` does not involve [ ** hast** ] [ hast ] so there are
114
+ Use of ` mdast-util-heading-style ` does not involve ** [ hast] [ ] ** so there are
64
115
no openings for [ cross-site scripting (XSS)] [ xss ] attacks.
65
116
66
117
## Related
@@ -72,8 +123,8 @@ no openings for [cross-site scripting (XSS)][xss] attacks.
72
123
73
124
## Contribute
74
125
75
- See [ ` contributing.md ` in ` syntax-tree/.github ` ] [ contributing ] for ways to get
76
- started.
126
+ See [ ` contributing.md ` ] [ contributing ] in [ ` syntax-tree/.github ` ] [ health ] for
127
+ ways to get started.
77
128
See [ ` support.md ` ] [ support ] for ways to get help.
78
129
79
130
This project has a [ code of conduct] [ coc ] .
@@ -118,11 +169,19 @@ abide by its terms.
118
169
119
170
[ npm ] : https://docs.npmjs.com/cli/install
120
171
121
- [ contributing ] : https://github.com/syntax-tree/.github/blob/HEAD/contributing.md
172
+ [ esm ] : https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
173
+
174
+ [ esmsh ] : https://esm.sh
175
+
176
+ [ typescript ] : https://www.typescriptlang.org
122
177
123
- [ support ] : https://github.com/syntax-tree/.github/blob/HEAD/support.md
178
+ [ health ] : https://github.com/syntax-tree/.github
124
179
125
- [ coc ] : https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md
180
+ [ contributing ] : https://github.com/syntax-tree/.github/blob/main/contributing.md
181
+
182
+ [ support ] : https://github.com/syntax-tree/.github/blob/main/support.md
183
+
184
+ [ coc ] : https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
126
185
127
186
[ mdast ] : https://github.com/syntax-tree/mdast
128
187
@@ -131,3 +190,5 @@ abide by its terms.
131
190
[ xss ] : https://en.wikipedia.org/wiki/Cross-site_scripting
132
191
133
192
[ hast ] : https://github.com/syntax-tree/hast
193
+
194
+ [ remark-lint ] : https://github.com/remarkjs/remark-lint
0 commit comments