Skip to content

fix(asciidoc): read superscript and subscript marks in paragraphs - #5787

Open
Aryapatel-007 wants to merge 1 commit into
docling-project:mainfrom
Aryapatel-007:fix-asciidoc-superscript-subscript
Open

Aryapatel-007 wants to merge 1 commit into
docling-project:mainfrom
Aryapatel-007:fix-asciidoc-superscript-subscript

Conversation

@Aryapatel-007

Copy link
Copy Markdown

The AsciiDoc backend kept superscript (^2^) and subscript (~2~) marks in the text. This PR reads them as Formatting.script, like the HTML, DOCX and ODT backends do, and like #4824 did for bold, italic and monospace.

The rule follows Asciidoctor:

  • The marks are unconstrained, so they also work inside a word: H~2~O, E=mc^2^.
  • The marked text has no whitespace, so x^2 + y^2 and ~/.bashrc and ~/x stay plain.
  • They nest with bold and italic: **bold^sup^** and ^*x*^.
  • A backslash before the mark keeps it as text (\^not^).

Math macros (stem:[...], latexmath:[...], asciimath:[...]) are now kept as written. Their ^ and ~ belong to the formula, and Asciidoctor formats nothing inside them. Without this, a corpus check (below) showed stem:[sum_(i=1)^n i^3=...] losing its carets. A side effect: bold and italic marks inside a math macro are also left alone now. Before, stem:[a *b* c] made b bold.

_parse_inline now has five parameters, so the flags after text are keyword-only.

Issue resolved by this Pull Request:
Resolves #5786

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

Review evidence:

Input Before After
Water is H~2~O and E=mc^2^. one text item with the marks inline group: 2 (sub), 2 (super)
HTML export of the same H~2~O and E=mc^2^ H<sub>2</sub>O and E=mc<sup>2</sup>
**bold^sup^**, ^*x*^ literal marks sup bold and super, x bold and super
x^2 + y^2, ~/.bashrc and ~/x plain plain (unchanged)
stem:[sum_(i=1)^n i^3=((n(n+1))/2)^2] plain plain (unchanged)
paragraph without marks one text item one text item (unchanged)
  • Added test_superscript_and_subscript_in_paragraphs. It fails on main (a0bd0155) and passes with this change.
  • pytest tests/test_backend_asciidoc.py: 95 passed. The AsciiDoc reference outputs did not change.
  • pytest tests/test_backend_text_encoding.py tests/test_input_doc.py: 136 passed, 12 failed. The same 12 fail on main in my environment, all with "The 'docling-parse' package is required", because I did not install the PDF parser.
  • ruff format --check, ruff check (0.17.2), tach check: clean. ty check (0.0.33) on the backend: no new warnings (4 on main, 4 here).
  • Corpus check: I converted 874 .adoc files from the Asciidoctor, Asciidoctor PDF, AsciidoctorJ, Asciidoctor Diagram, Gradle and Maven plugin repos and asciidoctor.org, on main and on this branch, and compared the text items, their formatting and the Markdown. One file changes: asciidoctor.org/news/docker-asciidoctorj-announcement.adoc, where the footnote markers ^*^ become a superscript *, as Asciidoctor renders them. No conversion fails.
  • Speed: the new patterns scan in linear time. A 200,000-character line of ^a pairs converts in about 2.6 s (it makes 100,000 items) and the regular expression alone takes 0.03 s. Unclosed marks scan in linear time too.

Known output details, not from this change:

  • The Markdown export has no syntax for superscript and subscript, so it prints H2O and mc2, the same as for <sub> and <sup> from the HTML backend.
  • In the changed file above, a paragraph that starts with ^*^ now exports to Markdown as * For now, ..., which a Markdown reader takes as a list item. The serializer does not escape a leading * (docling-core#61).
  • Superscript and subscript in list items, headings and table cells are not read, as for bold and italic (AsciiDoc: links and inline marks in list items are kept as literal markup #5434 covers list items).

I used Claude Code to help with this change.

^text^ and ~text~ stayed in the text as literal marks. They now set
Formatting.script, as in the HTML, DOCX and ODT backends. As in
Asciidoctor, the marks also work inside a word (H~2~O, E=mc^2^), but the
marked text has no whitespace, so x^2 + y^2 stays plain.

Math macros (stem:[...], latexmath:[...], asciimath:[...]) are kept as
written, because their ^ and ~ belong to the formula.

Resolves docling-project#5786

Signed-off-by: Arya Patel <aryapatel7899@gmail.com>
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @Aryapatel-007, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added asciidoc issue related to asciidoc backend bug Something isn't working labels Dec 6, 2026
@github-actions

github-actions Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit b7a3dc28bd. The analysis read the diff only. It did not run code from this pull request.

Warning

The AI analysis did not finish. Only the deterministic checks are shown.

Topic labels added: bug, asciidoc.

CI safety: not assessed.

Possibly related pull requests

PR State Signal Assessment
#5435 open also references issue #5434 not assessed
#4824 merged referenced as #4824 not assessed

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asciidoc issue related to asciidoc backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsciiDoc: superscript (^x^) and subscript (~x~) marks stay in the text

1 participant