Repository navigation
[io] Fix the AsciiDoc export showing escape backslashes and dropping lines - #2238
Open
aad1tyaaaaa wants to merge 2 commits into
Open
aad1tyaaaaa wants to merge 2 commits into
aad1tyaaaaa wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2238 +/- ##
==========================================
- Coverage 98.28% 98.26% -0.02%
==========================================
Files 182 182
Lines 13165 13170 +5
==========================================
+ Hits 12939 12942 +3
- Misses 226 228 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
felixdittrich92
requested changes
Nov 27, 2026
felixdittrich92
left a comment
Collaborator
There was a problem hiding this comment.
Thanks, the character-reference approach checks out when rendered with Asciidoctor (asciidoctor.js 3.0.4):
- 91 of 103 tricky lines now render as the OCR text, against 28 before, and none renders worse.
- On real documents (OCR with layout, tables and font style, about 6,800 words) the stray backslashes are gone.
- It also stops
pass:[...]in OCR text from putting raw HTML into the output, and link hrefs no longer contain backslashes.
A few things before merging:
- Rebase on main:
test_font_style_exportsandtest_font_style_exports_can_be_plain(from #2237) still expect the backslash escapes (\*due\*) and fail once merged. They now get*due*. - E-mail links: an address with
_now becomes a link to the wrong address.jane_doe@example.comis linked asmailto:doe@example.com, because_cuts Asciidoctor's e-mail autolink in two; before, it was plain text.john+tag@example.comwas already split like this. Could you leave e-mail-like words unescaped (Asciidoctor then links the full address), or prefix them with\to keep them as plain text? $: could you add$to_ADOC_SPECIAL_CHARS?$$…$$is still read as an inline passthrough, so the$$disappear and the text inside shows the character references literally (<img).- Nit: only a
'''line is a thematic break, so matching it with a regex such as^'{3,}\s*$, rather than adding'to_ADOC_LINE_MARKERS, would avoid{empty}before lines like'90sor'tis.
…lines
Asciidoctor only honours a backslash escape in a few contexts and keeps
it as literal text everywhere else, so snake_case or C++ rendered with
visible backslashes, while *bold* or H~2~O were still formatted. Write
special characters as numeric character references instead, and also
escape [ and ] so a line like [1] is no longer read as a block attribute
line and dropped.
Prefix lines that start like an ordered list item (1., J., iv)), an
admonition (NOTE:) or a thematic break (''') with {empty}, as is already
done for other block markers.
… break in AsciiDoc
Author
|
Thanks for testing this so thoroughly. Pushed an update:
|
aad1tyaaaaa
force-pushed
the
fix-asciidoc-escaping
branch
from
November 27, 2026 12:56
f54721d to
464186b
Compare
This branch has not been deployed
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.
What
export_as_asciidoc()escapes special characters with a backslash, but Asciidoctor only treats a backslash as an escape in a few contexts and keeps it as literal text everywhere else. Some escapes also don't stop the formatting, and a few kinds of line change meaning or disappear.Rendered with Asciidoctor (asciidoctor.js 3.0.4), comparing the text a reader sees with the OCR text:
snake_case_namesnake\_case\_namesnake\_case\_nameC++C\+\+C+\+#tag\#tag\#tag*important*\*important\**important\*(still bold in some positions)H~2~OH\~2\~O[1]on its own line[1]1. first,J. SmithNOTE: check this'''Fix
escape_textwrites the special characters as numeric character references (_becomes_), which Asciidoctor always renders as the plain character.[and]are added to the set.finalize_linealso prefixes{empty}to lines that start like an ordered list item (1.,a.,iv)), an admonition (NOTE:,TIP:, ...) or a'''break, as it already does for the other block markers.1.5 million,Note: lower caseand2022 was a yearare left alone.Over 36 sample lines, the rendered text now matches the OCR text in 28 cases instead of 5. The rest is out of scope here: typographic replacements (
(C),--,...), e-mail auto-links andTerm::description lists.The trade-off is that the
.adocsource is less readable by eye (snake_case), but it renders as the OCR text.Tests
test_asciidoc_escape_text(8 cases) andtest_asciidoc_finalize_line(10 cases, including the lines that must stay unchanged). The 12 positive cases fail without the fix.tests/common/test_io_exporters.pypasses;ruff check,ruff format --checkandmypy doctr/are clean.AI assistance: I used Claude Code (Claude Opus) to help find this bug, write the fix and tests, and check the rendering with Asciidoctor. I reviewed and ran everything myself.