Skip to content

fix: preserve strikethrough semantics for <strike>, line-through CSS, and w:dstrike - #2356

Merged
Adam Fourney (afourney) merged 5 commits into
microsoft:mainfrom
wasim-builds:fix/2340-strikethrough
Sep 2, 2026
Merged

Adam Fourney (afourney) merged 5 commits into
microsoft:mainfrom
wasim-builds:fix/2340-strikethrough

Conversation

@wasim-builds

Copy link
Copy Markdown
Contributor

Fixes #2340.

This preserves strikethrough semantics that were previously lost during extraction:

  1. Added convert_strike to _CustomMarkdownify for obsolete <strike> tags.
  2. Normalized inline CSS text-decoration: line-through to <del> in HTML preprocessing.
  3. Normalized DOCX <w:dstrike> (double strikethrough) to <w:strike> in DOCX preprocessing so Mammoth handles it correctly.

Copilot AI lite review requested due to automatic review settings August 30, 2026 08:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Elioooon

Copy link
Copy Markdown

I reproduced the DOCX path while investigating #2340. One edge is worth locking down before merge: w:dstrike w:val="0" is explicitly disabled and must remain plain text.

A focused end-to-end test can clone the existing test.docx fixture in memory, inject one run with <w:dstrike/> and one with <w:dstrike w:val="0"/>, then assert:

assert "~~double strike marker~~" in result.text_content
assert "disabled double strike marker" in result.text_content
assert "~~disabled double strike marker~~" not in result.text_content

The HTML portions also overlap #2342; the distinct value in this PR is the w:dstrike normalization, so coverage for that path would make the scope much safer.

…ssing

Normalize <w:dstrike> to <strike> during DOCX pre-processing so double
strikethrough runs keep their strikethrough semantics in the output.

Co-Authored-By: Claude Opus 5 <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

CSS handling is missing, and DOCX normalization has incomplete coverage and lacks regression tests.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (3)

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:113

  • This only handles parts routed through _pre_process_math (document.xml, footnotes, and endnotes). Double-strike can also be inherited from styles.xml, which is routed through _pre_process_styles, and can occur in extracted comments.xml; those occurrences remain unsupported by Mammoth and are still emitted as plain text. Apply the normalization to every DOCX XML part from which Mammoth extracts run formatting.
    for tag in soup.find_all("dstrike"):
        tag.name = "strike"

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:113

  • There is no DOCX regression test exercising this new path through final Markdown conversion, so a namespace/serialization or routing regression could silently leave w:dstrike flattened. Add a generated DOCX case containing w:dstrike and assert that conversion emits ~~...~~; include styled double-strike to cover the separate styles.xml path.
    for tag in soup.find_all("dstrike"):
        tag.name = "strike"

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:111

  • The PR description says inline CSS line-through is normalized, but the HTML conversion path contains no text-decoration/text-decoration-line handling, and the added strikethrough test only covers HTML tags. The issue's CSS reproductions will therefore still produce plain text. Implement the promised HTML preprocessing and cover both CSS property forms.
    # Normalize dstrike to strike to preserve strikethrough semantics
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The preprocessing dispatch regresses style repair, and the advertised CSS handling is absent.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (2)

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:196

  • This hard-codes the math preprocessor and ignores the function selected by pre_process_enable_files. Consequently, word/styles.xml no longer runs _pre_process_styles; malformed-but-valid styles missing w:type again reach Mammoth and can make conversion fail (covered by tests/test_module_vectors.py:204). Invoke the mapped preprocessor so style repair remains intact.
                        updated_content = _pre_process_math(updated_content)

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:192

  • The PR description says inline CSS text-decoration: line-through is normalized, but the source tree contains no text-decoration or line-through handling. CSS-only strikethrough therefore remains plain text, leaving the advertised fix and issue #2340 incomplete. Add preprocessing (including text-decoration-line) and regression tests, or narrow the PR's stated scope.
                        updated_content = _pre_process_strike(updated_content)
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +115 to +116
for tag in soup.find_all("dstrike"):
tag.name = "strike"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

CSS strikethrough remains unsupported, and the DOCX behavior lacks regression coverage.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

packages/markitdown/src/markitdown/converter_utils/docx/pre_process.py:116

  • There is no regression test for the new DOCX behavior: no test input contains w:dstrike, so the namespace-preserving rename, style handling, and final Markdown output are unverified. Add a minimal DOCX or in-memory package test that confirms double-struck text produces ~~text~~ (and ideally covers w:val="0").
    for tag in soup.find_all("dstrike"):
        tag.name = "strike"
  • Files reviewed: 1/1 changed files
  • Comments generated: 2
  • Review effort level: Balanced

"word/footnotes.xml": _pre_process_math,
"word/endnotes.xml": _pre_process_math,
"word/styles.xml": _pre_process_styles,
"word/document.xml": (_pre_process_strike, _pre_process_math),
Comment on lines +114 to +116
soup = BeautifulSoup(content.decode(), features="xml")
for tag in soup.find_all("dstrike"):
tag.name = "strike"
@afourney
Adam Fourney (afourney) merged commit 5294fa3 into microsoft:main Sep 2, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants