Skip to content

Commit

Permalink
Don't escape = text if it's the first node in a block
Browse files Browse the repository at this point in the history
Fixes #335
  • Loading branch information
robinst committed Sep 12, 2024
1 parent e3795b2 commit 26d4df9
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 @@ -366,9 +366,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 @@ -189,6 +189,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 26d4df9

Please sign in to comment.