Skip to content

fix(html): read code language from Sphinx highlighting wrappers - #5701

Open
XuanTuWang wants to merge 1 commit into
docling-project:mainfrom
XuanTuWang:fix/html-sphinx-code-language
Open

XuanTuWang wants to merge 1 commit into
docling-project:mainfrom
XuanTuWang:fix/html-sphinx-code-language

Conversation

@XuanTuWang

@XuanTuWang XuanTuWang commented Dec 1, 2026 •

Copy link
Copy Markdown

Sphinx puts the lexer for a code block on an outer div, for example div.highlight-python3 > div.highlight > pre. Read that hint when the block itself has no recognized language. Keep explicit hints on pre and code first. Leave unsupported lexers such as shell-session as unknown.

Issue resolved by this Pull Request:
Resolves #5700

Checklist:

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

Review evidence:

  • The tracking issue contains a runnable example.
  • Ran the four new HTML conversion cases on the unmodified base. The Python wrapper case returned unknown and failed. The other three passed. After the fix, all four passed. They check the code text and language, including an explicit inner Bash hint, an unsupported lexer, and an unrelated wrapper.
  • In a document with paragraphs before and after the code, all three items stayed under the body in source order. The JSON export had code_language: Python. The Markdown export used a python fence and the HTML export used language-python.
  • Converted the same snapshot of the Python JSON documentation before and after. Of 15 source blocks, 11 could be matched one-to-one by exact code text on both versions. For those 11, nine Python examples changed from unknown to Python. The two shell transcripts stayed unknown.
  • python -m pytest -q tests/test_code_language_detection.py tests/test_backend_html.py -k 'sphinx_code_language or preformatted or code_language' passed all 78 selected cases. Also ran both test files in full with the locked docling-core version (2.108.0): 237 passed and one optional Playwright test was skipped because Playwright was not installed. make validate and git diff --check passed. No reference files changed. The full repository test suite was not run locally.

Prepared and tested with OpenAI Codex assistance.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @XuanTuWang, all your commits are properly signed off. 🎉

Signed-off-by: XuanTuWang <147527217+XuanTuWang@users.noreply.github.com>
@XuanTuWang
XuanTuWang force-pushed the fix/html-sphinx-code-language branch from e9149eb to 2eecbfb Compare December 1, 2026 13:35
@mergify

mergify Bot commented Dec 1, 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)(?:\(.+\))?(!)?:

@XuanTuWang
XuanTuWang marked this pull request as ready for review December 1, 2026 13:35
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working html issue related to html backend priority:low labels Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The HTML backend now reads the code language from Sphinx div.highlight-<lexer> wrappers when pre and code have no recognized language. A test and a docs note go with the change.

Topic labels added: bug, html, priority:low.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#5536 open changes the same code related: It adds a MediaWiki backend and some HTML fixes for math spans, figure captions, and definition lists. It touches the same files but does not change code language detection.

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

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI first review (advisory): no blocker found

This review covers the full diff at 2eecbfbf7c. It read the code and did not run it.

No merge-deciding defect found. The new Sphinx wrapper lookup in _code_language_hint runs only after the explicit pre and code hints fail. It also runs only when the structure is div.highlight-<lexer> > div.highlight > pre, so other inputs keep their old result.

A maintainer makes the merge decision. This review never approves the pull request.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Dec 1, 2026
@codecov

codecov Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working html issue related to html backend priority:low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTML: Sphinx code blocks lose the language specified on their wrapper

1 participant