diff --git a/packages/markitdown/src/markitdown/converters/_markdownify.py b/packages/markitdown/src/markitdown/converters/_markdownify.py index 19e8a2984..ca1358fab 100644 --- a/packages/markitdown/src/markitdown/converters/_markdownify.py +++ b/packages/markitdown/src/markitdown/converters/_markdownify.py @@ -86,11 +86,16 @@ def convert_img( self, el: Any, text: str, - convert_as_inline: Optional[bool] = False, + parent_tags: Optional[Any] = None, **kwargs, ) -> str: """Same as usual converter, but removes data URIs""" + # markdownify >= 1.0 passes `parent_tags` (containing the pseudo-tag + # "_inline" for headings/table cells) instead of the old + # `convert_as_inline` boolean; check that so inline images still reduce + # to their alt text. + parent_tags = parent_tags or set() alt = el.attrs.get("alt", None) or "" src = el.attrs.get("src", None) or el.attrs.get("data-src", None) or "" title = el.attrs.get("title", None) or "" @@ -98,7 +103,7 @@ def convert_img( # Remove all line breaks from alt alt = alt.replace("\n", " ") if ( - convert_as_inline + "_inline" in parent_tags and el.parent.name not in self.options["keep_inline_images_in"] ): return alt diff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.py index 4d62e4919..854fc8450 100644 --- a/packages/markitdown/tests/test_module_misc.py +++ b/packages/markitdown/tests/test_module_misc.py @@ -552,3 +552,29 @@ def test_markitdown_llm() -> None: test() print("OK") print("All tests passed!") + + +def test_inline_image_in_heading_reduced_to_alt() -> None: + from markitdown.converters._html_converter import HtmlConverter + + md = HtmlConverter().convert_string('

| Pic | Name |
|---|---|
![]() | bob |
