Skip to content

fix(html): turn inline SVG into a PictureItem with title caption - #5673

Open
er-s-an wants to merge 7 commits into
docling-project:mainfrom
er-s-an:fix/html-inline-svg-picture
Open

er-s-an wants to merge 7 commits into
docling-project:mainfrom
er-s-an:fix/html-inline-svg-picture

Conversation

@er-s-an

@er-s-an er-s-an commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

The HTML backend had no handling for an inline <svg>. Its <title> was merged into the surrounding body text, and no picture was created. This is the SVG half of the contract on #4766.

After this change:

  • <svg> becomes a PictureItem, the same way <img> does
  • <title> is the caption (a <figcaption> still wins when the SVG is in a figure)
  • <desc> is stored as PictureMeta.description
  • decorative SVG is skipped: aria-hidden="true", role="presentation", role="none"
  • an SVG <title> is no longer used as the HTML document title

Covered in paragraphs, list items, table cells, and a list item that holds only an SVG. <video> / <audio> (TrackItem after #4752) is left for a follow-up, once a maintainer confirms that direction on #4766.

Checklist:

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

Review evidence:

Before, the #4766 repro printed body text Before Icon after and created no picture for the SVG. After, the paragraph text is Before after (same spacing as an inline <img>), one PictureItem is created with caption Icon, and <desc> lands in picture.meta.description. Decorative SVG is omitted and does not leak its title.

uv run pytest tests/test_backend_html.py: 184 passed, 1 skipped, including 9 new SVG cases. No reference documents were regenerated.

The HTML backend ignored <svg>, so its <title> leaked into body text and
no picture was created. Emit a PictureItem the way <img> is handled:
<title> becomes the caption, <desc> is stored as a description, and
decorative SVG (aria-hidden, role=presentation/none) is skipped.

soup.title also picked up an SVG title as the document title; only a
non-SVG <title> is used for that now.

<video>/<audio> TrackItem handling is left for a follow-up, after a
maintainer confirms the contract in docling-project#4766.

Signed-off-by: er-s-an <92594860+er-s-an@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @er-s-an, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Nov 29, 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 ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working html issue related to html backend priority:medium labels Nov 29, 2026
@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

AI triage (advisory)

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

The HTML backend now turns an inline <svg> into a PictureItem. The <title> becomes the caption and <desc> becomes PictureMeta.description. Decorative SVG is skipped, and an SVG <title> no longer sets the document title.

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

3 related pull request(s) in the same code
PR State Signal Assessment
#4900 open changes the same code related: It edits the same backend file, but it changes the numbering of ordered list markers. It does not handle SVG.
#5707 open changes the same code related: It edits convert() in the same backend file, but it adds opt-in JSON-LD extraction. It does not handle SVG.
#4752 merged referenced as #4752 related: It is merged and adds tracks for audio and video in other backends. It has no HTML or SVG change. This PR only names it as a follow-up for <video> and <audio>.

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 87def67c60. It read the code and did not run it.

The change drops all visible text inside an inline <svg> (for example <text> labels in charts). It keeps only <title> and <desc>. The PR description does not say this, and no test covers it. The reviewer must decide whether this loss is accepted for all HTML inputs.

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

tag = cast(Tag, item)
if self._is_suppressed_tag(tag):
return AnnotatedTextList()
if tag.name == "svg":

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.

question: Visible <text> content of an inline SVG is dropped without a replacement

_extract_text_and_hyperlink_recursively now returns an empty list for every <svg>. Before this change, the text of <text>, <tspan>, and similar children was part of the body text. Now only <title> and <desc> are read, in _svg_child_text and _emit_svg. The PR emits no <text> content anywhere, and the code comment says it "belongs to the picture".

Example: <p>Revenue <svg><text x="0" y="10">Q1: 40%</text></svg></p> loses Q1: 40%. The result is a captionless picture. Charts and diagrams with SVG labels hit this case. A bare <svg> icon with no <title> also becomes an empty PictureItem for every user.

The PR text and the 9 new tests cover neither case. Please state whether this loss of <text> content is accepted. If it is not, keep the text in a form such as PictureMeta.description, or as body text when no <title> exists. Add a test for an SVG that has <text> and no <title>.

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

codecov Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.40909% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
docling/backend/html_backend.py 78.40% 7 Missing and 12 partials ⚠️

📢 Thoughts on this report? Let us know!

@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
3 tasks done
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Nov 30, 2026

@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 changes since 87def67c60 at 85909129ce. It read the code and did not run it.

The incremental diff only merges unrelated changes from the base branch: VLM, CLI, and a CHANGELOG entry. It does not touch docling/backend/html_backend.py or tests/test_backend_html.py. The earlier open question stays open: the author has not said whether the loss of SVG <text> content is accepted.

Earlier findings

  • open (question): Visible <text> content of an inline SVG is dropped without a replacement

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

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) labels Dec 1, 2026
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Dec 2, 2026
…icture

Signed-off-by: er-s-an <92594860+er-s-an@users.noreply.github.com>
@github-actions github-actions Bot removed the ai:ci-safe AI triage found no CI-safety concern (advisory) label Dec 2, 2026
@github-actions github-actions Bot added the ai:ci-safe AI triage found no CI-safety concern (advisory) label Dec 2, 2026
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Dec 4, 2026
@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) and removed ai:ci-safe AI triage found no CI-safety concern (advisory) labels Dec 4, 2026

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) bug Something isn't working html issue related to html backend priority:medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant