Skip to content

Commit e2fcf4e

Browse files
committed
Add improved docs
1 parent 237bdcf commit e2fcf4e

File tree

1 file changed

+89
-28
lines changed

1 file changed

+89
-28
lines changed

readme.md

Lines changed: 89 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,59 +8,110 @@
88
[![Backers][backers-badge]][collective]
99
[![Chat][chat-badge]][chat]
1010

11-
[**mdast**][mdast] utility to get the style of a heading.
11+
[mdast][] utility to get the style of a heading.
1212

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+
```
1439

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?
1741

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][]:
1949

2050
```sh
2151
npm install mdast-util-heading-style
2252
```
2353

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+
2468
## Use
2569

2670
```js
2771
import {unified} from 'unified'
72+
import {fromMarkdown} from 'mdast-util-from-markdown'
2873
import {headingStyle} from 'mdast-util-heading-style'
29-
import remarkParse from 'remark-parse'
30-
31-
const processor = unified().use(remarkParse)
3274

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'
3678

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'
3981
```
4082

4183
## API
4284

43-
This package exports the following identifiers: `headingStyle`.
85+
This package exports the identifier `headingStyle`.
4486
There is no default export.
4587

4688
### `headingStyle(node[, relative])`
4789

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.
4994

50-
###### Parameters
95+
###### Returns
5196

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.
5599

56-
###### Returns
100+
## Types
101+
102+
This package is fully typed with [TypeScript][].
103+
It exports the type `Style`.
57104

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.
60111

61112
## Security
62113

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
64115
no openings for [cross-site scripting (XSS)][xss] attacks.
65116

66117
## Related
@@ -72,8 +123,8 @@ no openings for [cross-site scripting (XSS)][xss] attacks.
72123

73124
## Contribute
74125

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.
77128
See [`support.md`][support] for ways to get help.
78129

79130
This project has a [code of conduct][coc].
@@ -118,11 +169,19 @@ abide by its terms.
118169

119170
[npm]: https://docs.npmjs.com/cli/install
120171

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
122177

123-
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md
178+
[health]: https://github.com/syntax-tree/.github
124179

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
126185

127186
[mdast]: https://github.com/syntax-tree/mdast
128187

@@ -131,3 +190,5 @@ abide by its terms.
131190
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
132191

133192
[hast]: https://github.com/syntax-tree/hast
193+
194+
[remark-lint]: https://github.com/remarkjs/remark-lint

0 commit comments

Comments
 (0)