Skip to content

Even-numbered backtick strings have incorrect precedence with at least emStrong and link delimiters #3776

@elliott-with-the-longest-name-on-github

Description

Marked version:

16.3.0

Describe the bug

Possibly related to #1663?

There are some weird edge cases around backtick parsing. Take the following string:

**You might think this should be bold, but it should actually be regular text because codespans have higher priority: ``**``

This should turn the closing ** into a codespan, but it doesn't. Weirdly enough, it will work when the backtick strings have an odd number of backticks, eg. 1 or 3, but will flip back to not working for any even number of backticks.

To Reproduce
Steps to reproduce the behavior:

  1. marked
  2. CommonMark

I have also observed this behavior with link parsing. The following string parses correctly in CommonMark but not in Marked:

[this``should be parsed as text/codespan/text](https://github``.com)

It exhibits the same "okay with an odd number, not okay with an even number" behavior.

Expected behavior

Given the precedence codespan markers have over everything inline other than autolinks and HTML, these should parse as text and codespan elements, not text/strong or link.

Metadata

Metadata

Assignees

No one assigned

    Labels

    L2 - annoyingSimilar to L1 - broken but there is a known workaround available for the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions