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
fix: Support escapes within emphasis #2627
fix: Support escapes within emphasis #2627
Conversation
...particularly right at the end. Fixes markedjs#2280
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
src/rules.js
Outdated
@@ -169,8 +169,8 @@ export const inline = { | |||
lDelim: /^(?:\*+(?:([punct_])|[^\s*]))|^_+(?:([punct*])|([^\s_]))/, | |||
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right. | |||
// () Skip orphan inside strong () Consume to delim (1) #*** (2) a***#, a*** (3) #***a, ***a (4) ***# (5) #***# (6) a***a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also update this comment line by repositioning these labels above their respective sections to help future developers parse the regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
**strong text\\\[**\] | ||
|
||
_em\[pha\]\(sis\)_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have one and three backslashes; could you add an example with 2 backslashes just for completeness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have good intuition! Done, with a supporting bug fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about **strong text\\[**\]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's one of the cases that is not yet handled correctly as of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, ok.
@@ -350,7 +350,8 @@ export class Lexer { | |||
|
|||
// Mask out escaped em & strong delimiters | |||
while ((match = this.tokenizer.rules.inline.escapedEmSt.exec(maskedSrc)) != null) { | |||
maskedSrc = maskedSrc.slice(0, match.index) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex); | |||
maskedSrc = maskedSrc.slice(0, match.index + match[0].length - 2) + '++' + maskedSrc.slice(this.tokenizer.rules.inline.escapedEmSt.lastIndex); | |||
this.tokenizer.rules.inline.escapedEmSt.lastIndex--; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that would require a lot more work trying to make sure we mask out the right characters everywhere. #2628 and this PR are two separate PRs doing two different things. I think we should merge this PR pretty much how it is. If we want to consolidate how things are done after merging this we can.
...particularly right at the end.
Fixes #2280
This resolves the issue at hand, but further improvements will be necessary to bring things fully into alignment with https://spec.commonmark.org/0.30/#emphasis-and-strong-emphasis .
Contributor
Committer
In most cases, this should be a different person than the contributor.