-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Markdownlint: Add custom rule "Blanks around multiline HTML tags" #27674
Markdownlint: Add custom rule "Blanks around multiline HTML tags" #27674
Conversation
Original function would flag markdownlint-disable-* comments which would require being followed by the line to disable. It would also flag HTML tags directly following or preceding triple backticks. These are now allowed so that code blocks can start and end more cleanly.
Added TOP005 rule to linter config file.
These files' first lines need to be level 1 headings, not level 3, as they are not files to be rendered on the TOP website.
I like how it already includes the new rule in the actions. I guess it runs using the rules from my fork as opposed to the rules from upstream. |
Technically HTML tags on the first or last line of a file would trigger other rules to error, but adding `?? ""` for the sake of completeness. Single quotes have been switched to double quotes to be consistent with other JS files in the repo.
Demonstrates how a lack of blank lines interferes with unrelated lint checks.
Bug found - need to account for any unindented HTML tags inside code blocks and not the first or last line. Rare edge case but would rather fix it now than later. |
These cases have a legitimate need to "break the rule". We only want to flag for HTML tags we use for the actual lesson markup, or md code block examples of such. .trim added so that indentation doesn't matter.
Now includes examples of ignored code blocks (html/jsx type).
Bug fixed - needed to allow all HTML within html/jsx code blocks. |
markdownlint/TOP005_blanksAroundMultilineHtmlTags/tests/TOP005_test.md
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/TOP005_blanksAroundMultilineHtmlTags.js
Outdated
Show resolved
Hide resolved
markdownlint/TOP005_blanksAroundMultilineHtmlTags/tests/TOP005_test.md
Outdated
Show resolved
Hide resolved
Removed unrelated errors to make it easier to demonstrate TOP005. The behaviour with unrelated errors are now explained in text. Fixed opening introduction line as it incorrectly stated there would not be any errors flagged.
Opted to return token.map as is on line 19 instead of the same but with 1 subtracted from token.map[1]. The only difference this makes is include the closing backticks line in the isWithinIgnoredFence range check, which will have no effect on the outcome of the check. The benefit is not needing to explain why we need to subtract 1 from token.map[1] only. This allows everything to remain intuitive, and the only deviation being the onError.lineNumber value which has a comment to explain its 1-index requirement. Regexr test links added. Co-authored-by: Eric Olkowski <thatblindgeye@gmail.com>
These should already be ignored by the lint actions
Includes visual formatting improvements.
Because
Discovered in #27648, until a blank line is reached, any text following an opening HTML tag gets ignored by the linter almost all of the time. This allows for easy misses due to uncaught rule errors.
The cause of this is markdown-it's method for parsing HTML blocks, where any content following an opening HTML tag, until a blank line is reached, gets bundled into the same single
html_block
token. Thus, they don't get their own tokens and so bypass lint checks.By enforcing blank lines (or code block delimiters) surrounding isolated HTML tags, the above is avoided and all HTML block text content can be linted appropriately. HTML tags within text (e.g. spans/anchors for link fragments) are ignored by this rule.
This PR
.md
file for TOP005 demonstrating valid and invalid casesIssue
Closes #27673
Additional Information
Failed lint checks all come from the
TOP005_test.md
file which are all intended errors.Pull Request Requirements
location of change: brief description of change
format, e.g.Intro to HTML and CSS lesson: Fix link text
Because
section summarizes the reason for this PRThis PR
section has a bullet point list describing the changes in this PRIssue
section