Skip to content

Allow info string of fenced code to start with the other fence character - #464

Open
ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-fence-info-with-other-fence-char
Open

ybai08 wants to merge 1 commit into
commonmark:mainfrom
ybai08:fix-fence-info-with-other-fence-char

Conversation

@ybai08

@ybai08 ybai08 commented Oct 18, 2026

Copy link
Copy Markdown

An opening fence followed directly by the other fence character wasn't recognized, so these became paragraphs:

```~/.bashrc
code
```
~~~`info`
code
~~~

checkOpener counted all backticks and tildes at the start of the line together and gave up when both were present. Only the run of the first character is the fence, and the info string can contain the other character (backtick fences only disallow backticks in the info string), so it now counts just that run. ~ `` is still not a fence (backtickAndTildeCantBeMixed` passes unchanged).

cmark and commonmark.js both parse the two examples above as code blocks with info strings ~/.bashrc and `info`.

Tests added in FencedCodeBlockParserTest, both fail without the change. mvn test (all modules) and mvn spotless:check pass.

An opening fence like "```~/.bashrc" or "~~~`info`" was not recognized,
because backticks and tildes after the first character were counted as
part of the fence. The fence is only the run of the first character, so
the info string can start directly after it with the other character.

This branch has not been deployed

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

1 participant