Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
451 changes: 451 additions & 0 deletions docling_core/transforms/serializer/common.py

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion docling_core/transforms/serializer/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
CommonParams,
DocSerializer,
_get_annotation_text,
_join_inline_parts,
_should_use_legacy_annotations,
create_ser_result,
)
Expand Down Expand Up @@ -892,7 +893,7 @@ def serialize(
)

# Join all parts without separators
inline_html = " ".join([p.text for p in parts if p.text])
inline_html = _join_inline_parts(parts)

# Wrap in span if needed
if inline_html:
Expand Down
3 changes: 2 additions & 1 deletion docling_core/transforms/serializer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
CommonParams,
DocSerializer,
_get_annotation_text,
_join_inline_parts,
_should_use_legacy_annotations,
create_ser_result,
)
Expand Down Expand Up @@ -806,7 +807,7 @@ def serialize(
visited=my_visited,
**kwargs,
)
text_res = " ".join([p.text for p in parts if p.text])
text_res = _join_inline_parts(parts)
return create_ser_result(text=text_res, span_source=parts)


Expand Down
2 changes: 1 addition & 1 deletion test/data/doc/2408.09869v3_enriched_p2_p3_p5.gt.html
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
<li style="list-style-type: '· ';">Can leverage different accelerators (GPU, MPS, etc).</li>
</ul>
<h2>2 Getting Started</h2>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a> . All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a>. All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<p>Docling provides an easy code interface to convert PDF documents from file system, URLs or binary streams, and retrieve the output in either JSON or Markdown format. For convenience, separate methods are offered to convert single documents or batches of documents. A basic usage example is illustrated below. Further examples are available in the Doclign code repository.</p>
<pre><code>from docling.document_converter import DocumentConverter Large</code></pre>
<pre><code>source = "https://arxiv.org/pdf/2206.01062" # PDF path or URL converter = DocumentConverter() result = converter.convert_single(source) print(result.render_as_markdown()) # output: "## DocLayNet: A Human -Annotated Dataset for Document -Layout Analysis [...]"</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion test/data/doc/2408.09869v3_enriched_split.gt.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h2>1 Introduction</h2>
<li style="list-style-type: '· ';">Can leverage different accelerators (GPU, MPS, etc).</li>
</ul>
<h2>2 Getting Started</h2>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a> . All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a>. All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<p>Docling provides an easy code interface to convert PDF documents from file system, URLs or binary streams, and retrieve the output in either JSON or Markdown format. For convenience, separate methods are offered to convert single documents or batches of documents. A basic usage example is illustrated below. Further examples are available in the Doclign code repository.</p>
<pre><code>from docling.document_converter import DocumentConverter Large</code></pre>
<pre><code>source = "https://arxiv.org/pdf/2206.01062" # PDF path or URL converter = DocumentConverter() result = converter.convert_single(source) print(result.render_as_markdown()) # output: "## DocLayNet: A Human -Annotated Dataset for Document -Layout Analysis [...]"</code></pre>
Expand Down
2 changes: 1 addition & 1 deletion test/data/doc/2408.09869v3_enriched_split_p2.gt.html
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
<li style="list-style-type: '· ';">Can leverage different accelerators (GPU, MPS, etc).</li>
</ul>
<h2>2 Getting Started</h2>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a> . All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<span class='inline-group'>To use Docling, you can simply install the docling package from PyPI. Documentation and examples are available in our GitHub repository at <a href="https://github.com/DS4SD/docling">github.com/DS4SD/docling</a>. All required model assets 1 are downloaded to a local huggingface datasets cache on first use, unless you choose to pre-install the model assets in advance.</span>
<p>Docling provides an easy code interface to convert PDF documents from file system, URLs or binary streams, and retrieve the output in either JSON or Markdown format. For convenience, separate methods are offered to convert single documents or batches of documents. A basic usage example is illustrated below. Further examples are available in the Doclign code repository.</p>
<pre><code>from docling.document_converter import DocumentConverter Large</code></pre>
<pre><code>source = "https://arxiv.org/pdf/2206.01062" # PDF path or URL converter = DocumentConverter() result = converter.convert_single(source) print(result.render_as_markdown()) # output: "## DocLayNet: A Human -Annotated Dataset for Document -Layout Analysis [...]"</code></pre>
Expand Down
12 changes: 6 additions & 6 deletions test/data/doc/inline_and_formatting.gt.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,20 @@
<div class='page'>
<h1>Contribution guideline example</h1>
<p>This is simple.</p>
<span class='inline-group'>Foo <em>emphasis</em> <strong>strong emphasis</strong> <em><strong>both</strong></em> .</span>
<span class='inline-group'>Create your feature branch: <code>git checkout -b feature/AmazingFeature</code> .</span>
<span class='inline-group'>Foo <em>emphasis</em> <strong>strong emphasis</strong> <em><strong>both</strong></em>.</span>
<span class='inline-group'>Create your feature branch: <code>git checkout -b feature/AmazingFeature</code>.</span>
<ol>
<li style="list-style-type: '1. ';">
<span class='inline-group'>Pull the <a href="https://github.com/docling-project/docling"><strong>repository</strong></a> .</span>
<span class='inline-group'>Pull the <a href="https://github.com/docling-project/docling"><strong>repository</strong></a>.</span>
</li>
<li style="list-style-type: '2. ';">
<span class='inline-group'>Create your feature branch ( <code>git checkout -b feature/AmazingFeature</code> )</span>
<span class='inline-group'>Create your feature branch (<code>git checkout -b feature/AmazingFeature</code>)</span>
</li>
<li style="list-style-type: '3. ';">
<span class='inline-group'>Commit your changes ( <code>git commit -m 'Add some AmazingFeature'</code> )</span>
<span class='inline-group'>Commit your changes (<code>git commit -m 'Add some AmazingFeature'</code>)</span>
</li>
<li style="list-style-type: '4. ';">
<span class='inline-group'>Push to the branch ( <code>git push origin feature/AmazingFeature</code> )</span>
<span class='inline-group'>Push to the branch (<code>git push origin feature/AmazingFeature</code>)</span>
</li>
<li style="list-style-type: '5. ';">Open a Pull Request</li>
<li style="list-style-type: '6. ';"><strong>Whole list item has same formatting</strong></li>
Expand Down
12 changes: 6 additions & 6 deletions test/data/doc/inline_and_formatting.gt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

