FIX: Always escape setext heading underlines - #82
Merged
Conversation
ZogStriP
approved these changes
Sep 3, 2026
A text line that contains only `=` was escaped only when the escaper
saw a paragraph line directly in front of it in the same text node.
For the first line of a fragment it assumed there was no paragraph
line before it.
That assumption does not hold. The escaper works on one text fragment
at a time and the renderer joins the fragments afterwards, so a
fragment starting with `===` can end up right after a paragraph line:
`Text("Body") LineBreak Text("===")` renders as `Body\n===`, and so
does `[b]Body[/b]\n===`. Discourse cooks both as an `<h1>`.
Every other block construct is escaped without looking at the
surrounding lines. The setext rule was the only exception, so this
drops the paragraph tracking (`prev_was_paragraph`, `paragraph_line?`,
`block_construct?`) and escapes a `=`-only line in every position.
The `-` half of the guard was already dead code: a line with a single
dash is caught by the bullet list rule, two dashes by the ndash pair
in `escape_inline`, and three or more by the thematic break rule. The
`SETEXT_UNDERLINE_DASH` regex is gone with it.
The cost is cosmetic. I checked the over-escaped output in a Discourse
instance: `\=` renders as a literal `=` at paragraph start, after a
blank line, in list items and in blockquotes.
gschlager
force-pushed
the
escape-setext-underlines-always
branch
from
September 3, 2026 17:55
040aa49 to
2e8758b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This replaces #81. Threading an
after_line_breakflag throughRenderContext, the renderer and both escapers fixed only the<br>case. A plain newline after inline markup like[b]Body[/b]\n===still cooked as a heading, so I fixed the root cause instead.The escaper only sees one text fragment and assumed the first line never follows a paragraph line. The renderer joins fragments afterwards, so that is often wrong. Every other block construct is already escaped without looking at surrounding lines. Now
=-only lines are too.prev_was_paragraph,paragraph_line?,block_construct?,SETEXT_UNDERLINE_DASH), about 60 lines.-half of that guard was already dead: single dashes hit the bullet rule,--the ndash rule,---the thematic break rule.\=renders as a literal=everywhere, so the only cost is\=\=\=\=in the raw Markdown.Supersedes #81.