.. | ||
.npmrc | ||
index.js | ||
package.json | ||
readme.md | ||
tsconfig.json |
remark-lint-table-cell-padding
remark-lint
rule to warn when GFM table cells are padded inconsistently.
Contents
- What is this?
- When should I use this?
- Presets
- Install
- Use
- API
- Recommendation
- Fix
- Examples
- Compatibility
- Contribute
- License
What is this?
This package checks table cell padding.
Tables are a GFM feature enabled with remark-gfm
.
When should I use this?
You can use this package to check that tables are consistent.
Presets
This plugin is included in the following presets:
Preset | Options |
---|---|
remark-preset-lint-consistent |
'consistent' |
remark-preset-lint-markdown-style-guide |
'padded' |
Install
This package is ESM only. In Node.js (version 16+), install with npm:
npm install remark-lint-table-cell-padding
In Deno with esm.sh
:
import remarkLintTableCellPadding from 'https://esm.sh/remark-lint-table-cell-padding@4'
In browsers with esm.sh
:
<script type="module">
import remarkLintTableCellPadding from 'https://esm.sh/remark-lint-table-cell-padding@4?bundle'
</script>
Use
On the API:
import remarkLint from 'remark-lint'
import remarkLintTableCellPadding from 'remark-lint-table-cell-padding'
import remarkParse from 'remark-parse'
import remarkStringify from 'remark-stringify'
import {read} from 'to-vfile'
import {unified} from 'unified'
import {reporter} from 'vfile-reporter'
const file = await read('example.md')
await unified()
.use(remarkParse)
.use(remarkLint)
.use(remarkLintTableCellPadding)
.use(remarkStringify)
.process(file)
console.error(reporter(file))
On the CLI:
remark --frail --use remark-lint --use remark-lint-table-cell-padding .
On the CLI in a config file (here a package.json
):
…
"remarkConfig": {
"plugins": [
…
"remark-lint",
+ "remark-lint-table-cell-padding",
…
]
}
…
API
This package exports no identifiers.
It exports the TypeScript types
Options
and
Style
.
The default export is
remarkLintTableCellPadding
.
unified().use(remarkLintTableCellPadding[, options])
Warn when GFM table cells are padded inconsistently.
Parameters
options
(Options
, optional) — preferred style or whether to detect the first style and warn for further differences
Returns
Transform (Transformer
from unified
).
Style
Style (TypeScript type).
'compact'
— prefer zero spaces between pipes and content'padded'
— prefer at least one space between pipes and content
Type
type Style = 'compact' | 'padded'
Options
Configuration (TypeScript type).
Type
type Options = Style | 'consistent'
Recommendation
It’s recommended to use at least one space between pipes and content for
legibility of the markup ('padded'
).
Fix
remark-stringify
with
remark-gfm
formats all table cells as padded by
default.
Pass tableCellPadding: false
to use a more compact style.
Examples
ok.md
When configured with 'padded'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
| A | B |
| ----- | ----- |
| Alpha | Bravo |
Out
No messages.
not-ok.md
When configured with 'padded'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
| A | B |
| :----|----: |
| Alpha|Bravo |
| C | D |
| :----- | ---: |
|Charlie | Delta|
Too much padding isn’t good either:
| E | F | G | H |
| :---- | -------- | :----: | -----: |
| Echo | Foxtrot | Golf | Hotel |
Out
3:8: Cell should be padded
3:9: Cell should be padded
7:2: Cell should be padded
7:17: Cell should be padded
13:7: Cell should be padded with 1 space, not 2
13:18: Cell should be padded with 1 space, not 2
13:23: Cell should be padded with 1 space, not 2
13:27: Cell should be padded with 1 space, not 2
13:32: Cell should be padded with 1 space, not 2
ok.md
When configured with 'compact'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
|A |B |
|-----|-----|
|Alpha|Bravo|
Out
No messages.
not-ok.md
When configured with 'compact'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
| A | B |
| -----| -----|
| Alpha| Bravo|
|C | D|
|:------|-----:|
|Charlie|Delta |
Out
3:5: Cell should be compact
3:12: Cell should be compact
7:15: Cell should be compact
ok-padded.md
In
👉 Note: this example uses GFM (
remark-gfm
).
The default is `'consistent'`.
| A | B |
| ----- | ----- |
| Alpha | Bravo |
| C | D |
| ------- | ----- |
| Charlie | Delta |
Out
No messages.
not-ok-padded.md
When configured with 'consistent'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
| A | B |
| ----- | ----- |
| Alpha | Bravo |
| C | D |
| :----- | ----: |
|Charlie | Delta |
Out
7:2: Cell should be padded
ok-compact.md
When configured with 'consistent'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
|A |B |
|-----|-----|
|Alpha|Bravo|
|C |D |
|-------|-----|
|Charlie|Delta|
Out
No messages.
not-ok-compact.md
When configured with 'consistent'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
|A |B |
|-----|-----|
|Alpha|Bravo|
|C | D|
|:------|-----:|
|Charlie|Delta |
Out
7:15: Cell should be compact
not-ok.md
When configured with '💩'
.
Out
1:1: Incorrect table cell padding style `💩`, expected `'padded'`, `'compact'`, or `'consistent'`
empty.md
When configured with 'padded'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
<!-- Empty cells are OK, but those surrounding them may not be. -->
| | Alpha | Bravo|
| ------ | ----- | ---: |
| Charlie| | Echo|
Out
3:25: Cell should be padded
5:10: Cell should be padded
5:25: Cell should be padded
missing-body.md
When configured with 'padded'
.
In
👉 Note: this example uses GFM (
remark-gfm
).
<!-- Missing cells are fine as well. -->
| Alpha | Bravo | Charlie |
| ----- | ------- | ------- |
| Delta |
| Echo | Foxtrot |
Out
No messages.
Compatibility
Projects maintained by the unified collective are compatible with maintained versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line,
remark-lint-table-cell-padding@4
,
compatible with Node.js 12.
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.