From 9a6450903a07511758e6820a23dd497fafd7c3fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=8F=AF?= Date: Mon, 9 Mar 2026 11:33:02 +0800 Subject: [PATCH 1/2] fix: convert headings to plain text in table cells (issue #2722) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 温可 --- docling_core/transforms/serializer/markdown.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/docling_core/transforms/serializer/markdown.py b/docling_core/transforms/serializer/markdown.py index da547b21..b8d53d22 100644 --- a/docling_core/transforms/serializer/markdown.py +++ b/docling_core/transforms/serializer/markdown.py @@ -191,6 +191,7 @@ def serialize( doc_serializer: BaseDocSerializer, doc: DoclingDocument, is_inline_scope: bool = False, + in_table_cell: bool = False, visited: Optional[set[str]] = None, # refs of visited items **kwargs: Any, ) -> SerializationResult: @@ -269,7 +270,7 @@ def serialize( pieces.append(text) text_part = " ".join(pieces) else: - text_part = self._format_heading(text, item) + text_part = self._format_heading(text, item, in_table_cell=in_table_cell) elif isinstance(item, CodeItem): if params.format_code_blocks: # inline items and all hyperlinks: use single backticks @@ -318,8 +319,13 @@ def _format_heading( self, text: str, item: Union[TitleItem, SectionHeaderItem], + in_table_cell: bool = False, ) -> str: """Format a heading/title item. Override to customize heading representation.""" + # According to markdown specs, headings are not allowed inside tables + # Convert to plain text when in table cell + if in_table_cell: + return text num_hashes = 1 if isinstance(item, TitleItem) else item.level + 1 return f"{num_hashes * '#'} {text}" @@ -532,7 +538,7 @@ def serialize( for col in row: if isinstance(col, RichTableCell): ref_item = col.ref.resolve(doc=doc) - inner_kwargs = {**kwargs, "_nested_in_table": True} + inner_kwargs = {**kwargs, "_nested_in_table": True, "in_table_cell": True} cell_text = doc_serializer.serialize( item=ref_item, **inner_kwargs, From 9767ec9a797f492ac9d195b141c6c9ee8d37c37a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=A9=E5=8F=AF?= Date: Mon, 9 Mar 2026 12:36:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?DCO=20Remediation=20Commit=20for=20?= =?UTF-8?q?=E6=B8=A9=E5=8F=AF=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I, 温可 , hereby add my Signed-off-by to this commit: 9a64509 Signed-off-by: 温可