Search code examples
gitmarkdownmkdocs

markdownlint pre-commit incorrectly removing shortcut links


Context

Using mkdocs markdown syntax for creating an info box -- along with shortcut linking:

test.md

??? infobox "example"

    example shortcut link --> [Buuntu/fastapi-react]

[Buuntu/fastapi-react]: https://github.com/Buuntu/fastapi-react

By executing markdownlint via pre-commit (details below) the link will be removed, resulting in:

test.md

??? infobox "example"

    example shortcut link --> [Buuntu/fastapi-react]

I've tried modifying MD053 but it doesn't seem to have done anything... so I'm clearly missing something in the rule definitions

Question: Which rule is making this unwanted change?

Implementation

.markdownlint.jsonc

{
  "default": true,
  "MD003": { "style": "atx" },
  "MD007": { "indent": 4 },
  "MD013": {
    "line_length": 80,
    "heading_line_length": 80,
    "code_block_line_length": 80,
    "code_blocks": true,
    "tables": true,
    "headings": true,
    "headers": true,
    "strict": false,
    "stern": false
  },

  "no-hard-tabs": false,
  "whitespace": false,
  "MD053": {                // <-- added rule modification
    "ignored_definitions":
      ["full", "collapsed", "shortcut"]
  }
}

.pre-commit-config.yaml

- repo: https://github.com/igorshubovych/markdownlint-cli
  rev: v0.32.2
  hooks:
  - id: markdownlint
    args:
    - --fix
    verbose: true
    entry: bash -c 'markdownlint "$@" || true' --

Solution

  • In your original markdown, "example sortcut link..." is indented which makes it a code block. Links are not going to get picked up in code blocks so markdownlint considers it unused and deletes it.

    I don't want markdownlint deleting links I haven't gotten to using yet so I just turn that all the way off.

    In VSCode's settings.json:

        "markdownlint.config": {
            "link-image-reference-definitions": false,
        },
    

    In .markdownlint.yaml:

    MD053: false
    

    Or:

    link-image-reference-definitions: false