#4423·docling

HTML backend: `orig` does not keep the source text of paragraphs and inline text

Author: morten-lagaboteCreated Sep 28, 2026Updated Sep 28, 2026

Bug

The HTML backend sanitizes the text with HTMLDocumentBackend._clean_unicode (#2004, #2006): dashes, curly quotes and the ellipsis are replaced with ASCII characters, and invisible characters are removed. As proposed in #2004, the sanitized text goes to text and the source text is kept in orig (in TextItem, orig is the "untreated representation").

Headings, titles, captions and simple list items keep the source text in orig. Paragraphs, inline text, the parts of rich list items and code blocks do not: their orig is the sanitized text as well, so the source text is lost.

Input:

xml
<h2>See §§ 3–5</h2>
<p>See §§ 3–5 and “quoted” text … it’s kept.</p>

Actual (label: text | orig):

section_header: See §§ 3-5 | See §§ 3–5
text: See §§ 3-5 and "quoted" text ... it's kept. | See §§ 3-5 and "quoted" text ... it's kept.

Expected: orig keeps the source text, as for the heading:

section_header: See §§ 3-5 | See §§ 3–5
text: See §§ 3-5 and "quoted" text ... it's kept. | See §§ 3–5 and “quoted” text … it’s kept.

This is also visible in the ground truth of wiki_duck.html: the page ranges in the references (e.g. pp. 737–738) have a hyphen in orig. In a published page, https://lovdata.no/nav/rundskriv/r11-00, orig keeps 198 of the 385 en dashes of the source.

Steps to reproduce

python
from io import BytesIO

from docling.datamodel.base_models import DocumentStream, InputFormat
from docling.document_converter import DocumentConverter

html = """<!DOCTYPE html><html><head><meta charset="utf-8"></head><body>
<h2>See §§ 3–5</h2>
<p>See §§ 3–5 and “quoted” text … it’s kept.</p>
</body></html>"""

converter = DocumentConverter(allowed_formats=[InputFormat.HTML])
document = converter.convert(DocumentStream(name="punctuation.html", stream=BytesIO(html.encode()))).document
for item, _ in document.iterate_items():
    print(f"{item.label.value}: {item.text} | {item.orig}")

Docling version

2.130.0 (also reproduced with 2.124.0); docling-core 2.99.0; beautifulsoup4 4.15.0

Python version

Python 3.13.9