Python tool for converting files and office documents to Markdown.
Preserve strikethrough from <strike> and CSS line-through (#2342)
Gyanu Mayankbe631e1fc050
diff --git a/packages/markitdown/src/markitdown/converters/_markdownify.py b/packages/markitdown/src/markitdown/converters/_markdownify.pyindex 8403b6b0..db2f1800 100644--- a/packages/markitdown/src/markitdown/converters/_markdownify.py+++ b/packages/markitdown/src/markitdown/converters/_markdownify.py@@ -122,5 +122,9 @@ class _CustomMarkdownify(markdownify.MarkdownConverter):return "[x] " if el.has_attr("checked") else "[ ] "return ""+ def convert_strike(self, el: Any, text: str, *args, **kwargs) -> str:+ """Obsolete <strike> is still in the wild; treat it like <s>/<del>."""+ return self.convert_s(el, text, *args, **kwargs) # type: ignore+def convert_soup(self, soup: Any) -> str:return super().convert_soup(soup) # type: ignorediff --git a/packages/markitdown/tests/test_module_misc.py b/packages/markitdown/tests/test_module_misc.pyindex 2cd6129b..135fb770 100644--- a/packages/markitdown/tests/test_module_misc.py+++ b/packages/markitdown/tests/test_module_misc.py@@ -264,6 +264,44 @@ def test_docx_comments() -> None:validate_strings(result, DOCX_COMMENT_TEST_STRINGS)+def test_html_strikethrough_variants(tmp_path) -> None:+ html = """<!doctype html>+<html><body>+<p>Plain <s>s element</s> after.</p>+<p>Plain <del>del element</del> after.</p>+<p>Plain <strike>strike element</strike> after.</p>+<p>Spaces A<strike> B </strike>C.</p>+<p>Runs D<strike> E </strike>F.</p>+<p>Empty G<strike></strike>H.</p>+<p>Newline I<strike>J+K</strike>L.</p>+<p>Break M<strike>N<br>O</strike>P.</p>+</body></html>+"""+ path = tmp_path / "strike.html"+ path.write_text(html, encoding="utf-8")+ markdown = MarkItDown().convert(str(path)).markdown++ assert markdown == "\n\n".join(+ [+ # <s>, <del> and the obsolete <strike> all mean strikethrough+ "Plain ~~s element~~ after.",+ "Plain ~~del element~~ after.",+ "Plain ~~strike element~~ after.",+ # Surrounding whitespace stays outside of the markup ...+ "Spaces A ~~B~~ C.",+ # ... and runs of it collapse to a single space+ "Runs D ~~E~~ F.",+ # An empty element contributes nothing+ "Empty GH.",+ # A line break inside the element is kept, and the markup+ # survives it because strikethrough may span a single newline+ "Newline I~~J\nK~~L.",+ "Break M~~N\nO~~P.",+ ]+ )++def test_docx_equations() -> None:markitdown = MarkItDown()docx_file = os.path.join(TEST_FILES_DIR, "equations.docx")