Files
docling-core/tests/data/doc/cdata_when_needed.gt.dclg.xml
Peter W. J. StaarandPanos Vagenas 981489fb2d fix(doclang): preserve hyperlinks in round trip (#1019)
* fix: doclang hyperlink roundtrip

Signed-off-by: Peter Staar <taa@zurich.ibm.com>

* fix the unit-tests

Signed-off-by: Peter Staar <taa@zurich.ibm.com>

* fix(doclang): scope hrefs so unlinked runs stay unlinked

An href applies to all content of its element, so runs inherit a host's
link. The writer therefore puts a link on an element holding runs only when
all its content shares it, and never on a heading, which reads formatted
runs as flat text. Otherwise the item's own text gets a linked <text> and
each run keeps its own href. On read, a host of runs no longer carries the
link too, and a heading's own href no longer splits it into runs.

Also skip linked runs whose content is excluded, and stop the href lookup
at the end of each element head.

Signed-off-by: Panos Vagenas <pva@zurich.ibm.com>

---------

Signed-off-by: Peter Staar <taa@zurich.ibm.com>
Signed-off-by: Panos Vagenas <pva@zurich.ibm.com>
Co-authored-by: Panos Vagenas <pva@zurich.ibm.com>
2026-11-13 13:14:43 +01:00

206 lines
4.7 KiB
XML
Vendored

<doclang>
<list>
<ldiv>
<marker>■</marker>
</ldiv>
item of leading list
</list>
<heading>Title of the Document</heading>
<text><content>Author 1
Affiliation 1</content></text>
<text><content>Author 2
Affiliation 2</content></text>
<heading level="2">1. Introduction</heading>
<text>This paper introduces the biggest invention ever made. ...</text>
<list>
<ldiv>
<marker>■</marker>
</ldiv>
list item 1
<ldiv>
<marker>■</marker>
</ldiv>
list item 2
<ldiv>
<marker>■</marker>
</ldiv>
<text>list item 3</text>
<list class="ordered">
<ldiv/>
list item 3.a
<ldiv/>
list item 3.b
<ldiv/>
<text>list item 3.c</text>
<list class="ordered">
<ldiv/>
list item 3.c.i
</list>
</list>
<ldiv>
<marker>■</marker>
</ldiv>
list item 4
</list>
<table>
<caption>This is the caption of table 1.</caption>
<fcel/>
Product
<fcel/>
Years
<lcel/>
<nl/>
<ucel/>
<fcel/>
2016
<fcel/>
2017
<nl/>
<fcel/>
Apple
<fcel/>
49823
<fcel/>
695944
<nl/>
</table>
<picture>
<caption>This is the caption of figure 1.</caption>
</picture>
<picture>
<caption>This is the caption of figure 2.</caption>
<src uri="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAIklEQVRoge3BAQ0AAADCoPdPbQ8HFAAAAAAAAAAAAAAA8G4wQAAB9qDgAAAAAABJRU5ErkJggg=="/>
</picture>
<list>
<ldiv>
<marker>■</marker>
</ldiv>
item 1 of list
</list>
<list>
<ldiv>
<marker>*</marker>
</ldiv>
item 1 of list after empty list
<ldiv/>
item 2 of list after empty list
</list>
<list>
<ldiv>
<marker>■</marker>
</ldiv>
item 1 of neighboring list
<ldiv>
<marker>■</marker>
</ldiv>
<text>item 2 of neighboring list</text>
<list>
<ldiv>
<marker>□</marker>
</ldiv>
item 1 of sub list
<ldiv>
<marker>□</marker>
</ldiv>
Here a code snippet: <code><label value="Python"/><![CDATA[print("Hello world")]]></code> (to be displayed inline)
<ldiv>
<marker>□</marker>
</ldiv>
Here a formula: <formula>E=mc^2</formula> (to be displayed inline)
</list>
</list>
<text>Here a code block:</text>
<code>
<label value="Python"/>
<![CDATA[print("Hello world")]]>
</code>
<text>Here a formula block:</text>
<formula>E=mc^2</formula>
<text>Some formatting chops: <bold>bold </bold><italic>italic </italic><underline>underline </underline><strikethrough>strikethrough </strikethrough><subscript>subscript </subscript><superscript>superscript </superscript><text><href uri="."/><content>hyperlink </content></text><![CDATA[& ]]><text><href uri="https://github.com/DS4SD/docling"/><strikethrough><underline><italic><bold>everything at the same time.</bold></italic></underline></strikethrough></text></text>
<list class="ordered">
<ldiv>
<marker>(i)</marker>
</ldiv>
Item 1 in A
<ldiv>
<marker>(ii)</marker>
</ldiv>
Item 2 in A
<ldiv>
<marker>(iii)</marker>
</ldiv>
<text>Item 3 in A</text>
<list class="ordered">
<ldiv/>
Item 1 in B
<ldiv>
<marker>42.</marker>
</ldiv>
<text>Item 2 in B</text>
<list class="ordered">
<ldiv/>
Item 1 in C
<ldiv/>
Item 2 in C
</list>
<ldiv/>
Item 3 in B
</list>
<ldiv>
<marker>(iv)</marker>
</ldiv>
Item 4 in A
</list>
<list>
<ldiv/>
List item without parent list group
</list>
<text>The end.</text>
<text>Simple text</text>
<text><content> 4 leading spaces, 1 trailing </content></text>
<text><![CDATA[Some 'single' quotes]]></text>
<text><![CDATA[Some "double" quotes]]></text>
<text>
<summary><![CDATA[Summary with <tags> & ampersands]]></summary>
<![CDATA[An ampersand: &]]>
</text>
<picture>
<description>Description content</description>
</picture>
<code>0 == 0</code>
<code><content> 1 leading space, 4 trailing </content></code>
<code><![CDATA[0 < 1]]></code>
<code>
<label value="Python"/>
42 == 42
</code>
<code>
<label value="Python"/>
<![CDATA[42 < 1337]]>
</code>
<table>
<fcel/>
Foo
<fcel/>
Bar
<nl/>
<fcel/>
<![CDATA[Header & Title]]>
<fcel/>
<![CDATA[Value > 100]]>
<nl/>
<fcel/>
<![CDATA[<script>]]>
<fcel/>
<![CDATA[A & B]]>
<nl/>
<fcel/>
Only
<fcel/>
<![CDATA[<second>]]>
<nl/>
</table>
<text><![CDATA[0 < 1]]></text>
<text><italic><bold><![CDATA[0 < 42]]></bold></italic></text>
</doclang>