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

fix: Support escapes within emphasis #2627

Merged
merged 5 commits into from Nov 2, 2022

Conversation

gibson042
Copy link
Contributor

...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

  • Test(s) exist to ensure functionality and minimize regression (if no tests added, list tests covering this PR); or,
  • no tests required for this PR.
  • If submitting new feature, it has been documented in the appropriate places.

Committer

In most cases, this should be a different person than the contributor.

...particularly right at the end.

Fixes markedjs#2280
@vercel
Copy link

vercel bot commented Oct 27, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
marked-website ✅ Ready (Inspect) Visit Preview Nov 1, 2022 at 5:22AM (UTC)

Copy link
Member

@UziTech UziTech left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

test/unit/Lexer-spec.js Show resolved Hide resolved

**strong text\\\[**\]

_em\[pha\]\(sis\)_
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about **strong text\\[**\]

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, ok.

src/rules.js Outdated Show resolved Hide resolved
@@ -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--;
Copy link
Contributor

Choose a reason for hiding this comment

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

@UziTech Similar to my comment on #2628, would this whole PR (and #2628) be cleaner if we just pre-masked out all escaped characters (not just * and _)? Rather than each tokenizer trying to handle escaped characters in its own way?

Copy link
Member

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.

@UziTech UziTech merged commit 377823a into markedjs:master Nov 2, 2022
github-actions bot pushed a commit that referenced this pull request Nov 2, 2022
## [4.2.1](v4.2.0...v4.2.1) (2022-11-02)

### Bug Fixes

* Support escapes within emphasis ([#2627](#2627)) ([377823a](377823a)), closes [#2280](#2280)
@calculuschild calculuschild mentioned this pull request Jun 5, 2023
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Broken "Strong" transform
3 participants