mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2026-04-26 09:46:01 +03:00
[GH-ISSUE #789] MD049 should not trigger when using asterisk for intraword emphasis #2382
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#2382
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 @Josh-Cena on GitHub (Apr 24, 2023).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/789
Consider the following config (using markdownlint-cli2):
However, MD049 triggers for the following code:
These cases cannot be fixed to underscores, because underscores are not allowed as intraword emphasis, per CommonMark:
Prettier correctly handles this case by not converting the asterisks (and even actively corrects underscores to asterisks).
@DavidAnson commented on GitHub (Apr 24, 2023):
You've told the rule that all emphasis should be done with an underscore and it is correctly reporting on instances that are using asterisk for emphasis instead.
I don't think I agree it's wrong to do so. In this case, you could switch to underscore as shown here: https://dlaa.me/markdownlint/#%25m%23%20Issue%20780%0A%0AIn%20this%20array%2C%20the%20leftmost%20column%20contains%20the%20entries%20a%E2%82%81%2C%20a%E2%82%82%2C%20a%E2%82%83%2C%20and%20a%E2%82%84.%0A%0AIn%20this%20array%2C%20the%20leftmost%20column%20contains%20the%20entries%20_a%E2%82%81_%2C%20_a%E2%82%82_%2C%20_a%E2%82%83_%2C%20and%20_a%E2%82%84_.%0A%0A%3C!--%20markdownlint-configure-file%20%7B%0A%20%20%22MD049%22%3A%20%7B%0A%20%20%20%20%22style%22%3A%20%22underscore%22%0A%20%20%7D%0A%7D%20--%3E%0A
I realize that output is subtly different, but I'm not sure this is the kind of nuance I want to try to bake into the rule implementation. Instead, I am inclined to suggest this is an edge case, and you can use an inline comment to disable the rule for this case.
@Josh-Cena commented on GitHub (Apr 24, 2023):
This is semantically incorrect: subscripts are number entities, which must remain upright in formulae. Also consider other cases where intraword emphasis is intentional:
*J*ava*S*cript *O*bject *N*otation.The rule reports instances where underscores should be used but asterisks are seen. But in this instance, using underscore makes it not even an emphasis anymore. When I use
"underscore", I'm enforcing a style of "use underscores where I can", not "any emphasis using asterisk is automatically wrong".It even comes with an autofixer that produces invalid output. It is my belief (from working on ESLint rules) that an autofixer should never break code, because people unconsciously run it in CI/pre-commit and then may never notice it again. Since making the autofixer conditionally available is not any less complex than making the rule report at all, maybe we should remove the autofixer if we don't want this logic in the rule?