[GH-ISSUE #996] MD026: Invalid range when YAML front matter ending with punctuation is wrapped in HTML comment tags #585

Closed
opened 2026-03-03 01:28:13 +03:00 by kerem · 6 comments
Owner

Originally created by @skyzyx on GitHub (Oct 6, 2023).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/996

I've been using this tool for a few years. Thank you!

I recently started seeing error messages causing markdownlint-cli to die. I know that this is occurring when using the CLI, but looking at the paths that are triggering the error, it seems to be coming from the underlying markdownlint.js library. Hence, opening the issue here.

This works: (markdownlint@v0.30.0)

  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.36.0
    hooks:
      - id: markdownlint
        args:
          - --ignore=node_modules
          - --ignore=.github
          - --ignore=.templates
          - --fix
          - '**/*.md'

This crashes: (markdownlint@v0.31.1)

  - repo: https://github.com/igorshubovych/markdownlint-cli
    rev: v0.37.0
    hooks:
      - id: markdownlint
        args:
          - --ignore=node_modules
          - --ignore=.github
          - --ignore=.templates
          - --fix
          - '**/*.md'

Error message is as follows, and repeats multiple times (I think once per Markdown document).

Error: Property 'range' of onError parameter is incorrect.
    at throwError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:606:13)
    at onError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:642:9)
    at addError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/helpers/helpers.js:581:3)
    at Object.MD026 [as function] (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/md026.js:36:9)
    at invokeRuleFunction (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:703:51)
    at forRule (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:714:7)
    at Array.map (<anonymous>)
    at lintContent (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:781:44)
    at lintContentWrapper (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:834:12)
    at lintFile (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:851:5)

I haven't meaningfully updated my .markdownlint.json file in about ~2 years.

{
  "heading-increment": false,
  "first-header-h1": true,
  "header-style": {
    "style": "atx"
  },
  "ul-style": {
    "style": "asterisk"
  },
  "list-indent": true,
  "ul-start-left": true,
  "ul-indent": {
    "indent": 4
  },
  "no-trailing-spaces": {
    "br_spaces": 2,
    "list_item_empty_lines": false
  },
  "single-trailing-newline": true,
  "no-hard-tabs": {
    "code_blocks": false
  },
  "no-reversed-links": true,
  "no-multiple-blanks": {
    "maximum": 1
  },
  "line-length": {
    "line_length": 10000,
    "code_blocks": false,
    "tables": false
  },
  "commands-show-output": false,
  "no-missing-space-atx": true,
  "no-multiple-space-atx": true,
  "blanks-around-headers": {
    "lines_above": 1,
    "lines_below": 1
  },
  "header-start-left": true,
  "no-duplicate-header": {
    "allow_different_nesting": true
  },
  "single-h1": {
    "level": 1
  },
  "no-trailing-punctuation": {
    "punctuation": ".,;:"
  },
  "no-multiple-space-blockquote": true,
  "no-blanks-blockquote": true,
  "ol-prefix": {
    "style": "one"
  },
  "list-marker-space": {
    "ul_single": 1,
    "ol_single": 1,
    "ul_multi": 1,
    "ol_multi": 1
  },
  "blanks-around-fences": {
    "list_items": true
  },
  "blanks-around-lists": true,
  "no-inline-html": {
    "allowed_elements": [
      "a",
      "b",
      "br",
      "code",
      "details",
      "div",
      "img",
      "li",
      "nobr",
      "p",
      "pre",
      "summary",
      "ul"
    ]
  },
  "no-bare-urls": true,
  "hr-style": {
    "style": "consistent"
  },
  "no-emphasis-as-header": true,
  "no-space-in-emphasis": false,
  "no-space-in-code": false,
  "no-space-in-links": true,
  "fenced-code-language": true,
  "code-block-style": {
    "style": "fenced"
  },
  "first-line-h1": false,
  "no-empty-links": true,
  "proper-names": {
    "names": [],
    "code_blocks": false
  }
}

It appears to be triggering from here: https://github.com/DavidAnson/markdownlint/blob/v0.31.1/lib/markdownlint.js#L606

Looking at the diff between the two releases, the only thing I see that looks like it might be related is this line:

https://github.com/DavidAnson/markdownlint/compare/v0.30.0..v0.31.1#diff-807e51fda288b4ebd0ccd4229d72a4c025f9b9316b0244ac45e76d8ff2317269L1025

