mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 01:36:03 +03:00
[GH-ISSUE #1213] HTML disable/enables comments triggered when inside Markdown inline code #640
Labels
No labels
bug
enhancement
enhancement
enhancement
fixed in next
fixed in next
fixed in next
new rule
new rule
new rule
pull-request
question
refactoring
refactoring
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/markdownlint#640
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @rachmari on GitHub (May 15, 2024).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/1213
I noticed recently that even when an HTML enable/disable comment is inside inline code (e.g.,
<!-- markdownlint-enable -->), it is still executed.I noticed that the regex
/<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/gidoes not account for whether the disable/enable comments are inside inline code. If a negative lookbehind is used/((?<!)<!--\s*markdownlint-(disable|enable|capture|restore|disable-file|enable-file|disable-line|disable-next-line|configure-file))(?:\s|-->)/githe HTML comments are properly ignored.Are Markdown inline code tags ignored by design?
For some background about why we ran into this issue, we write documentation for how to use our custom Markdownlint linter for external contributors (https://github.com/github/docs/blob/main/content/contributing/collaborating-on-github-docs/using-the-content-linter.md). That documentation uses some HTML pre tags and other things to get the Markdown to render properly, which causes other issues in our rendering pipeline.
In our docs, we'd like to write something like this in a Markdown file while also still being able to run Markdownlint on the same file:
This will effectively disable all rules, and prevent any errors from being raised. On the opposite side, using
<!-- markdownlint-enable -->will enable all rules, even rules we don't include in our custom config.@DavidAnson commented on GitHub (May 15, 2024):
I think your lookbehind got garbled, but I'd be reluctant to "fix" this too narrowly as there is no guarantee the backticks are tight to the comment (or that nothing else is in between).
What do you think about this approach that works today: https://dlaa.me/markdownlint/#%25m%23%20Issue%201213%0A%0AText%20%60%3C!--%20markdownlint-disable%20--%3E%60%20text%0A%0A%3C!--%20markdownlint-restore%20--%3E%0A%0A%23%20Extra%20H1%0A
@rachmari commented on GitHub (May 15, 2024):
@DavidAnson sorry for the typo in the issue summary. There was an extra ` (Fixed).
I didn't know about the restore config option. Does this option restore back to the rule configuration prior to any disables/enables? I see the description in the README, but it's not clear whether it restores back to the captured configuration. It seems to imply that the restore option must be used only after the capture option is used. Is that accurate?
@DavidAnson commented on GitHub (May 15, 2024):
If you scroll down a bit in the README, it says there is an implicit capture at the top of every document. It's not wrong to pair every restore with a capture, but it's unnecessary if nothing has been disabled or enabled up to that point.
@rachmari commented on GitHub (May 15, 2024):
@DavidAnson thank you for the explanation. In that case, the solution you provided does work for us. Thank you! ✨