Skip to content

Commit 014fca7

Browse files
authored
Add improved docs
Closes GH-276.
1 parent 96e8c4f commit 014fca7

File tree

153 files changed

+12585
-5981
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+12585
-5981
lines changed

.remarkrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import listOfRules from './script/plugin/list-of-rules.js'
1111
const plugins = [
1212
remarkPresetLintRecommended,
1313
remarkPresetLintConsistent,
14-
[remarkToc, {tight: true, maxDepth: 2, heading: 'contents'}],
14+
[remarkToc, {tight: true, maxDepth: 3, heading: 'contents'}],
1515
remarkCommentConfig,
1616
[remarkGfm, {tablePipeAlign: false}],
1717
remarkGithub,

doc/comparison-to-markdownlint.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# [markdownlint](https://github.com/mivok/markdownlint)
1+
# [markdownlint](https://github.com/markdownlint/markdownlint)
2+
3+
> ⚠️ **Important**: this comparison hasn’t been updated in years.
24
35
This table documents the similarity and difference between
4-
[**markdownlint**](https://github.com/mivok/markdownlint/blob/HEAD/docs/RULES.md)
6+
[**markdownlint**](https://github.com/markdownlint/markdownlint/blob/master/docs/RULES.md)
57
rules and **remark-lint**’s rules.
68

79
| markdownlint | remark | note |

doc/create-a-custom-rule.md

Lines changed: 65 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Create a custom `remark-lint` rule
22

3-
This guide is part of [a step-by-step tutorial](https://dev.to/floroz/how-to-create-a-custom-lint-rule-for-markdown-and-mdx-using-remark-and-eslint-2jim), and will help you getting started to create your first linting plugin for `remark`.
3+
This guide is part of [a step-by-step tutorial][tutorial], and will help you
4+
getting started to create your first linting plugin for `remark`.
45

56
## Contents
67

@@ -31,8 +32,10 @@ Now we can start installing our dependencies:
3132
npm install remark-lint remark-cli
3233
```
3334

34-
* [`remark-lint`](https://github.com/remarkjs/remark-lint): Core lint plugin
35-
* [`remark-cli`](https://github.com/remarkjs/remark/tree/main/packages/remark-cli): Command-line interface
35+
* [`remark-lint`][remark-lint]
36+
— core lint plugin
37+
* [`remark-cli`][remark-cli]
38+
— command line interface
3639

3740
We will also use some utilities:
3841

@@ -42,13 +45,12 @@ npm install unified-lint-rule unist-util-generated unist-util-visit
4245

4346
These will help us creating and managing our custom rules.
4447

45-
[Back to Top](#contents)
46-
4748
## Set up remark
4849

49-
With everything installed, we can now create a `.remarkrc.js` that will contain the plugins we’ll use.
50+
With everything installed, we can now create a `.remarkrc.js` that will contain
51+
the plugins we’ll use.
5052

51-
For more info on configuration, see [Configuring `remark-lint`](https://github.com/remarkjs/remark-lint#configuring-remark-lint).
53+
For more info on configuration, see [Examples in `remark-lint`][examples].
5254

5355
```sh
5456
touch .remarkrc.js
@@ -61,7 +63,8 @@ module.exports = {
6163
}
6264
```
6365

64-
Then, in our `package.json`, add the following script to process all the markdown files in our project:
66+
Then, in our `package.json`, add the following script to process all the
67+
markdown files in our project:
6568

6669
```json
6770
"scripts": {
@@ -87,34 +90,35 @@ Some funny images of our favorite pets
8790
![a lovely dog](lovely-dog.png)
8891
```
8992

90-
At this point, we have a working `remark` configuration and a markdown file in the project.
93+
At this point, we have a working `remark` configuration and a markdown file in
94+
the project.
9195

9296
If we run `npm run lint` we should expect to see in our terminal:
9397

9498
```sh
9599
doc.md: no issues found
96100
```
97101

98-
All good, the file has been processed, and because we haven’t specified any plugins nor lint rules, no issues are found.
99-
100-
[Back to Top](#contents)
102+
All good, the file has been processed, and because we haven’t specified any
103+
plugins nor lint rules, no issues are found.
101104

102105
## The `no-invalid-gif` rule
103106

104-
Let’s imagine we want to write a rule that checks whether a `.gif` file is used as an image.
105-
Given the content of our `doc.md` file declared above, we would expect an *error* or *warning* pointing to:
107+
Let’s imagine we want to write a rule that checks whether a `.gif` file is used
108+
as an image.
109+
Given the content of our `doc.md` file declared above, we would expect an
110+
*error* or *warning* pointing to:
106111

107112
```markdown
108113
![a funny cat](funny-cat.gif)
109114
```
110115

111116
Because the file extension `.gif` in the image violates our rule.
112117

113-
[Back to Top](#contents)
114-
115118
## Create the custom rule
116119

117-
Let’s create a new folder `rules` under the root directory, where we will place all of our custom rules, and create a new file in it named `no-gif-allowed.js`.
120+
Let’s create a new folder `rules` under the root directory, where we will place
121+
all of our custom rules, and create a new file in it named `no-gif-allowed.js`.
118122

119123
```sh
120124
mkdir rules
@@ -123,11 +127,14 @@ touch no-gif-allowed.js
123127
cd .. # return to project root
124128
```
125129

126-
*Note*: the name of folders and files, and where to place them within your project, is up to you.
130+
*Note*: the name of folders and files, and where to place them within your
131+
project, is up to you.
127132

128133
In `./rules/no-gif-allowed.js`, let’s import `unified-lint-rule`.
129134

130-
We then export the result of calling `rule` by providing the *namespace and rule name* (`remark-lint:no-gif-allowed`) as the first argument, and our implementation of the rule (`noGifAllowed`) as the second argument.
135+
We then export the result of calling `rule` by providing the *namespace and rule
136+
name* (`remark-lint:no-gif-allowed`) as the first argument, and our
137+
implementation of the rule (`noGifAllowed`) as the second argument.
131138

132139
```js
133140
// rules/no-gif-allowed.js
@@ -143,7 +150,8 @@ const remarkLintNoGifAllowed = lintRule(
143150
export default remarkLintNoGifAllowed
144151
```
145152

146-
Let’s say you want all your custom rules to be defined as part of your project namespace.
153+
Let’s say you want all your custom rules to be defined as part of your project
154+
namespace.
147155
If your project was named `my-project`, then you can export your rule as:
148156

149157
```js
@@ -152,9 +160,8 @@ const remarkLintNoGifAllowed = lintRule('my-project-name:no-gif-allowed', () =>
152160
const remarkLintNoGifAllowed = lintRule('my-npm-published-package:no-gif-allowed', () => {})
153161
```
154162

155-
This can help you when wanting to create a group of rules under the same *namespace*.
156-
157-
[Back to Top](#contents)
163+
This can help you when wanting to create a group of rules under the same
164+
*namespace*.
158165

159166
## Rule arguments
160167

@@ -164,17 +171,20 @@ Your rule function will receive three arguments:
164171
(tree, file, options) => {}
165172
```
166173

167-
* `tree` (*required*): [mdast](https://github.com/syntax-tree/mdast)
168-
* `file` (*required*): [virtual file](https://github.com/vfile/vfile)
169-
* `options` (*optional*): additional information passed to the rule by users
170-
171-
[Back to Top](#contents)
174+
* `tree` (*required*): [mdast][]
175+
* `file` (*required*): [virtual file][vfile]
176+
* `options` (*optional*): additional info passed to the rule by users
172177

173178
## Rule implementation
174179

175-
Because we will be inspecting [mdast](https://github.com/syntax-tree/mdast), which is a markdown abstract syntax tree built upon [unist](https://github.com/syntax-tree/unist), we can take advantage of the many existing [unist utilities](https://github.com/syntax-tree/unist#utilities) to inspect our tree’s nodes.
180+
Because we will be inspecting [mdast][], which is a markdown abstract syntax
181+
tree built upon [unist][], we can take advantage of the many existing
182+
[unist utilities][unist-util] to inspect our tree’s nodes.
176183

177-
For this example, we will use [`unist-util-visit`](https://github.com/syntax-tree/unist-util-visit) to recursively inspect all the image nodes, and [`unist-util-generated`](https://github.com/syntax-tree/unist-util-generated) to ensure we are not inspecting nodes that we have generated ourselves and do not belong to the `doc.md`.
184+
For this example, we will use [`unist-util-visit`][unist-util-visit] to
185+
recursively inspect all the image nodes, and
186+
[`unist-util-generated`][unist-util-generated] to ensure we are not inspecting
187+
nodes that we have generated ourselves and do not belong to the `doc.md`.
178188

179189
```js
180190
import {lintRule} from 'unified-lint-rule'
@@ -205,7 +215,7 @@ const remarkLintNoGifAllowed = lintRule(
205215
// Remember to provide the node as second argument to the message,
206216
// in order to obtain the position and column where the violation occurred.
207217
file.message(
208-
'Invalid image file extentions. Please do not use gifs',
218+
'Invalid image file extensions. Please do not use gifs',
209219
node
210220
)
211221
}
@@ -217,11 +227,10 @@ const remarkLintNoGifAllowed = lintRule(
217227
export default remarkLintNoGifAllowed
218228
```
219229

220-
[Back to Top](#contents)
221-
222230
## Import the rule in your remark config
223231

224-
Now that our custom rule is defined and ready to be used we need to add it to our `remark` configuration.
232+
Now that our custom rule is defined and ready to be used we need to add it to
233+
our `remark` configuration.
225234

226235
You can do that by importing your rule and adding it in `plugins` array:
227236

@@ -238,16 +247,33 @@ const preset = {plugins}
238247
export default preset
239248
```
240249

241-
[Back to Top](#contents)
242-
243250
## Apply the rule on the Markdown file
244251

245252
If you run `npm run lint`, you should see the following message in the terminal:
246253

247254
```text
248-
5:1-5:30 warning Invalid image file extentions. Please do not use gifs no-gif-allowed remark-lint
255+
5:1-5:30 warning Invalid image file extensions. Please do not use gifs no-gif-allowed remark-lint
249256
```
250257

251-
**Congratulations! The rule works!**
258+
**Congratulations!
259+
The rule works!**
260+
261+
[tutorial]: https://dev.to/floroz/how-to-create-a-custom-lint-rule-for-markdown-and-mdx-using-remark-and-eslint-2jim
262+
263+
[remark-lint]: https://github.com/remarkjs/remark-lint
264+
265+
[remark-cli]: https://github.com/remarkjs/remark/tree/main/packages/remark-cli
266+
267+
[examples]: https://github.com/remarkjs/remark-lint#examples
268+
269+
[mdast]: https://github.com/syntax-tree/mdast
270+
271+
[vfile]: https://github.com/vfile/vfile
272+
273+
[unist]: https://github.com/syntax-tree/unist
274+
275+
[unist-util]: https://github.com/syntax-tree/unist#utilities
276+
277+
[unist-util-visit]: https://github.com/syntax-tree/unist-util-visit
252278

253-
[Back to Top](#contents)
279+
[unist-util-generated]: https://github.com/syntax-tree/unist-util-generated

0 commit comments

Comments
 (0)