Skip to content
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

MD037/no-space-in-emphasis reported when underscore contained within emphasis #324

Closed
tekumara opened this issue Aug 28, 2020 · 7 comments
Closed

Comments

@tekumara
Copy link

tekumara commented Aug 28, 2020

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

_~/.ssh/id_rsa_ and _foo_

Renders as:

~/.ssh/id_rsa and foo

@DavidAnson
Copy link
Owner

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

@tekumara
Copy link
Author

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 😢

@DavidAnson
Copy link
Owner

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

@tekumara
Copy link
Author

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

@DavidAnson
Copy link
Owner

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

@tekumara
Copy link
Author

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.

@DavidAnson
Copy link
Owner

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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants