Skip to content

feat: add opt-in ENRMRKD_TEXT_ESCAPED for backslash escapes - #5

Closed
juliusmarminge wants to merge 1 commit into
software-mansion-labs:masterfrom
pingdotgg:escaped-text
Closed

juliusmarminge wants to merge 1 commit into
software-mansion-labs:masterfrom
pingdotgg:escaped-text

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 27, 2026 •

Copy link
Copy Markdown

What and why

Add the opt-in ENRMRKD_FLAG_ESCAPEDTEXT flag. With it, a backslash-escaped character in normal text is reported as the new ENRMRKD_TEXT_ESCAPED text type instead of ENRMRKD_TEXT_NORMAL. The text is still the character without its backslash, so a renderer that handles both types the same way produces the same output.

Today an application cannot tell \. from . once the text reaches its callback. Enriched Markdown needs that distinction for an opt-in preserveWindowsPaths flag: CommonMark reads C:\Users\me\.config as C:\Users\me.config, and with the flag the application puts the backslash back when the escape sits inside a drive path. Doing this in the parser wrapper keeps the vendored parser byte-identical to this fork through scripts/fetch-md4c.sh, as the review on enriched-markdown#1037 asked of parser changes.

The consumer PR is software-mansion/enriched-markdown#1105. This one needs to merge first.

Behavior

  • Off by default. Without the flag, nothing changes.
  • Only escapes that would otherwise be ENRMRKD_TEXT_NORMAL change type. A backslash before a newline is still a hard break. Code spans, code blocks and raw HTML have no escapes, so they are unaffected. Link destinations and titles are built as attributes and keep their resolved text.
  • md4c-html already renders unknown text types as escaped HTML, so its output is unchanged with the flag on.
  • The flag uses 0x2000000, leaving 0x1000000 for ENRMRKD_FLAG_HTMLBR in feat: add opt-in HTML line break events #3. md2html gets --fescaped-text as -Q, since -E and -J are taken.

Validation

  • test/spec-escaped-text.txt runs through the existing scripts/run-tests.py with --fescaped-text: path-like escapes, ordinary escapes, code spans, link destinations and titles, and backslash hard breaks render exactly as without the flag.
  • The full runner passes: all spec files and the 31 pathological cases.
  • The consumer PR's golden AST test shows the new type reaching the wrapper: C:\Users\me\.t3 keeps its backslashes when its flag is on and parses as CommonMark when it is off.

Model: Claude Opus 5.5. Harness: Claude Code in T3 Code.

ENRMRKD_FLAG_ESCAPEDTEXT reports a backslash-escaped character in normal
text as ENRMRKD_TEXT_ESCAPED, so an application can tell an escape from
the literal character.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@juliusmarminge

Copy link
Copy Markdown
Author

Closing in favour of mity#477, which adds the same opt-in upstream (MD_FLAG_ESCAPEDTEXT reporting MD_TEXT_ESCAPED). Once it's vendored here, software-mansion/enriched-markdown#1105 builds on it with no local parser change.

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