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

Markdown: Breaks italic syntax that contains unescaped underscores #6112

Open
abemedia opened this issue May 10, 2019 · 6 comments
Open

Markdown: Breaks italic syntax that contains unescaped underscores #6112

abemedia opened this issue May 10, 2019 · 6 comments
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:markdown Issues affecting Markdown scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program

Comments

@abemedia
Copy link

Prettier 1.17.0
Playground link

--parser markdown

Input:

# Title

## Correct Output

*[Italic link](../_link_including_underscores_.md)*

---

## Incorrect Output

_[Italic link](../_link_including_underscores_.md)_

---  

Output:

# Title

## Correct Output

_[Italic link](../_link_including_underscores_.md)_

---

## Incorrect Output

_[Italic link](../\_link_including_underscores_.md)\_

---

Expected behavior:

# Title

## Correct Output

_[Italic link](../_link_including_underscores_.md)_

---

## Incorrect Output

_[Italic link](../_link_including_underscores_.md)_

---

(Should not escape the final underscore for Incorrect Output.)

@duailibe duailibe added help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:markdown Issues affecting Markdown type:bug Issues identifying ugly output, or a defect in the program labels May 14, 2019
@revelt
Copy link

revelt commented May 14, 2019

Remark parser assumes _[Italic link](../_link_including_underscores_ is emphasis and .md)_ is text. Try yourselves: https://astexplorer.net/ (set markdown as parser)

But shouldn't underscores be escaped anyway?

For example, escaped _[Italic link](../_link_including_underscores\_.md)_ parses correctly.

It seems it's malformed (unescaped) input, not a prettier's bug. What do you think?

@duailibe
Copy link
Member

@revelt Thanks again.. you're right.

This isn't a high priority bug since the output is valid, but it's not exactly pretty, so we should probably fix it anyway?

@revelt
Copy link

revelt commented May 14, 2019

To add 2p, the unescaped input broke even GitHub syntax highlighter, it's visible on a Stylus GitHub Dark theme (v1.21.52):

markdown_bug

@josh11b
Copy link

josh11b commented Mar 23, 2022

I just ran into a problem with this using version 2.3.2:

Input:

_[link 1](https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Non-subclassable_classes)_
_[link 2](<https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Non-subclassable_classes>)_

Output:

_[link 1](https://en.wikipedia.org/wiki/Inheritance_(object-oriented*programming)#Non-subclassable_classes)*
_[link 2](<https://en.wikipedia.org/wiki/Inheritance_(object-oriented*programming)#Non-subclassable_classes>)*

This rewrite breaks the link and does not render correctly:

_link 1*
_link 2*

Expected behavior:

_[link 1](<https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Non-subclassable_classes>)_
_[link 2](<https://en.wikipedia.org/wiki/Inheritance_(object-oriented_programming)#Non-subclassable_classes>)_

which works as expected:
link 1
link 2

josh11b added a commit to carbon-language/carbon-lang that referenced this issue Mar 23, 2022
Looks like this might be related to prettier/prettier#6112 , but the observed behavior is more broken than that bug indicates.
@chris-grabcad
Copy link

chris-grabcad commented Mar 28, 2022

There's a similar issue without even considering links

my_file_name is _italic_

is prettified to

my*file_name is \_italic*

I tried to circumvent this by escaping the _ characters like this

my\_file\_name is _italic_

which gets prettified to

my_file_name is _italic_

which in turn gets prttified to

my*file_name is \_italic*

So it seems that prettifying the file twice (we're using a pre-commit hook with pretty-quick) will break the formatting and the intention

even if you escape the _ at some point it will eventually deteriorate and break syntax :-(

please see this playground

if required I can make this a separate issue.

@thorn0 thorn0 added the scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency label Jan 12, 2023
@seiyab
Copy link
Sponsor Contributor

seiyab commented Jan 31, 2024

Related: #11828

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted We're a small group who can't get to every issue promptly. We’d appreciate help fixing this issue! lang:markdown Issues affecting Markdown scope:dependency Issues that cannot be solved inside Prettier itself, and must be fixed in a dependency type:bug Issues identifying ugly output, or a defect in the program
Projects
None yet
Development

No branches or pull requests

7 participants