Skip to content

Commit 3210a96

Browse files
committed
Allow disabling table padding
Because on big tables it creates noise. Setting "paddedTable" to "false" in package.json does 3 things: 1. Disable padding by `remark-stringify` 2. Use fixed width columns: `| --- | --- |` 3. Disable `remark-lint-table-cell-padding` Linting is disabled because `remark-lint-table-cell-padding` has no option (yet) for this particular style. See: remarkjs/remark-lint#217 Prior discussion: #16
1 parent 93d12f9 commit 3210a96

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

cli.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@ if (argv.help) {
3232
const cwd = process.cwd()
3333
const glob = argv._.length ? argv._ : ['*.md']
3434
const pkg = getNearestPackage(cwd) || {}
35-
const packageOpts = pkg.hallmark || {}
35+
const packageOpts = Object.assign({}, pkg.hallmark)
3636
const repo = pkg.repository ? pkg.repository.url || pkg.repository : ''
3737
const ignore = [].concat(packageOpts.ignore || []).concat(argv.ignore || [])
3838

39+
packageOpts.validateLinks = packageOpts.validateLinks !== false
40+
packageOpts.paddedTable = packageOpts.paddedTable !== false
41+
3942
deglob(glob, { usePackageJson: false, cwd, ignore }, function (err, files) {
4043
if (err) throw err
4144
if (files.length === 0) process.exit()

lint.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = function (fix, cwd, validateLinks, repository) {
1+
module.exports = function (fix, cwd, packageOpts, repository) {
22
const preset = {
33
plugins: [
44
require('remark-lint'),
@@ -30,7 +30,10 @@ module.exports = function (fix, cwd, validateLinks, repository) {
3030
require('remark-lint-no-heading-content-indent'),
3131
require('remark-lint-hard-break-spaces'),
3232
[require('remark-lint-code-block-style'), 'fenced'],
33-
[require('remark-lint-table-cell-padding'), 'padded'],
33+
34+
// TODO: support fixed-width columns (https://github.com/remarkjs/remark-lint/issues/217)
35+
packageOpts.paddedTable ? [require('remark-lint-table-cell-padding'), 'padded'] : null,
36+
3437
require('remark-lint-table-pipes'),
3538
[require('remark-lint-checkbox-character-style'), {
3639
checked: 'x', unchecked: ' '
@@ -42,13 +45,14 @@ module.exports = function (fix, cwd, validateLinks, repository) {
4245
// Temporarily allow skipping link validation, because remark does not parse
4346
// HTML anchors - as used in various Level readme's. Those readme's should be
4447
// updated to use markdown only.
45-
if (validateLinks) {
48+
if (packageOpts.validateLinks) {
4649
preset.plugins.push([require('remark-validate-links'), {
4750
// If we don't pass this, remark-validate-links tries to get the repo url
4851
// from `git remote -v` which is not desirable for forks.
4952
repository: repository || false
5053
}])
5154
}
5255

56+
preset.plugins = preset.plugins.filter(Boolean)
5357
return preset
5458
}

options.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,18 @@ module.exports = function (argv, packageOpts, files, cwd, repository) {
4242
test: /^table of contents$/i,
4343
summary: 'Click to expand'
4444
}],
45-
require('./lint')(fix, cwd, packageOpts.validateLinks !== false, repository)
45+
require('./lint')(fix, cwd, packageOpts, repository)
4646
].filter(Boolean),
4747
settings: {
4848
// One style for code blocks, whether they have a language or not.
4949
fences: true,
50-
listItemIndent: '1'
50+
listItemIndent: '1',
51+
52+
// Allow disabling padding because on big tables it creates noise.
53+
paddedTable: packageOpts.paddedTable,
54+
55+
// In addition, use fixed width columns.
56+
stringLength: packageOpts.paddedTable ? (s) => String(s).length : () => 3
5157
},
5258
pluginPrefix: 'remark',
5359
// "Whether to write successfully processed files"

0 commit comments

Comments
 (0)