Skip to content

Commit 4993c34

Browse files
fix: title for export to markdown and add text_width parameter (#59)
* fix: added new linw after title Signed-off-by: Peter Staar <[email protected]> * adding the text_width parameter to export_to_markdown Signed-off-by: Peter Staar <[email protected]> * added the text_width and reformatted Signed-off-by: Peter Staar <[email protected]> --------- Signed-off-by: Peter Staar <[email protected]>
1 parent 3a6a4c0 commit 4993c34

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

docling_core/types/doc/document.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import mimetypes
55
import re
66
import sys
7+
import textwrap
78
import typing
89
from io import BytesIO
910
from typing import Any, Dict, Final, List, Literal, Optional, Tuple, Union
@@ -1125,6 +1126,7 @@ def export_to_markdown( # noqa: C901
11251126
image_placeholder: str = "<!-- image -->",
11261127
image_mode: ImageRefMode = ImageRefMode.PLACEHOLDER,
11271128
indent: int = 4,
1129+
text_width: int = -1,
11281130
) -> str:
11291131
r"""Serialize to Markdown.
11301132
@@ -1207,8 +1209,8 @@ def export_to_markdown( # noqa: C901
12071209
elif isinstance(item, TextItem) and item.label in [DocItemLabel.TITLE]:
12081210
in_list = False
12091211
marker = "" if strict_text else "#"
1210-
text = f"{marker} {item.text}\n"
1211-
mdtexts.append(text.strip())
1212+
text = f"{marker} {item.text}"
1213+
mdtexts.append(text.strip() + "\n")
12121214

12131215
elif (
12141216
isinstance(item, TextItem)
@@ -1251,7 +1253,10 @@ def export_to_markdown( # noqa: C901
12511253

12521254
elif isinstance(item, TextItem) and item.label in labels:
12531255
in_list = False
1254-
if len(item.text):
1256+
if len(item.text) and text_width > 0:
1257+
wrapped_text = textwrap.fill(text, width=text_width)
1258+
mdtexts.append(wrapped_text + "\n")
1259+
elif len(item.text):
12551260
text = f"{item.text}\n"
12561261
mdtexts.append(text)
12571262

0 commit comments

Comments
 (0)