markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

Strikethrough is silently lost for `<strike>`, CSS `line-through`, and DOCX double-strike

Open cagdasyurekli opened this issue 3 months ago • 1 comments

Description

MarkItDown preserves some strikethrough representations but silently flattens semantically equivalent variants to plain text. This makes superseded or corrected text indistinguishable from current text in the Markdown output.

The behavior reproduces with the latest PyPI release, markitdown==0.1.7.

Minimal HTML reproduction

from pathlib import Path
from tempfile import TemporaryDirectory

from markitdown import MarkItDown

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>Plain <span style="text-decoration: line-through;">inline CSS line-through</span> after.</p>
<p>Plain <span style="text-decoration-line: line-through;">CSS text-decoration-line</span> after.</p>
</body></html>
"""

with TemporaryDirectory() as tmp:
    path = Path(tmp) / "fixture.html"
    path.write_text(html, encoding="utf-8")
    print(MarkItDown().convert(str(path)).markdown)

Actual output

Plain ~~s element~~ after.

Plain ~~del element~~ after.

Plain strike element after.

Plain inline CSS line-through after.

Plain CSS text-decoration-line after.

Expected output

All five inputs express strikethrough and should retain that meaning, for example:

Plain ~~s element~~ after.

Plain ~~del element~~ after.

Plain ~~strike element~~ after.

Plain ~~inline CSS line-through~~ after.

Plain ~~CSS text-decoration-line~~ after.

At minimum, the obsolete but still encountered <strike> element could be normalized consistently with <s> and <del>. If parsing inline CSS is intentionally out of scope, documenting that limitation would make the loss less surprising.

DOCX observation

A minimal DOCX shows the same inconsistency between OOXML variants:

OOXML run property Actual Markdown
<w:strike/> ~~single strike~~
<w:dstrike/> double strike

Mapping double-strike to ordinary Markdown strikethrough would preserve the important semantic distinction from current text even if Markdown cannot represent the double line exactly.

Impact

The text itself remains present, so conversion appears successful, but consumers can interpret superseded text as current. This is particularly misleading in notes, procedures, and other documents where strikethrough carries meaning.

Environment

  • MarkItDown: 0.1.7
  • Python: 3.12.13
  • OS: macOS 26.6.2, arm64

The same HTML and DOCX outputs were also observed through a MarkItDown MCP installation using markitdown==0.1.5.

Duplicate check

I searched open and closed issues for strikethrough, strike, line-through, double strike, and dstrike and did not find a report matching this behavior.

cagdasyurekli avatar Aug 25 '26 09:08 cagdasyurekli

Solid report — the repro is tight, and this is a good example of the "text survives, semantics die" class of extraction bug: conversion looks successful, but superseded/corrected text becomes indistinguishable from current text downstream. Since MarkItDown is increasingly the ingestion step in RAG/LLM pipelines, that's the worst kind of failure (silent, and it corrupts retrieval meaning).

A few source-level notes that might shorten the fix:

1. <strike> — one missing method, no upstream fork needed _CustomMarkdownify (converters/_markdownify.py) subclasses the upstream markdownify.MarkdownConverter, which defines convert_del/convert_s → ~~…~~ but has no converter for the obsolete <strike> element, so it falls through to plain text. Adding a 4-line method to _CustomMarkdownify fixes it:

def convert_strike(self, el, text, convert_as_inline=False, **kwargs):
    return "~~%s~~" % text

(Alternatively, normalize in the soup pass before convert_soup — same result.)

2. Inline CSS line-through — markdownify is tag-driven, so this needs the soup pre-pass The HTML converter already mutates the parsed soup before markdownify (script/style removal, body selection in _html_converter.py), so a small normalization walk fits the existing structure:

for el in soup.find_all("span", style=True):
    style = el.get("style", "").lower()
    if "line-through" in style.replace(" ", ""):
        el.name = "del"

The substring check is coarse but safe here: line-through only appears in text-decoration/text-decoration-line (shorthand underline line-through, longhand, !important suffix all match). One caveat — skip elements already inside del/s/strike so you don't double-wrap.

3. DOCX w:dstrike — this one is a mammoth mapping, not a markdownify one DocxConverter routes through mammoth.convert_to_html(...) and then reuses the same HtmlConverter, so an HTML-layer fix can't reach dstrike unless mammoth emits a strikethrough tag for it (empirically it doesn't). Two cheap options: pass a default style_map in DocxConverter.convert (mammoth accepts run mappings like r:dstrike => s, merged with any user-supplied map), or normalize it in converter_utils/docx/pre_process.py alongside the existing pre-processing. Markdown can't represent double-strike, but ~~ is the right lossy fallback — it preserves the part that matters (this text is not current).

Nice catch on the duplicate check too — genuinely unreported.

NG-PR0JECT avatar Aug 26 '26 06:08 NG-PR0JECT