1

Context

After applying a line length limit of 80 characters on the pre-commit check of markdown-lint, I was experiencing some difficulties in including a markdown table that I create with more width than 80 characters.

Note

I see value in applying the linter to the README.md because I quite often forget about the line length while typing the README.md. (In essence, the trivial solution: disable the linter or disable MD013 everywhere, is considered sub-optimal).

Pre-commit of MarkdownLint

- repo: https://github.com/markdownlint/markdownlint
   rev: v0.11.0
   hooks:
     - id: markdownlint

Markdown table example

| Algorithm                            | Encoding | Adaptation | Radiation    | Backend                      |
| ------------------------------------ | -------- | ---------- | ------------ | ---------------------------- |
| Minimum Dominating Set Approximation | Sparse   | Redundancy | Neuron Death | - networkx LIF<br>- Lava LIF |
| Some Algorithm Approximation         | Sparse   | Redundancy | Neuron Death | - networkx LIF<br>- Lava LIF |
|                                      |          |            |              |                              |

Approach I

First I tried to include a ignore MD013 (line length check) in the relevant section of the Markdown table, however, Markdown Lint does not support such an option.

Approach II

I tried to manually apply the new line breaks to the table, however, that results in additional rows in the table: enter image description here

Question

How can I stay within the 80 lines whilst including a wide markdown table, (without generating new horizontal lines)?

a.t.
  • 2,002
  • 3
  • 26
  • 66

2 Answers2

2

You could try changing your hook to another similar project: igorshubovych/markdownlint-cli

repos:
  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.32.2
    hooks:
      - id: markdownlint
        args: ["--fix"]

You may include a .markdownlint.yaml file in the same directory as your .pre-commit-config.yaml. Set the line length rule but ignore it for tables. Like so:

# Default state for all rules
default: true

# MD013/line-length - Line length
MD013:
  line_length: 80
  tables: false

Check the .markdownlint.yaml schema for other configuration options.

Gabriel M. Silva
  • 642
  • 4
  • 10
  • Awesome, thank you! Your suggestions resolved the issue after copying your files and running `pre-commit install`. – a.t. Nov 30 '22 at 14:37
1

I want to mention that something similar to @Gabriel's answer should work for you if (like me) you don't have a pre-commit-config.yaml file.

just make a .markdownlint.json file at the root of your project, with the following content:

{
  "MD013": {
      "line_length": 80,
      "code_block_line_length": 120,
      "tables": false
    }
  
}

You could now set your line length to be whatever you prefer; alternatively, you could set the line checking to be false for tables.

desertnaut
  • 57,590
  • 26
  • 140
  • 166