Skip to content

Commit c3bd521

Browse files
authored
Merge pull request #459 from TanbirRamim/code-span-after-unclosed-backticks
Fix code spans after an unclosed backtick string
2 parents 73d76d0 + 3b3292c commit c3bd521

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎commonmark/src/main/java/org/commonmark/internal/inline/BackticksInlineParser.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,12 @@ public ParsedInline tryParse(InlineParserState inlineParserState) {
3838
while (scanner.find('`') > 0) {
3939
var beforeClosing = scanner.position();
4040
var length = scanner.matchMultiple('`');
41-
// Keep track of last position of backticks run of this length
42-
backtickPositions.put(length, beforeClosing);
41+
// Keep track of last position of backticks run of this length. Once the whole input
42+
// has been scanned, the map already holds the last positions, so don't overwrite them
43+
// with earlier ones.
44+
if (!scannedToEnd) {
45+
backtickPositions.put(length, beforeClosing);
46+
}
4347
if (length == openingLength) {
4448
Code node = new Code();
4549

‎commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,4 +456,11 @@ public void emphasisAfterHardLineBreak() {
456456
Foo</p>
457457
""");
458458
}
459+
460+
@Test
461+
public void codeSpansAfterUnclosedBackticks() {
462+
assertRendering("`` `a` `c`", "<p>`` <code>a</code> <code>c</code></p>\n");
463+
assertRendering(
464+
"`` `a` `c` `e`", "<p>`` <code>a</code> <code>c</code> <code>e</code></p>\n");
465+
}
459466
}

0 commit comments

Comments
 (0)