Skip to content

Commit

Permalink
Merge pull request #338 from commonmark/issue-335-md-escaping-equals
Browse files Browse the repository at this point in the history
Don't escape `=` text if it's the first node in a block
  • Loading branch information
robinst authored Sep 14, 2024
2 parents 3785185 + 26d4df9 commit db57101
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,11 @@ public void visit(Text text) {
break;
}
case '=': {
// Would be ambiguous with a Setext heading, escape
writer.raw("\\=");
literal = literal.substring(1);
// Would be ambiguous with a Setext heading, escape unless it's the first line in the block
if (text.getPrevious() != null) {
writer.raw("\\=");
literal = literal.substring(1);
}
break;
}
case '0':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public void testEscaping() {
assertRoundTrip("\\## Test\n");
assertRoundTrip("\\#\n");
assertRoundTrip("Foo\n\\===\n");
// Only needs to be escaped after some text, not at beginning of paragraph
assertRoundTrip("===\n");
assertRoundTrip("a\n\n===\n");
// The beginning of the line within the block, so disregarding prefixes
assertRoundTrip("> \\- Test\n");
assertRoundTrip("- \\- Test\n");
Expand Down

0 comments on commit db57101

Please sign in to comment.