Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Core Grammars:
- enh(json) add json5 support [Kerry Shetline][]
- fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][]
- fix(csharp) Support digit separators [te-ing][]
- fix(markdown) Ignore mid_word underscores, issue #4279 [Dan Vanderkam]

Documentation:

Expand Down Expand Up @@ -55,6 +56,7 @@ CONTRIBUTORS
[te-ing]: https://github.com/te-ing
[Anthony Martin]: https://github.com/anthony-c-martin
[NriotHrreion]: https://github.com/NriotHrreion
[Dan Vanderkam]: https://github.com/danvk


## Version 11.11.1
Expand Down
4 changes: 2 additions & 2 deletions src/languages/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ export default function(hljs) {
end: /\*/
},
{
begin: /_(?![_\s])/,
end: /_/,
begin: /(?<![a-zA-Z0-9])_(?![_\s])/,
end: /_(?![a-zA-Z0-9])/,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to sit until v12 unless you know how to do this without negative look-behind... this would be a breaking change for older versions of Safari that v11 still supports.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a look @joshgoebel. Is there any guess when there might be a v12? Is it months, years, maybe never?

Claude came up with a more complex version that doesn't have any negative lookbehind. If this seems reasonable, I can move it over to this PR:
main...danvk:highlight.js:markdown-midword-underscore-no-lookbehind

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to say, I would have thought a year ago but then I got busy with life.

I guess if we're never going to need to match on that last character for another mode then it could be gobbled up by the "guard" here, yes... When you pull that over please also leave your negative look-behind in place, just comment it out and add a short comment that it's for v12+.

relevance: 0
}
]
Expand Down
3 changes: 3 additions & 0 deletions test/markup/markdown/bold_italics.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ _ not italic_
<span class="hljs-quote">&gt; * One (this point is italic)</span>
<span class="hljs-quote">&gt; * Two</span>
<span class="hljs-quote">&gt; * Three</span>

No italics mid_word underscores.
But italics for <span class="hljs-emphasis">_full_word_</span> with underscores.
3 changes: 3 additions & 0 deletions test/markup/markdown/bold_italics.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ _ not italic_
> * One (this point is italic)
> * Two
> * Three

No italics mid_word underscores.
But italics for _full_word_ with underscores.