[GH-ISSUE #366] MD041: errors when using html's h1 instead of # in most cases #2155

Closed
opened 2026-03-07 20:05:06 +03:00 by kerem · 5 comments
Owner

Originally created by @nnmrts on GitHub (Jan 12, 2021).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/366

With the rule MD041 (first-line-heading) enabled:

  • no error using #
    • simple
      code:

      # title
      test test
      ## test level 2
      

      rendered:

      title

      test test

      test level 2

    • image as title
      code:

      # ![](https://via.placeholder.com/200x100)
      
      test test
      
      ## test level 2
      

      rendered:

      test test

      test level 2

    • centered image as title using p and img
      code:

      # <p align="center"><img src="https://via.placeholder.com/200x100"></p>
      
      test test
      
      ## test level 2
      

      rendered (note: this renders differently in github readmes than comments; the heading line below the image here is above the image in readmes (which is not what we want in general)):

      test test

      test level 2

    • centered image as title using h1 and img (this has two level-1 headings in one line and also (correctly) renders two heading lines, both is not nice)
      code:

      # <h1 align="center"><img src="https://via.placeholder.com/200x100"></h1>
      
      test test
      
      ## test level 2
      

      rendered:

      test test

      test level 2

  • no error using h1
    • it's okay with h1 stuff as long as something with # comes after it
      code:
      <h1>title</h1>
      # title
      test test
      ## test level 2
      
      rendered:

      title

      # title

      test test

      test level 2

  • error using h1
    • simple
      code:

      <h1>title</h1>
      test test
      ## test level 2
      

      rendered:

      title

      test test

      test level 2

    • image as title
      code:

      <h1><img src="https://via.placeholder.com/200x100"></h1>
      
      test test
      
      ## test level 2
      

      rendered:

      test test

      test level 2


While I know that using h1 instead of # is not "pure" and that using images as titles is kinda weird, both are often seen in GitHub readme files for a reason. The first one because you can't center #, but you can center h1 (<h1 align="center">title</h1>). The second one because the first image (or even the first "thing") in a readme often is the logo, which includes the project name most of the time, so it feels kinda redundant to have the name of your project above the logo of your project which includes the name of your project again.

Originally created by @nnmrts on GitHub (Jan 12, 2021). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/366 With the rule MD041 (first-line-heading) enabled: - no error using `#` - simple code: ```md # title test test ## test level 2 ``` rendered: > # title > > test test > > ## test level 2 - image as title code: ```md # ![](https://via.placeholder.com/200x100) test test ## test level 2 ``` rendered: > # ![](https://via.placeholder.com/200x100) > > test test > > ## test level 2 - centered image as title using `p` and `img` code: ```md # <p align="center"><img src="https://via.placeholder.com/200x100"></p> test test ## test level 2 ``` rendered (note: this renders differently in github readmes than comments; the heading line below the image here is above the image in readmes (which is not what we want in general)): > # <p align="center"><img src="https://via.placeholder.com/200x100"></p> > > test test > > ## test level 2 - centered image as title using `h1` and `img` (this has two level-1 headings in one line and also (correctly) renders two heading lines, both is not nice) code: ```md # <h1 align="center"><img src="https://via.placeholder.com/200x100"></h1> test test ## test level 2 ``` rendered: > # <h1 align="center"><img src="https://via.placeholder.com/200x100"></h1> > > test test > > ## test level 2 - no error using h1 - it's okay with `h1` stuff as long as something with `#` comes after it code: ```md <h1>title</h1> # title test test ## test level 2 ``` rendered: > <h1>title</h1> > # title > > test test > > ## test level 2 - error using h1 - simple code: ```md <h1>title</h1> test test ## test level 2 ``` rendered: > <h1>title</h1> > > test test > > ## test level 2 - image as title code: ```md <h1><img src="https://via.placeholder.com/200x100"></h1> test test ## test level 2 ``` rendered: > <h1><img src="https://via.placeholder.com/200x100"></h1> > > test test > > ## test level 2 --- While I know that using `h1` instead of `#` is not "pure" and that using images as titles is kinda weird, both are often seen in GitHub readme files for a reason. The first one because you can't center `#`, but you can center `h1` (`<h1 align="center">title</h1>`). The second one because the first image (or even the first "thing") in a readme often is the logo, which includes the project name most of the time, so it feels kinda redundant to have the name of your project above the logo of your project which includes the name of your project again.
kerem 2026-03-07 20:05:06 +03:00
Author
Owner

@nnmrts commented on GitHub (Jan 12, 2021):

I'm writing a new comment here so I don't have to edit the original issue again (sorry):

Is there a rationale behind the rule just accepting # and not h1 as well? I would suggest either:

  • change the current rule to also accept h1 as top level heading
  • add a new rule which determines if html headings are allowed (and have the same meaning) instead of markdown headings
<!-- gh-comment-id:758613965 --> @nnmrts commented on GitHub (Jan 12, 2021): I'm writing a new comment here so I don't have to edit the original issue again (sorry): Is there a rationale behind the rule just accepting `#` and not `h1` as well? I would suggest either: - change the current rule to also accept h1 as top level heading - add a new rule which determines if html headings are allowed (and have the same meaning) instead of markdown headings
Author
Owner

@DavidAnson commented on GitHub (Jan 12, 2021):

I kind of feel like this is an abuse of Markdown, but it may be straightforward to add and I'll have a look.

<!-- gh-comment-id:758771480 --> @DavidAnson commented on GitHub (Jan 12, 2021): I kind of feel like this is an abuse of Markdown, but it may be straightforward to add and I'll have a look.
Author
Owner

@nnmrts commented on GitHub (Jan 12, 2021):

@DavidAnson I agree. As I said, this is not pure, and it is far from beautiful too. If there was a way to center images (or anything at all) in markdown on GitHub, I (and many others) would definitely use it before even considering using html tags. There is so much potential for styling markdown on GitHub, but after years of proposals and ideas to support a limited version of the style attribute or some sort of inline class attributes on their end, it seems like they just don't want to go in that direction with markup, I guess.

Normally this wouldn't be in the scope of markdownlint at all, and I'd fully understand if this rule never gets changed. But in my mind and since using html to do stuff markdown can't do is a common practice, this would be a great change.

<!-- gh-comment-id:759006785 --> @nnmrts commented on GitHub (Jan 12, 2021): @DavidAnson I agree. As I said, this is not pure, and it is far from beautiful too. If there was a way to center images (or anything at all) in markdown on GitHub, I (and many others) would definitely use it before even considering using html tags. There is so much potential for styling markdown on GitHub, but after years of proposals and ideas to support a limited version of the `style` attribute or some sort of inline `class` attributes on their end, it seems like they just don't want to go in that direction with markup, I guess. Normally this wouldn't be in the scope of markdownlint at all, and I'd fully understand if this rule never gets changed. But in my mind and since using html to do stuff markdown can't do is a common practice, this would be a great change.
Author
Owner

@MichaIng commented on GitHub (Feb 10, 2021):

Ah nice, many thanks, we suffer from this issue just now. I hope for a soon release of markdownlint-cli2 to contain this change?

<!-- gh-comment-id:776988498 --> @MichaIng commented on GitHub (Feb 10, 2021): Ah nice, many thanks, we suffer from this issue just now. I hope for a soon release of markdownlint-cli2 to contain this change?
Author
Owner

@DavidAnson commented on GitHub (Feb 10, 2021):

Yes

<!-- gh-comment-id:777009632 --> @DavidAnson commented on GitHub (Feb 10, 2021): Yes
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#2155
No description provided.