remark-lint-no-duplicate-headings
Advanced tools
Comparing version 3.1.0 to 3.1.1
export default remarkLintNoDuplicateHeadings | ||
export type Root = import('mdast').Root | ||
declare const remarkLintNoDuplicateHeadings: import('unified').Plugin< | ||
| void[] | ||
| [unknown] | ||
| void[] | ||
| [ | ||
( | ||
| boolean | ||
| import('unified-lint-rule').Label | ||
| import('unified-lint-rule').Severity | ||
| import('unified-lint-rule').Label | ||
), | ||
@@ -12,0 +12,0 @@ unknown |
26
index.js
/** | ||
* ## When should I use this? | ||
* | ||
* You can use this package to check that headings with the same text are | ||
* used once. | ||
* | ||
* ## API | ||
* | ||
* There are no options. | ||
* | ||
* ## Recommendation | ||
* | ||
* Headings having unique text helps screen reader users (who typically use | ||
* “jump to heading” features to navigate within a page, which reads headings | ||
* out loud). | ||
* It also helps because often headings receive automatic unique IDs, and when | ||
* the same heading text is used, they are suffixed with a number based on where | ||
* they are positioned in the document, which makes linking to them prone to | ||
* changes. | ||
* | ||
* @module no-duplicate-headings | ||
* @summary | ||
* remark-lint rule to warn when headings with the same text are found. | ||
* @author Titus Wormer | ||
* @copyright 2015 Titus Wormer | ||
* @license MIT | ||
* @module no-duplicate-headings | ||
* @fileoverview | ||
* Warn when duplicate headings are found. | ||
* | ||
* @example | ||
@@ -10,0 +28,0 @@ * {"name": "ok.md"} |
{ | ||
"name": "remark-lint-no-duplicate-headings", | ||
"version": "3.1.0", | ||
"version": "3.1.1", | ||
"description": "remark-lint rule to warn on duplicate headings", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
186
readme.md
@@ -13,4 +13,30 @@ <!--This file is generated--> | ||
Warn when duplicate headings are found. | ||
[`remark-lint`][mono] rule to warn when headings with the same text are found. | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Presets](#presets) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`unified().use(remarkLintNoDuplicateHeadings[, config])`](#unifieduseremarklintnoduplicateheadings-config) | ||
* [Recommendation](#recommendation) | ||
* [Examples](#examples) | ||
* [Compatibility](#compatibility) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package is a [unified][] ([remark][]) plugin, specifically a `remark-lint` | ||
rule. | ||
Lint rules check markdown code style. | ||
## When should I use this? | ||
You can use this package to check that headings with the same text are | ||
used once. | ||
## Presets | ||
@@ -24,55 +50,56 @@ | ||
## Example | ||
## Install | ||
##### `ok.md` | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
###### In | ||
```sh | ||
npm install remark-lint-no-duplicate-headings | ||
``` | ||
```markdown | ||
# Foo | ||
In Deno with [Skypack][]: | ||
## Bar | ||
```js | ||
import remarkLintNoDuplicateHeadings from 'https://cdn.skypack.dev/remark-lint-no-duplicate-headings@3?dts' | ||
``` | ||
###### Out | ||
In browsers with [Skypack][]: | ||
No messages. | ||
```html | ||
<script type="module"> | ||
import remarkLintNoDuplicateHeadings from 'https://cdn.skypack.dev/remark-lint-no-duplicate-headings@3?min' | ||
</script> | ||
``` | ||
##### `not-ok.md` | ||
## Use | ||
###### In | ||
On the API: | ||
```markdown | ||
# Foo | ||
```js | ||
import {read} from 'to-vfile' | ||
import {reporter} from 'vfile-reporter' | ||
import {remark} from 'remark' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintNoDuplicateHeadings from 'remark-lint-no-duplicate-headings' | ||
## Foo | ||
main() | ||
## [Foo](http://foo.com/bar) | ||
``` | ||
async function main() { | ||
const file = await remark() | ||
.use(remarkLint) | ||
.use(remarkLintNoDuplicateHeadings) | ||
.process(await read('example.md')) | ||
###### Out | ||
```text | ||
3:1-3:7: Do not use headings with similar content (1:1) | ||
5:1-5:29: Do not use headings with similar content (3:1) | ||
console.error(reporter(file)) | ||
} | ||
``` | ||
## Install | ||
On the CLI: | ||
This package is [ESM only][esm]: | ||
Node 12+ is needed to use it and it must be `imported`ed instead of `required`d. | ||
[npm][]: | ||
```sh | ||
npm install remark-lint-no-duplicate-headings | ||
remark --use remark-lint --use remark-lint-no-duplicate-headings example.md | ||
``` | ||
This package exports no identifiers. | ||
The default export is `remarkLintNoDuplicateHeadings`. | ||
On the CLI in a config file (here a `package.json`): | ||
## Use | ||
You probably want to use it on the CLI through a config file: | ||
```diff | ||
@@ -83,4 +110,4 @@ … | ||
… | ||
"lint", | ||
+ "lint-no-duplicate-headings", | ||
"remark-lint", | ||
+ "remark-lint-no-duplicate-headings", | ||
… | ||
@@ -92,25 +119,66 @@ ] | ||
Or use it on the CLI directly | ||
## API | ||
```sh | ||
remark -u lint -u lint-no-duplicate-headings readme.md | ||
This package exports no identifiers. | ||
The default export is `remarkLintNoDuplicateHeadings`. | ||
### `unified().use(remarkLintNoDuplicateHeadings[, config])` | ||
This rule supports standard configuration that all remark lint rules accept | ||
(such as `false` to turn it off or `[1, options]` to configure it). | ||
There are no options. | ||
## Recommendation | ||
Headings having unique text helps screen reader users (who typically use | ||
“jump to heading” features to navigate within a page, which reads headings | ||
out loud). | ||
It also helps because often headings receive automatic unique IDs, and when | ||
the same heading text is used, they are suffixed with a number based on where | ||
they are positioned in the document, which makes linking to them prone to | ||
changes. | ||
## Examples | ||
##### `ok.md` | ||
###### In | ||
```markdown | ||
# Foo | ||
## Bar | ||
``` | ||
Or use this on the API: | ||
###### Out | ||
```diff | ||
import {remark} from 'remark' | ||
import {reporter} from 'vfile-reporter' | ||
import remarkLint from 'remark-lint' | ||
import remarkLintNoDuplicateHeadings from 'remark-lint-no-duplicate-headings' | ||
No messages. | ||
remark() | ||
.use(remarkLint) | ||
+ .use(remarkLintNoDuplicateHeadings) | ||
.process('_Emphasis_ and **importance**') | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
}) | ||
##### `not-ok.md` | ||
###### In | ||
```markdown | ||
# Foo | ||
## Foo | ||
## [Foo](http://foo.com/bar) | ||
``` | ||
###### Out | ||
```text | ||
3:1-3:7: Do not use headings with similar content (1:1) | ||
5:1-5:29: Do not use headings with similar content (3:1) | ||
``` | ||
## Compatibility | ||
Projects maintained by the unified collective are compatible with all maintained | ||
versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
Our projects sometimes work with older versions, but this is not guaranteed. | ||
## Contribute | ||
@@ -156,4 +224,12 @@ | ||
[unified]: https://github.com/unifiedjs/unified | ||
[remark]: https://github.com/remarkjs/remark | ||
[mono]: https://github.com/remarkjs/remark-lint | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[skypack]: https://www.skypack.dev | ||
[npm]: https://docs.npmjs.com/cli/install | ||
@@ -163,7 +239,7 @@ | ||
[contributing]: https://github.com/remarkjs/.github/blob/HEAD/contributing.md | ||
[contributing]: https://github.com/remarkjs/.github/blob/main/contributing.md | ||
[support]: https://github.com/remarkjs/.github/blob/HEAD/support.md | ||
[support]: https://github.com/remarkjs/.github/blob/main/support.md | ||
[coc]: https://github.com/remarkjs/.github/blob/HEAD/code-of-conduct.md | ||
[coc]: https://github.com/remarkjs/.github/blob/main/code-of-conduct.md | ||
@@ -170,0 +246,0 @@ [license]: https://github.com/remarkjs/remark-lint/blob/main/license |
10036
98
243