[GH-ISSUE #1678] New Rule: Order of List + Heading = 1. List 2. Heading #733

Closed
opened 2026-03-03 01:29:26 +03:00 by kerem · 9 comments
Owner

Originally created by @Malix-Labs on GitHub (Jul 14, 2025).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1678

Numbered headings doesn't seem to have a standard, but there is two ways of doing them

The GitHub renderer seems to correctly parse the semantic (but also does not adjust the font size) of a List, then a Heading:

1. ## First Part

Body of the first part

2. ## Second Part

Body of the second part
  1. First Part

Body of the first part

  1. Second Part

Body of the second part

But seems to not correctly parse the semantic (but also does adjust the font size) of a Heading, then a List:

## 1. First Part

Body of the first part

## 2. Second Part

Body of the second part

1. First Part

Body of the first part

2. Second Part

Body of the second part

I do not know if that is in the standard markdown spec,
But it might be worth creating a new rule for it

Originally created by @Malix-Labs on GitHub (Jul 14, 2025). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1678 <!-- Thank you for taking the time to report an issue! When deciding where to open an issue, please note there are multiple projects under the markdownlint umbrella: - https://github.com/DavidAnson/markdownlint : This is the core JavaScript/Node.js library and is used by other tools. Most issues with implementation and rule behavior belong here. - https://github.com/igorshubovych/markdownlint-cli : This is the original CLI for markdownlint. Issues specific to CLI belong here. - https://github.com/DavidAnson/markdownlint-cli2 : This is a newer CLI for markdownlint and is used by other tools. Issues specific to CLI2 belong here. - https://github.com/DavidAnson/vscode-markdownlint : This is the Visual Studio Code extension for markdownlint. Issues specific to VS Code belong here. - https://github.com/DavidAnson/markdownlint-cli2-action : This is a GitHub Action for markdownlint. Issues specific to the Action belong here. - https://github.com/markdownlint/markdownlint : This is the original markdownlint implementation for Ruby. All Ruby-related issues belong here. Before creating an issue, it's a good practice to search existing issues for something similar. If your issue has already been reported, please update the existing one with any new information. It's also good to review the documentation for any relevant details. When describing an issue, the following information is helpful: - What did you do? - What did you expect to happen? - What actually happened? - What messages or errors were there? - How can the issue be reproduced? - What version were you using? - What operating system were you using? The simplest demonstration of a problem is the most helpful. Small examples can be pasted into the issue description. (Be sure to paste as code so GitHub doesn't render the example in Markdown.) For larger examples, linking to a repository or file is more appropriate. Before proposing a new rule, please review the existing suggestions: https://github.com/DavidAnson/markdownlint/issues?q=is%3Aissue+is%3Aopen+label%3A%22new+rule%22 Thank you! --> Numbered headings doesn't seem to have a standard, but there is two ways of doing them The GitHub renderer seems to correctly parse the semantic (but also does not adjust the font size) of a List, then a Heading: > ```md > 1. ## First Part > > Body of the first part > > 2. ## Second Part > > Body of the second part > ``` > > 1. ## First Part > > Body of the first part > > 2. ## Second Part > > Body of the second part But seems to not correctly parse the semantic (but also does adjust the font size) of a Heading, then a List: > ```md > ## 1. First Part > > Body of the first part > > ## 2. Second Part > > Body of the second part > ``` > > ## 1. First Part > > Body of the first part > > ## 2. Second Part > > Body of the second part I do not know if that is in the standard markdown spec, But it might be worth creating a new rule for it
kerem 2026-03-03 01:29:26 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@DavidAnson commented on GitHub (Jul 14, 2025):

I'm not sure this construct makes a lot of sense in either form. I'd guess this is quite rare in practice. Perhaps a rule could exist to discourage both forms, but I don't think I see a lot of value if it's already something people don't do?

<!-- gh-comment-id:3071251035 --> @DavidAnson commented on GitHub (Jul 14, 2025): I'm not sure this construct makes a lot of sense in either form. I'd guess this is quite rare in practice. Perhaps a rule could exist to discourage both forms, but I don't think I see a lot of value if it's already something people don't do?
Author
Owner

@Malix-Labs commented on GitHub (Jul 15, 2025):

I see numbered headings quite often personally

i.e. yesterday, I encountered it in the Markdown form of AGPL v3

<!-- gh-comment-id:3072341425 --> @Malix-Labs commented on GitHub (Jul 15, 2025): I see numbered headings quite often personally i.e. yesterday, I encountered it in [the Markdown form of AGPL v3](https://www.gnu.org/licenses/agpl-3.0.md)
Author
Owner

@DavidAnson commented on GitHub (Jul 15, 2025):

That document you link to is Markdown in the sense that all text is Markdown, but I do not think it is making any attempt to adhere to basic Markdown conventions.

In your example, it looks to me like someone wanted to emphasize the numbered sections of an existing text document and just made them all headings.

Here's another example, a sequence of unordered list items containing a single ordered list item each:

provided that you also meet all of these conditions:

-   a) The work must carry prominent ...

I do not want to make too many decisions based on scenarios like this that feel like Markdown in name only.

<!-- gh-comment-id:3072531257 --> @DavidAnson commented on GitHub (Jul 15, 2025): That document you link to is Markdown in the sense that all text is Markdown, but I do not think it is making any attempt to adhere to basic Markdown conventions. In your example, it looks to me like someone wanted to emphasize the numbered sections of an existing text document and just made them all headings. Here's another example, a sequence of unordered list items containing a single ordered list item each: ``` provided that you also meet all of these conditions: - a) The work must carry prominent ... ``` I do not want to make too many decisions based on scenarios like this that feel like Markdown in name only.
Author
Owner

@Malix-Labs commented on GitHub (Jul 15, 2025):

This is true indeed

However, I think numbered headings are still valuable

They are especially common for legal or legislative (non-markdown) documents

<!-- gh-comment-id:3072759970 --> @Malix-Labs commented on GitHub (Jul 15, 2025): This is true indeed However, I think numbered headings are still valuable They are especially common for legal or legislative (non-markdown) documents
Author
Owner

@DavidAnson commented on GitHub (Jul 15, 2025):

FYI, headings that begin with a list item-like number are not treated as ordered or unordered lists per the CommonMark specification.

Specifically, the body of an ATX list is parsed as inline content which excludes list items (which are container blocks): https://spec.commonmark.org/0.31.2/#atx-headings

Corresponding example using the dingus: https://spec.commonmark.org/dingus/?text=%23%201.%20Test%0A%0A

<!-- gh-comment-id:3073696319 --> @DavidAnson commented on GitHub (Jul 15, 2025): FYI, headings that begin with a list item-like number are not treated as ordered or unordered lists per the CommonMark specification. Specifically, the body of an ATX list is parsed as inline content which excludes list items (which are container blocks): https://spec.commonmark.org/0.31.2/#atx-headings Corresponding example using the dingus: https://spec.commonmark.org/dingus/?text=%23%201.%20Test%0A%0A
Author
Owner

@DavidAnson commented on GitHub (Jul 15, 2025):

List items can explicitly include headings: https://spec.commonmark.org/0.31.2/#example-300

<!-- gh-comment-id:3073710423 --> @DavidAnson commented on GitHub (Jul 15, 2025): List items can explicitly include headings: https://spec.commonmark.org/0.31.2/#example-300
Author
Owner

@Malix-Labs commented on GitHub (Jul 15, 2025):

List items can explicitly include headings: spec.commonmark.org/0.31.2#example-300

Indeed;
Thus:

A List, then a Heading:

1. ## First Part

Body of the first part

2. ## Second Part

Body of the second part
  1. First Part

Body of the first part

  1. Second Part

Body of the second part

Is correct

While a Heading, then a List:

## 1. First Part

Body of the first part

## 2. Second Part

Body of the second part

1. First Part

Body of the first part

2. Second Part

Body of the second part

Is incorrect

<!-- gh-comment-id:3074364148 --> @Malix-Labs commented on GitHub (Jul 15, 2025): > List items can explicitly include headings: [spec.commonmark.org/0.31.2#example-300](https://spec.commonmark.org/0.31.2/#example-300) Indeed; Thus: A List, then a Heading: > ```md > 1. ## First Part > > Body of the first part > > 2. ## Second Part > > Body of the second part > ``` > > 1. ## First Part > > Body of the first part > > 2. ## Second Part > > Body of the second part Is correct While a Heading, then a List: > ```md > ## 1. First Part > > Body of the first part > > ## 2. Second Part > > Body of the second part > ``` > > ## 1. First Part > > Body of the first part > > ## 2. Second Part > > Body of the second part Is incorrect
Author
Owner

@DavidAnson commented on GitHub (Jul 15, 2025):

What do you mean by "correct" and "incorrect"? These are two different structures with (seemingly) defined behavior. Putting large blocks of content inside a list has different implications than having numbered headings, but I'm not sure I'd say either is obviously better in the abstract or in what scenarios one or the other is inappropriate.

<!-- gh-comment-id:3075839854 --> @DavidAnson commented on GitHub (Jul 15, 2025): What do you mean by "correct" and "incorrect"? These are two different structures with (seemingly) defined behavior. Putting large blocks of content inside a list has different implications than having numbered headings, but I'm not sure I'd say either is obviously better in the abstract or in what scenarios one or the other is inappropriate.
Author
Owner

@Malix-Labs commented on GitHub (Oct 4, 2025):

Have you tested how the vast majority of markdown processors handle them?

<!-- gh-comment-id:3368580542 --> @Malix-Labs commented on GitHub (Oct 4, 2025): Have you tested how the vast majority of markdown processors handle them?
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#733
No description provided.