Originally created by @skyzyx on GitHub (Oct 6, 2023). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/996 I've been using this tool for a few years. Thank you! I recently started seeing error messages causing markdownlint-cli to die. I know that this is occurring when using the CLI, but looking at the paths that are triggering the error, it seems to be coming from the underlying `markdownlint.js` library. Hence, opening the issue here. This works: ([markdownlint@v0.30.0](https://github.com/igorshubovych/markdownlint-cli/blob/v0.36.0/package-lock.json#L4624)) ```yml - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.36.0 hooks: - id: markdownlint args: - --ignore=node_modules - --ignore=.github - --ignore=.templates - --fix - '**/*.md' ``` This crashes: ([markdownlint@v0.31.1](https://github.com/igorshubovych/markdownlint-cli/blob/v0.37.0/package-lock.json#L4624)) ```yml - repo: https://github.com/igorshubovych/markdownlint-cli rev: v0.37.0 hooks: - id: markdownlint args: - --ignore=node_modules - --ignore=.github - --ignore=.templates - --fix - '**/*.md' ``` Error message is as follows, and repeats multiple times (I think once per Markdown document). ```text Error: Property 'range' of onError parameter is incorrect. at throwError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:606:13) at onError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:642:9) at addError (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/helpers/helpers.js:581:3) at Object.MD026 [as function] (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/md026.js:36:9) at invokeRuleFunction (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:703:51) at forRule (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:714:7) at Array.map (<anonymous>) at lintContent (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:781:44) at lintContentWrapper (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:834:12) at lintFile (~/.cache/pre-commit/repotk9skkxt/node_env-system/lib/node_modules/markdownlint-cli/node_modules/markdownlint/lib/markdownlint.js:851:5) ``` I haven't meaningfully updated my `.markdownlint.json` file in about ~2 years. ```json { "heading-increment": false, "first-header-h1": true, "header-style": { "style": "atx" }, "ul-style": { "style": "asterisk" }, "list-indent": true, "ul-start-left": true, "ul-indent": { "indent": 4 }, "no-trailing-spaces": { "br_spaces": 2, "list_item_empty_lines": false }, "single-trailing-newline": true, "no-hard-tabs": { "code_blocks": false }, "no-reversed-links": true, "no-multiple-blanks": { "maximum": 1 }, "line-length": { "line_length": 10000, "code_blocks": false, "tables": false }, "commands-show-output": false, "no-missing-space-atx": true, "no-multiple-space-atx": true, "blanks-around-headers": { "lines_above": 1, "lines_below": 1 }, "header-start-left": true, "no-duplicate-header": { "allow_different_nesting": true }, "single-h1": { "level": 1 }, "no-trailing-punctuation": { "punctuation": ".,;:" }, "no-multiple-space-blockquote": true, "no-blanks-blockquote": true, "ol-prefix": { "style": "one" }, "list-marker-space": { "ul_single": 1, "ol_single": 1, "ul_multi": 1, "ol_multi": 1 }, "blanks-around-fences": { "list_items": true }, "blanks-around-lists": true, "no-inline-html": { "allowed_elements": [ "a", "b", "br", "code", "details", "div", "img", "li", "nobr", "p", "pre", "summary", "ul" ] }, "no-bare-urls": true, "hr-style": { "style": "consistent" }, "no-emphasis-as-header": true, "no-space-in-emphasis": false, "no-space-in-code": false, "no-space-in-links": true, "fenced-code-language": true, "code-block-style": { "style": "fenced" }, "first-line-h1": false, "no-empty-links": true, "proper-names": { "names": [], "code_blocks": false } } ``` It appears to be triggering from here: https://github.com/DavidAnson/markdownlint/blob/v0.31.1/lib/markdownlint.js#L606 Looking at the diff between the two releases, the only thing I see that looks like it _might_ be related is this line: https://github.com/DavidAnson/markdownlint/compare/v0.30.0..v0.31.1#diff-807e51fda288b4ebd0ccd4229d72a4c025f9b9316b0244ac45e76d8ff2317269L1025
kerem 2026-03-03 01:28:13 +03:00
Author
Owner

@DavidAnson commented on GitHub (Oct 7, 2023):

According to the stack trace, the bug is probably in MD026. The source of the exception is just reporting an invalid range. The most helpful thing for me would be if you can identify a document that reproduces this problem so I can investigate. It can be a standalone document or you can point me to some existing repository and I can figure out which document it is. thank you!

