[GH-ISSUE #324] MD037/no-space-in-emphasis reported when underscore contained within emphasis #278

Closed
opened 2026-03-03 01:25:21 +03:00 by kerem · 7 comments
Owner

Originally created by @tekumara on GitHub (Aug 28, 2020).
Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/324

The following markdown snippet, reports MD037/no-space-in-emphasis

_~/.ssh/id_rsa_ and _foo_

Renders as:

~/.ssh/id_rsa and foo

Originally created by @tekumara on GitHub (Aug 28, 2020). Original GitHub issue: https://github.com/DavidAnson/markdownlint/issues/324 The following markdown snippet, reports MD037/no-space-in-emphasis ``` _~/.ssh/id_rsa_ and _foo_ ``` Renders as: _~/.ssh/id_rsa_ and _foo_
kerem 2026-03-03 01:25:21 +03:00
Author
Owner

@DavidAnson commented on GitHub (Aug 28, 2020):

This renders correctly because the parser makes assumptions about whitespace that allow it to ignore the embedded underscore. However, the linting rule cannot do that because it is specifically looking for mistakes in that area. Therefore, this is expected behavior for the rule. It believes the underscores match in pairs and therefore sees a problem. In order to fix this, you can escape the embedded underscore with a backslash. Here's an example of your text not reporting any violations:  https://dlaa.me/markdownlint/#%25m%23%20Issue%20324%0A%0A_~%2F.ssh%2Fid%5C_rsa_%20and%20_foo_%0A

<!-- gh-comment-id:682785815 --> @DavidAnson commented on GitHub (Aug 28, 2020): This renders correctly because the parser makes assumptions about whitespace that allow it to ignore the embedded underscore. However, the linting rule cannot do that because it is specifically looking for mistakes in that area. Therefore, this is expected behavior for the rule. It believes the underscores match in pairs and therefore sees a problem. In order to fix this, you can escape the embedded underscore with a backslash. Here's an example of your text not reporting any violations:  https://dlaa.me/markdownlint/#%25m%23%20Issue%20324%0A%0A_~%2F.ssh%2Fid%5C_rsa_%20and%20_foo_%0A
Author
Owner

@tekumara commented on GitHub (Aug 29, 2020):

Thanks for the quick response!

It looks like the commonmark spec allows for underscores inside emphasis, so the parser is happy.

_~/.ssh/id\_rsa_ makes markdownlint happy but prettier removes the backslash, so I can't win 😢

<!-- gh-comment-id:683221123 --> @tekumara commented on GitHub (Aug 29, 2020): Thanks for the quick response! It looks like the [commonmark spec](https://spec.commonmark.org/0.29/#emphasis-and-strong-emphasis) allows for underscores inside emphasis, so the parser is happy. `_~/.ssh/id\_rsa_` makes markdownlint happy but [prettier](https://prettier.io/) removes the backslash, so I can't win 😢
Author
Owner

@DavidAnson commented on GitHub (Aug 29, 2020):

How do you feel about using asterisk for emphasis for that part? Doing so allows the underscore to be an escaped like so: https://dlaa.me/markdownlint/#%25m%23%20Issue%20324%0A%0A*~%2F.ssh%2Fid_rsa*%20and%20_foo_%0A

<!-- gh-comment-id:683223822 --> @DavidAnson commented on GitHub (Aug 29, 2020): How do you feel about using asterisk for emphasis for that part? Doing so allows the underscore to be an escaped like so: https://dlaa.me/markdownlint/#%25m%23%20Issue%20324%0A%0A*~%2F.ssh%2Fid_rsa*%20and%20_foo_%0A
Author
Owner

@tekumara commented on GitHub (Aug 29, 2020):

I prefer asterisk actually, but when I run prettier it converts asterisks to underscores (and causes the MD037 report) 🤕

<!-- gh-comment-id:683225714 --> @tekumara commented on GitHub (Aug 29, 2020): I prefer asterisk actually, but when I run prettier it converts asterisks to underscores (and causes the MD037 report) 🤕
Author
Owner

@DavidAnson commented on GitHub (Aug 29, 2020):

I've lost track, is Prettier helping us or hurting us? 😐

<!-- gh-comment-id:683226333 --> @DavidAnson commented on GitHub (Aug 29, 2020): I've lost track, is Prettier helping us or hurting us? 😐
Author
Owner

@tekumara commented on GitHub (Aug 29, 2020):

99% of the time it's great. It will resolve a lot of issues identified by markdownlint (things like bare URLs, or trailing punctuation in headings, it can't fix automatically). For this edge case tho, markdownlint and prettier work against each other.

<!-- gh-comment-id:683227464 --> @tekumara commented on GitHub (Aug 29, 2020): 99% of the time it's great. It will resolve a lot of issues identified by markdownlint (things like bare URLs, or trailing punctuation in headings, it can't fix automatically). For this edge case tho, markdownlint and prettier work against each other.
Author
Owner

@DavidAnson commented on GitHub (Jun 19, 2021):

I don't see a simple way for this rule to be flexible enough to detect issues and also strict enough to allow this case. Because there are two easy workarounds (escape the underscore or use asterisks), I'm going to close the issue.

<!-- gh-comment-id:864351176 --> @DavidAnson commented on GitHub (Jun 19, 2021): I don't see a simple way for this rule to be flexible enough to detect issues and also strict enough to allow this case. Because there are two easy workarounds (escape the underscore or use asterisks), I'm going to close the issue.
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#278
No description provided.