remark-lint-fenced-code-marker
remark-lint
rule to warn when fenced code markers are inconsistent.
Contents
- What is this?
- When should I use this?
- Presets
- Install
- Use
- API
- Recommendation
- Fix
- Examples
- Compatibility
- Contribute
- 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 fenced code markers are consistent.
Presets
This rule is included in the following presets:
Preset | Setting |
---|---|
remark-preset-lint-consistent | 'consistent' |
remark-preset-lint-markdown-style-guide | '`' |
Install
This package is ESM only. In Node.js (version 12.20+, 14.14+, or 16.0+), install with npm:
npm install remark-lint-fenced-code-marker
In Deno with esm.sh
:
import remarkLintFencedCodeMarker from 'https://esm.sh/remark-lint-fenced-code-marker@3'
In browsers with esm.sh
:
<script type="module">
import remarkLintFencedCodeMarker from 'https://esm.sh/remark-lint-fenced-code-marker@3?bundle'
</script>
Use
On the API:
import {read} from 'to-vfile'
import {reporter} from 'vfile-reporter'
import {remark} from 'remark'
import remarkLint from 'remark-lint'
import remarkLintFencedCodeMarker from 'remark-lint-fenced-code-marker'
main()
async function main() {
const file = await remark()
.use(remarkLint)
.use(remarkLintFencedCodeMarker)
.process(await read('example.md'))
console.error(reporter(file))
}
On the CLI:
remark --use remark-lint --use remark-lint-fenced-code-marker example.md
On the CLI in a config file (here a package.json
):
…
"remarkConfig": {
"plugins": [
…
"remark-lint",
+ "remark-lint-fenced-code-marker",
…
]
}
…
API
This package exports no identifiers. The default export is remarkLintFencedCodeMarker
.
unified().use(remarkLintFencedCodeMarker[, 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).
The following options (default: 'consistent'
) are accepted:
'`'
— prefer grave accents'~'
— prefer tildes'consistent'
— detect the first used style and warn when further fenced code differs
Recommendation
Tildes are extremely uncommon. Due to this, it’s recommended to configure this rule with '`'
.
Fix
remark-stringify
formats fenced code with grave accents by default. Pass fence: '~'
to always use tildes.
Examples
ok.md
In
Indented code blocks are not affected by this rule:
bravo()
Out
No messages.
not-ok-consistent-tick.md
In
```alpha
bravo()
```
~~~
charlie()
~~~
Out
5:1-7:4: Fenced code should use `` ` `` as a marker
not-ok-consistent-tilde.md
In
~~~alpha
bravo()
~~~
```
charlie()
```
Out
5:1-7:4: Fenced code should use `~` as a marker
ok.md
When configured with '`'
.
In
```alpha
bravo()
```
```
charlie()
```
Out
No messages.
ok.md
When configured with '~'
.
In
~~~alpha
bravo()
~~~
~~~
charlie()
~~~
Out
No messages.
not-ok-incorrect.md
When configured with '💩'
.
Out
1:1: Incorrect fenced code marker `💩`: use either `'consistent'`, `` '`' ``, or `'~'`
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
See contributing.md
in remarkjs/.github
for ways to get started. See support.md
for ways to get help.
This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.