Skip to content

Proposed rules for markdown comment formatting and readability. #1618

@wwarriner

Description

@wwarriner

I'd like to propose one or more new rules around the use of HTML comments.

  1. No non-comment content on the same line as a comment open or close if the comment is multi-line.
  2. No comment content on the same line as a comment open or close, except for single-line comment. Could be split into open, close, both options.
  3. Exactly one space before and after comment content in single-line comments.
  4. No non-comment content on the same line as a single-line comment.

The following would trigger (1):

md <!--
comment
-->

<!--
comment
--> md

The following would trigger (2):

<!-- comment
-->

<!--
comment -->

The following would trigger (3):

<!--comment -->
<!-- comment-->
<!--  comment -->
<!-- comment  -->

The following would trigger (4):

md <!-- comment -->
<!-- comment --> md

I understand (4) may be the most contentious. The first three proposals are in line with linters, formatters, and parsers for other languages, and improve readability.

None of these should change page rendering, at least in MkDocs. All of them should be automatically fixable as well. Multiline comments would stay multiline comments, single line comments would stay single line comments, markdown content would be pushed to the appropriate locations away from the comments, and spaces in single line comments would be standardized.

I assume this would also apply to comments which are markdownlint-* directives. There is an open question of how to disable this/these rules, which might involve comments around comments. I don't think that would break anything, nor why someone would want to do that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions