Skip to content

Commit bdba960

Browse files
committed
Refactor readme.md
1 parent 8370859 commit bdba960

File tree

2 files changed

+86
-99
lines changed

2 files changed

+86
-99
lines changed

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@
3333
"nyc": "^12.0.2",
3434
"prettier": "^1.14.2",
3535
"remark": "^9.0.0",
36+
"remark-cli": "^5.0.0",
37+
"remark-preset-wooorm": "^4.0.0",
3638
"tape": "^4.0.0",
3739
"xo": "^0.22.0"
3840
},
3941
"scripts": {
40-
"format": "prettier --write \"**/*.js\" && xo --fix",
42+
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
4143
"test-api": "node test",
4244
"test-coverage": "nyc --reporter lcov tape test/index.js",
4345
"test": "npm run format && npm run test-coverage"
@@ -59,5 +61,10 @@
5961
"xo": {
6062
"prettier": true,
6163
"esnext": false
64+
},
65+
"remarkConfig": {
66+
"plugins": [
67+
"preset-wooorm"
68+
]
6269
}
6370
}

readme.md

Lines changed: 78 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,101 @@
1-
[![npm](https://nodei.co/npm/mdast-normalize-headings.png)](https://npmjs.com/package/mdast-normalize-headings)
1+
# mdast-normalize-headings [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov]
22

3-
# mdast-normalize-headings
3+
Providing multiple top-level headings per single markdown document is confusing
4+
for tools that assume that there is only a single top-level heading that
5+
contains some meta-information (usually title) about the document.
46

5-
[![Build Status][travis-badge]][travis] [![Dependency Status][david-badge]][david]
7+
This [**mdast**][mdast] utility makes sure that there is only one top-level
8+
heading in the document by adjusting headings depths accordingly.
69

7-
Providing multiple top-level headings per single Markdown document is confusing for tools that assume that there is only a single top-level heading that contains some meta-information (usually title) about the document.
10+
Originally extracted from [`remark-man`][man].
811

9-
This [mdast][] transformer makes sure that there is only one top-level heading in the document by adjusting headings depths accordingly.
12+
## Installation
1013

11-
Originally extracted from [remark-man][].
14+
[npm][]:
1215

13-
[mdast]: https://github.com/syntax-tree/mdast
14-
[remark]: https://github.com/wooorm/remark
15-
[remark-man]: https://github.com/wooorm/remark-man
16-
[remark-normalize-headings]: https://github.com/eush77/remark-normalize-headings
16+
```bash
17+
npm install mdast-normalize-headings
18+
```
19+
20+
## Usage
21+
22+
```js
23+
var u = require('unist-builder')
24+
var normalizeHeadings = require('mdast-normalize-headings')
25+
26+
var tree = u('root', [
27+
u('heading', {depth: 1}, [u('text', 'title')]),
28+
u('heading', {depth: 2}, [u('text', 'description')]),
29+
u('heading', {depth: 1}, [u('text', 'example')])
30+
])
1731

18-
[travis]: https://travis-ci.org/eush77/mdast-normalize-headings
19-
[travis-badge]: https://travis-ci.org/eush77/mdast-normalize-headings.svg
20-
[david]: https://david-dm.org/eush77/mdast-normalize-headings
21-
[david-badge]: https://david-dm.org/eush77/mdast-normalize-headings.png
32+
console.log(tree)
2233

23-
## Example
34+
normalizeHeadings(tree)
35+
36+
console.log(tree)
37+
```
38+
39+
Yields:
2440

2541
```js
26-
var normalizeHeadings = require('mdast-normalize-headings');
27-
28-
ast
29-
//=> {
30-
// "type": "root",
31-
// "children": [
32-
// {
33-
// "type": "heading",
34-
// "depth": 1,
35-
// "children": [
36-
// {
37-
// "type": "text",
38-
// "value": "title"
39-
// }
40-
// ]
41-
// },
42-
// {
43-
// "type": "heading",
44-
// "depth": 2,
45-
// "children": [
46-
// {
47-
// "type": "text",
48-
// "value": "description"
49-
// }
50-
// ]
51-
// },
52-
// {
53-
// "type": "heading",
54-
// "depth": 1,
55-
// "children": [
56-
// {
57-
// "type": "text",
58-
// "value": "example"
59-
// }
60-
// ]
61-
// }
62-
// ]
63-
// }
64-
65-
normalizeHeadings(ast)
66-
//=> {
67-
// "type": "root",
68-
// "children": [
69-
// {
70-
// "type": "heading",
71-
// "depth": 1,
72-
// "children": [
73-
// {
74-
// "type": "text",
75-
// "value": "title"
76-
// }
77-
// ]
78-
// },
79-
// {
80-
// "type": "heading",
81-
// "depth": 3,
82-
// "children": [
83-
// {
84-
// "type": "text",
85-
// "value": "description"
86-
// }
87-
// ]
88-
// },
89-
// {
90-
// "type": "heading",
91-
// "depth": 2,
92-
// "children": [
93-
// {
94-
// "type": "text",
95-
// "value": "example"
96-
// }
97-
// ]
98-
// }
99-
// ]
100-
// }
42+
{ type: 'root',
43+
children:
44+
[ { type: 'heading', depth: 1, children: [Array] },
45+
{ type: 'heading', depth: 2, children: [Array] },
46+
{ type: 'heading', depth: 1, children: [Array] } ] }
47+
{ type: 'root',
48+
children:
49+
[ { type: 'heading', depth: 1, children: [Array] },
50+
{ type: 'heading', depth: 3, children: [Array] },
51+
{ type: 'heading', depth: 2, children: [Array] } ] }
10152
```
10253

10354
## API
10455

105-
#### `normalizeHeadings(ast)`
56+
### `normalizeHeadings(tree)`
10657

107-
Modifies AST in-place. Returns `ast`.
58+
Modifies tree in-place. Returns `tree`.
10859

10960
## Related
11061

111-
- [remark-normalize-headings][][remark][] plugin wrapper.
62+
* [`remark-normalize-headings`][normalize-headings]
63+
[**remark**][remark] plugin wrapper
11264

113-
## Install
65+
## Contribute
11466

115-
```
116-
npm install mdast-normalize-headings
117-
```
67+
See [`contributing.md` in `syntax-tree/unist`][contributing] for ways to get
68+
started.
69+
70+
This organisation has a [Code of Conduct][coc]. By interacting with this
71+
repository, organisation, or community you agree to abide by its terms.
11872

11973
## License
12074

121-
MIT
75+
[MIT][license] © Eugene Sharygin
76+
77+
<!-- Definitions -->
78+
79+
[travis-badge]: https://img.shields.io/travis/syntax-tree/mdast-normalize-headings.svg
80+
81+
[travis]: https://travis-ci.org/syntax-tree/mdast-normalize-headings
82+
83+
[codecov-badge]: https://img.shields.io/codecov/c/github/syntax-tree/mdast-normalize-headings.svg
84+
85+
[codecov]: https://codecov.io/github/syntax-tree/mdast-normalize-headings
86+
87+
[npm]: https://docs.npmjs.com/cli/install
88+
89+
[license]: license
90+
91+
[contributing]: https://github.com/syntax-tree/unist/blob/master/contributing.md
92+
93+
[coc]: https://github.com/syntax-tree/unist/blob/master/code-of-conduct.md
94+
95+
[mdast]: https://github.com/syntax-tree/mdast
96+
97+
[remark]: https://github.com/remarkjs/remark
98+
99+
[man]: https://github.com/remarkjs/remark-man
100+
101+
[normalize-headings]: https://github.com/remarkjs/remark-normalize-headings

0 commit comments

Comments
 (0)