diff --git a/docling_core/types/doc/document.py b/docling_core/types/doc/document.py index d1689155..8b701648 100644 --- a/docling_core/types/doc/document.py +++ b/docling_core/types/doc/document.py @@ -1994,6 +1994,7 @@ def save_as_markdown( to_element: int = sys.maxsize, labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS, strict_text: bool = False, + escaping_underscores: bool = True, image_placeholder: str = "", image_mode: ImageRefMode = ImageRefMode.PLACEHOLDER, indent: int = 4, @@ -2016,6 +2017,7 @@ def save_as_markdown( to_element=to_element, labels=labels, strict_text=strict_text, + escaping_underscores=escaping_underscores, image_placeholder=image_placeholder, image_mode=image_mode, indent=indent, @@ -2033,6 +2035,7 @@ def export_to_markdown( # noqa: C901 to_element: int = sys.maxsize, labels: set[DocItemLabel] = DEFAULT_EXPORT_LABELS, strict_text: bool = False, + escaping_underscores: bool = True, image_placeholder: str = "", image_mode: ImageRefMode = ImageRefMode.PLACEHOLDER, indent: int = 4, @@ -2058,6 +2061,9 @@ def export_to_markdown( # noqa: C901 :param strict_text: bool: Whether to only include the text content of the document. (Default value = False). :type strict_text: bool = False + :param escaping_underscores: bool: Whether to escape underscores in the + text content of the document. (Default value = True). + :type escaping_underscores: bool = True :param image_placeholder: The placeholder to include to position images in the markdown. (Default value = "\" @@ -2226,7 +2232,8 @@ def escape_underscores(text): return "".join(parts) - mdtext = escape_underscores(mdtext) + if escaping_underscores: + mdtext = escape_underscores(mdtext) return mdtext @@ -2244,6 +2251,7 @@ def export_to_text( # noqa: C901 to_element, labels, strict_text=True, + escaping_underscores=False, image_placeholder="", )