Skip to content

Add MD_FLAG_ESCAPEDTEXT to report backslash-escaped characters - #477

Open
hryhoriiK97 wants to merge 1 commit into
mity:masterfrom
hryhoriiK97:escaped-text
Open

hryhoriiK97 wants to merge 1 commit into
mity:masterfrom
hryhoriiK97:escaped-text

Conversation

@hryhoriiK97

@hryhoriiK97 hryhoriiK97 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Adds an opt-in MD_FLAG_ESCAPEDTEXT. With it, a backslash-escaped character in normal text is reported as the new MD_TEXT_ESCAPED instead of MD_TEXT_NORMAL. The text is still the character without its backslash, so a renderer that treats both types alike produces the same output, and md4c-html needs no change.

Why

Once text reaches the callback, an application can't tell \. from .. We hit this in react-native-enriched-markdown, which renders output from coding agents, where Windows paths in prose are common. C:\Users\me\.config renders as C:\Users\me.config. That is correct CommonMark, but the application may know from context that the backslash was a separator and want to keep it.

That decision belongs in the application, so this only exposes what the parser already knows. Syntax and spec behaviour don't change.

Flag bits and an alternative

I know flag bits are scarce (your comment on #429). Today an application can get the same answer without any parser change: an escaped character arrives as one byte pointing into the input, so it can count the backslashes right before that pointer. I tested this against the flag and they agreed on every escape, but it relies on behaviour the API doesn't document.

If you'd rather not spend a bit on this, documenting that guarantee in md4c.h would work for us too.

Testing

Adds test/spec-escaped-text.txt. The full suite passes, also under ASan and UBSan, and HTML output is identical with and without the flag across the spec files.

@codecov

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.32%. Comparing base (f9e5eb2) to head (c039cdd).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #477      +/-   ##
==========================================
+ Coverage   79.30%   79.32%   +0.02%     
==========================================
  Files           5        5              
  Lines        3929     3933       +4     
  Branches     1311     1312       +1     
==========================================
+ Hits         3116     3120       +4     
  Misses        295      295              
  Partials      518      518              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

With the flag, a backslash-escaped character in normal text is reported as
the new MD_TEXT_ESCAPED instead of MD_TEXT_NORMAL. The text is still the
character without its backslash, so the HTML output does not change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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