This is simple.

Foo *emphasis* **strong emphasis** ***both*** .
Foo *emphasis* **strong emphasis** ***both***.

Create your feature branch: `git checkout -b feature/AmazingFeature` .
Create your feature branch: `git checkout -b feature/AmazingFeature`.

1. Pull the [**repository**](https://github.com/docling-project/docling) .
2. Create your feature branch ( `git checkout -b feature/AmazingFeature` )
3. Commit your changes ( `git commit -m 'Add some AmazingFeature'` )
4. Push to the branch ( `git push origin feature/AmazingFeature` )
1. Pull the [**repository**](https://github.com/docling-project/docling).
2. Create your feature branch (`git checkout -b feature/AmazingFeature`)
3. Commit your changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request
6. **Whole list item has same formatting**
7. List item has *mixed or partial* formatting
Expand Down
30 changes: 15 additions & 15 deletions test/data/doc/polymers.gt.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@ <h2>Safety and Regulatory Considerations</h2>
<span class='inline-group'><strong>Extraction in food simulants</strong></span>
<ul>
<li>
<span class='inline-group'><em>What it is</em> : Samples of the packaging material are immersed in a liquid that mimics the chemical properties of a specific food type (e.g., aqueous, acidic, fatty).</span>
<span class='inline-group'><em>What it is</em>: Samples of the packaging material are immersed in a liquid that mimics the chemical properties of a specific food type (e.g., aqueous, acidic, fatty).</span>
</li>
<li>
<span class='inline-group'><em>Typical simulants</em> :</span>
<span class='inline-group'><em>Typical simulants</em>:</span>
<ul>
<li>3% acetic acid (for acidic foods)</li>
<li>50% ethanol (for alcohol‑based foods)</li>
Expand All @@ -249,32 +249,32 @@ <h2>Safety and Regulatory Considerations</h2>
</ul>
</li>
<li>
<span class='inline-group'><em>Procedure</em> :</span>
<span class='inline-group'><em>Procedure</em>:</span>
<ul>
<li>Prepare a defined volume of simulant in a sealed vessel.</li>
<li>Immerse the material for a set time at a controlled temperature (often 50 °C–70 °C).</li>
<li>Remove, filter, and concentrate the extract for analysis.</li>
</ul>
</li>
<li>
<span class='inline-group'><em>Analysis</em> : GC‑MS, LC‑MS, or HPLC depending on the analyte class.</span>
<span class='inline-group'><em>Analysis</em>: GC‑MS, LC‑MS, or HPLC depending on the analyte class.</span>
</li>
<li>
<span class='inline-group'><em>Advantages</em> : Direct assessment of potential migration into a realistic medium; scalable for routine testing.</span>
<span class='inline-group'><em>Advantages</em>: Direct assessment of potential migration into a realistic medium; scalable for routine testing.</span>
</li>
<li>
<span class='inline-group'><em>Limitations</em> : Does not account for headspace gas migration; may underestimate migration of highly volatile substances.</span>
<span class='inline-group'><em>Limitations</em>: Does not account for headspace gas migration; may underestimate migration of highly volatile substances.</span>
</li>
</ul>
</li>
<li>
<span class='inline-group'><strong>Headspace analysis</strong></span>
<ul>
<li>
<span class='inline-group'><em>What it is</em> : Measurement of volatile substances that migrate from the material into the surrounding gas phase.</span>
<span class='inline-group'><em>What it is</em>: Measurement of volatile substances that migrate from the material into the surrounding gas phase.</span>
</li>
<li>
<span class='inline-group'><em>Procedure</em> :</span>
<span class='inline-group'><em>Procedure</em>:</span>
<ul>
<li>Seal the material in a headspace vial or chamber.</li>
<li>Equilibrate at a defined temperature (commonly 25 °C–60 °C).</li>
Expand All @@ -283,24 +283,24 @@ <h2>Safety and Regulatory Considerations</h2>
</ul>
</li>
<li>
<span class='inline-group'><em>Applications</em> : Assessment of aromas, flavor compounds, or volatile contaminants.</span>
<span class='inline-group'><em>Applications</em>: Assessment of aromas, flavor compounds, or volatile contaminants.</span>
</li>
<li>
<span class='inline-group'><em>Advantages</em> : Sensitive to low‑concentration volatiles; minimal sample preparation.</span>
<span class='inline-group'><em>Advantages</em>: Sensitive to low‑concentration volatiles; minimal sample preparation.</span>
</li>
<li>
<span class='inline-group'><em>Limitations</em> : Does not capture non‑volatile migration; results depend on equilibrium time and temperature.</span>
<span class='inline-group'><em>Limitations</em>: Does not capture non‑volatile migration; results depend on equilibrium time and temperature.</span>
</li>
</ul>
</li>
<li>
<span class='inline-group'><strong>Direct contact tests</strong></span>
<ul>
<li>
<span class='inline-group'><em>What it is</em> : The packaging material is placed in direct contact with the food or food simulant, often using a defined food‑packaging configuration.</span>
<span class='inline-group'><em>What it is</em>: The packaging material is placed in direct contact with the food or food simulant, often using a defined food‑packaging configuration.</span>
</li>
<li>
<span class='inline-group'><em>Procedure</em> :</span>
<span class='inline-group'><em>Procedure</em>:</span>
<ul>
<li>Assemble the material and food (or simulant) in a mold or container that simulates real usage (e.g., sealed pouch, jar).</li>
<li>Incubate for the intended storage time at the relevant temperature.</li>
Expand All @@ -309,10 +309,10 @@ <h2>Safety and Regulatory Considerations</h2>
</ul>
</li>
<li>
<span class='inline-group'><em>Advantages</em> : Mimics real consumer exposure; captures both liquid and vapor migration pathways.</span>
<span class='inline-group'><em>Advantages</em>: Mimics real consumer exposure; captures both liquid and vapor migration pathways.</span>
</li>
<li>
<span class='inline-group'><em>Limitations</em> : More labor‑intensive; requires careful control of contact area, thickness, and sealing integrity.</span>
<span class='inline-group'><em>Limitations</em>: More labor‑intensive; requires careful control of contact area, thickness, and sealing integrity.</span>
</li>
</ul>
</li>
Expand Down
30 changes: 15 additions & 15 deletions test/data/doc/polymers.gt.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,38 +50,38 @@
**Common migration testing methods**

- **Extraction in food simulants**
- *What it is* : Samples of the packaging material are immersed in a liquid that mimics the chemical properties of a specific food type (e.g., aqueous, acidic, fatty).
- *Typical simulants* :
- *What it is*: Samples of the packaging material are immersed in a liquid that mimics the chemical properties of a specific food type (e.g., aqueous, acidic, fatty).
- *Typical simulants*:
- 3% acetic acid (for acidic foods)
- 50% ethanol (for alcohol‑based foods)
- 95% ethanol (for high‑fat foods)
- Distilled water (for aqueous foods)
- *Procedure* :
- *Procedure*:
- Prepare a defined volume of simulant in a sealed vessel.
- Immerse the material for a set time at a controlled temperature (often 50 °C–70 °C).
- Remove, filter, and concentrate the extract for analysis.
- *Analysis* : GC‑MS, LC‑MS, or HPLC depending on the analyte class.
- *Advantages* : Direct assessment of potential migration into a realistic medium; scalable for routine testing.
- *Limitations* : Does not account for headspace gas migration; may underestimate migration of highly volatile substances.
- *Analysis*: GC‑MS, LC‑MS, or HPLC depending on the analyte class.
- *Advantages*: Direct assessment of potential migration into a realistic medium; scalable for routine testing.
- *Limitations*: Does not account for headspace gas migration; may underestimate migration of highly volatile substances.
- **Headspace analysis**
- *What it is* : Measurement of volatile substances that migrate from the material into the surrounding gas phase.
- *Procedure* :
- *What it is*: Measurement of volatile substances that migrate from the material into the surrounding gas phase.
- *Procedure*:
- Seal the material in a headspace vial or chamber.
- Equilibrate at a defined temperature (commonly 25 °C–60 °C).
- Sample the gas phase with a gas sampling needle or syringe.
- Analyze via GC‑FID, GC‑MS, or PTR‑MS.
- *Applications* : Assessment of aromas, flavor compounds, or volatile contaminants.
- *Advantages* : Sensitive to low‑concentration volatiles; minimal sample preparation.
- *Limitations* : Does not capture non‑volatile migration; results depend on equilibrium time and temperature.
- *Applications*: Assessment of aromas, flavor compounds, or volatile contaminants.
- *Advantages*: Sensitive to low‑concentration volatiles; minimal sample preparation.
- *Limitations*: Does not capture non‑volatile migration; results depend on equilibrium time and temperature.
- **Direct contact tests**
- *What it is* : The packaging material is placed in direct contact with the food or food simulant, often using a defined food‑packaging configuration.
- *Procedure* :
- *What it is*: The packaging material is placed in direct contact with the food or food simulant, often using a defined food‑packaging configuration.
- *Procedure*:
- Assemble the material and food (or simulant) in a mold or container that simulates real usage (e.g., sealed pouch, jar).
- Incubate for the intended storage time at the relevant temperature.
- Extract or sample the food directly (e.g., through the material or by taking a portion of the food).
- Analyze for migrated substances.
- *Advantages* : Mimics real consumer exposure; captures both liquid and vapor migration pathways.
- *Limitations* : More labor‑intensive; requires careful control of contact area, thickness, and sealing integrity.
- *Advantages*: Mimics real consumer exposure; captures both liquid and vapor migration pathways.
- *Limitations*: More labor‑intensive; requires careful control of contact area, thickness, and sealing integrity.

These three approaches—extraction in food simulants, headspace analysis, and direct contact tests—complement each other to provide a comprehensive assessment of potential migration from packaging into food.

Expand Down
Loading
Loading