<!-- gh-comment-id:1751541791 --> @DavidAnson commented on GitHub (Oct 7, 2023): According to the stack trace, the bug is probably in MD026. The source of the exception is just reporting an invalid range. The most helpful thing for me would be if you can identify a document that reproduces this problem so I can investigate. It can be a standalone document or you can point me to some existing repository and I can figure out which document it is. thank you!
Author
Owner

@DavidAnson commented on GitHub (Oct 7, 2023):

Note to self: Likely from this repo: https://github.com/northwood-labs/terraform-provider-corefunc

<!-- gh-comment-id:1751817627 --> @DavidAnson commented on GitHub (Oct 7, 2023): Note to self: Likely from this repo: https://github.com/northwood-labs/terraform-provider-corefunc
Author
Owner

@DavidAnson commented on GitHub (Oct 8, 2023):

The problem (with the repo above, at least) is that it puts YAML front matter inside HTML comment tags and the content of that HTML comment is being treated like Markdown. I've never seen this done before/elsewhere, but certainly it's wrong for markdownlint to throw in this scenario. Here is a simplified reproduction: https://dlaa.me/markdownlint/?renderer=markdownIt#%25m%3C!--%0A---%0Atitle%3A%20Front%20Matter%20YAML%20in%20HTML%20Comment%0Adescription%3A%20%7C-%0A%20%20This%20document%20has%20YAML%20front%20matter%20inside%20an%20HTML%20comment.%0A---%0A--%3E%0A%0A%23%20Front%20Matter%20YAML%20in%20HTML%20Comment%0A%0AText%20text%20text%0A

<!-- gh-comment-id:1751901096 --> @DavidAnson commented on GitHub (Oct 8, 2023): The problem (with the repo above, at least) is that it puts YAML front matter inside HTML comment tags and the content of that HTML comment is being treated like Markdown. I've never seen this done before/elsewhere, but certainly it's wrong for markdownlint to throw in this scenario. Here is a simplified reproduction: https://dlaa.me/markdownlint/?renderer=markdownIt#%25m%3C!--%0A---%0Atitle%3A%20Front%20Matter%20YAML%20in%20HTML%20Comment%0Adescription%3A%20%7C-%0A%20%20This%20document%20has%20YAML%20front%20matter%20inside%20an%20HTML%20comment.%0A---%0A--%3E%0A%0A%23%20Front%20Matter%20YAML%20in%20HTML%20Comment%0A%0AText%20text%20text%0A
Author
Owner

@DavidAnson commented on GitHub (Oct 8, 2023):

It turns out, that pattern is NOT technically an HTML comment which is why it is being parsed by markdownlint. Per the CommonMark specification (https://spec.commonmark.org/0.30/#raw-html):

An HTML comment consists of <!-- + text + -->, where text does not start with > or ->, does not end with -, and does not contain --.

<!-- gh-comment-id:1751902559 --> @DavidAnson commented on GitHub (Oct 8, 2023): It turns out, that pattern is NOT technically an HTML comment which is why it is being parsed by markdownlint. Per the CommonMark specification (<https://spec.commonmark.org/0.30/#raw-html>): > An HTML comment consists of `<!--` + text + `-->`, where text does not start with `>` or `->`, does not end with `-`, and does not contain `--`.
Author
Owner

@skyzyx commented on GitHub (Oct 8, 2023):

Out of interest, in which document did I add the thing which triggered the range error?

(I’ve been a Markdown user since the days when Movable Type was a popular blogging CMS. I also have a general interest in parsers, and in-turn, Commonmark/GFM.)

<!-- gh-comment-id:1752178576 --> @skyzyx commented on GitHub (Oct 8, 2023): Out of interest, in which document did I add the thing which triggered the range error? (I’ve been a Markdown user since the days when Movable Type was a popular blogging CMS. I also have a general interest in parsers, and in-turn, Commonmark/GFM.)
Author
Owner

@DavidAnson commented on GitHub (Oct 9, 2023):

Maybe all of them? But here's one example: docs/data-sources/str_camel.md. This is the pattern I saw in at least a couple of places:

<!--
---
title: Front Matter YAML in HTML Comment
---
-->
<!-- gh-comment-id:1752262713 --> @DavidAnson commented on GitHub (Oct 9, 2023): Maybe all of them? But here's one example: `docs/data-sources/str_camel.md`. This is the pattern I saw in at least a couple of places: ```md <!-- --- title: Front Matter YAML in HTML Comment --- --> ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/markdownlint#585
No description provided.