Skip to content

Commit

Permalink
Allow disabling table padding
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vweevers committed Aug 31, 2019
1 parent 93d12f9 commit 3210a96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion cli.js
Expand Up @@ -32,10 +32,13 @@ if (argv.help) {
const cwd = process.cwd()
const glob = argv._.length ? argv._ : ['*.md']
const pkg = getNearestPackage(cwd) || {}
const packageOpts = pkg.hallmark || {}
const packageOpts = Object.assign({}, pkg.hallmark)
const repo = pkg.repository ? pkg.repository.url || pkg.repository : ''
const ignore = [].concat(packageOpts.ignore || []).concat(argv.ignore || [])

packageOpts.validateLinks = packageOpts.validateLinks !== false
packageOpts.paddedTable = packageOpts.paddedTable !== false

deglob(glob, { usePackageJson: false, cwd, ignore }, function (err, files) {
if (err) throw err
if (files.length === 0) process.exit()
Expand Down
10 changes: 7 additions & 3 deletions lint.js
@@ -1,4 +1,4 @@
module.exports = function (fix, cwd, validateLinks, repository) {
module.exports = function (fix, cwd, packageOpts, repository) {
const preset = {
plugins: [
require('remark-lint'),
Expand Down Expand Up @@ -30,7 +30,10 @@ module.exports = function (fix, cwd, validateLinks, repository) {
require('remark-lint-no-heading-content-indent'),
require('remark-lint-hard-break-spaces'),
[require('remark-lint-code-block-style'), 'fenced'],
[require('remark-lint-table-cell-padding'), 'padded'],

// TODO: support fixed-width columns (https://github.com/remarkjs/remark-lint/issues/217)
packageOpts.paddedTable ? [require('remark-lint-table-cell-padding'), 'padded'] : null,

require('remark-lint-table-pipes'),
[require('remark-lint-checkbox-character-style'), {
checked: 'x', unchecked: ' '
Expand All @@ -42,13 +45,14 @@ module.exports = function (fix, cwd, validateLinks, repository) {
// Temporarily allow skipping link validation, because remark does not parse
// HTML anchors - as used in various Level readme's. Those readme's should be
// updated to use markdown only.
if (validateLinks) {
if (packageOpts.validateLinks) {
preset.plugins.push([require('remark-validate-links'), {
// If we don't pass this, remark-validate-links tries to get the repo url
// from `git remote -v` which is not desirable for forks.
repository: repository || false
}])
}

preset.plugins = preset.plugins.filter(Boolean)
return preset
}
10 changes: 8 additions & 2 deletions options.js
Expand Up @@ -42,12 +42,18 @@ module.exports = function (argv, packageOpts, files, cwd, repository) {
test: /^table of contents$/i,
summary: 'Click to expand'
}],
require('./lint')(fix, cwd, packageOpts.validateLinks !== false, repository)
require('./lint')(fix, cwd, packageOpts, repository)
].filter(Boolean),
settings: {
// One style for code blocks, whether they have a language or not.
fences: true,
listItemIndent: '1'
listItemIndent: '1',

// Allow disabling padding because on big tables it creates noise.
paddedTable: packageOpts.paddedTable,

// In addition, use fixed width columns.
stringLength: packageOpts.paddedTable ? (s) => String(s).length : () => 3
},
pluginPrefix: 'remark',
// "Whether to write successfully processed files"
Expand Down

0 comments on commit 3210a96

Please sign in to comment.