docx/strikethrough-text

Apply single-line strikethrough formatting to a run of text.

Library verdicts: python-docx: — docxjs: pass

Metadata

Feature iddocx/strikethrough-text
Formatdocx
Categorytext-formatting
Spececma-376-5-part-1 § 17.3.2.37 w:strike

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
strike-element-present
word/document.xml
exist
The run carrying the strikethrough text must have a <w:strike> child inside <w:rPr>.
//w:r[w:t[normalize-space()='Strikethrough text']]/w:rPr/w:strike
strike-val-not-false
word/document.xml
not-match = ^(0|false|off)$
If w:val is present it must not explicitly disable strike.
//w:r[w:t[normalize-space()='Strikethrough text']]/w:rPr/w:strike/@w:val

Render assertions

IDPredicateSelectorpython-docxdocxjs
strike-text-renderedcss_selector/ match-text = Strikethrough text
A DOM node marked struck (via <s>/<strike>/<del> or text-decoration: line-through) must contain the fixture text.
.docx-wrapper :is(s, strike, del), .docx-wrapper [style*='text-decoration: line-through'], .docx-wrapper [style*='text-decoration:line-through'], .docx-wrapper [style*='text-decoration-line: line-through'], .docx-wrapper [style*='text-decoration-line:line-through']pass
strike-text-visiblecomputed_style = line-through style=text-decoration-line
The computed text-decoration-line on the strikethrough run must include line-through.
.docx-wrapper :is(s, strike, del, span):not(:has(*))pass

Generator source

scripts/gen_strikethrough_text.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/strikethrough-text.docx``.

A minimal document exercising the ``w:strike`` strikethrough element.
One paragraph containing one run with strike-through enabled.
Satisfies the assertions in ``features/docx/strikethrough-text.json``.
"""

from __future__ import annotations

from pathlib import Path

from docx import Document

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "strikethrough-text.docx"


def main() -> int:
    doc = Document()
    paragraph = doc.add_paragraph()
    run = paragraph.add_run("Strikethrough text")
    run.font.strike = True
    _OUT.parent.mkdir(parents=True, exist_ok=True)
    doc.save(_OUT, reproducible=True)
    print(_OUT)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "docx/strikethrough-text",
  "title": "Strikethrough text",
  "format": "docx",
  "category": "text-formatting",
  "summary": "Apply single-line strikethrough formatting to a run of text.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "17.3.2.37",
    "element": "w:strike",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
    "notes": "Word emits <w:strike/> to draw a single line through the run's glyphs. Empty element means true. w:val is optional; if present it must not be 0/false/off (those explicitly disable strike in a toggled style chain). <w:dstrike> is the distinct double-strike variant."
  },
  "fixtures": {
    "machine": "docx/strikethrough-text",
    "office": "docx/strikethrough-text"
  },
  "generator": {
    "python": "scripts/gen_strikethrough_text.py"
  },
  "assertions": [
    {
      "id": "strike-element-present",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:r[w:t[normalize-space()='Strikethrough text']]/w:rPr/w:strike",
      "must": "exist",
      "description": "The run carrying the strikethrough text must have a <w:strike> child inside <w:rPr>."
    },
    {
      "id": "strike-val-not-false",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:r[w:t[normalize-space()='Strikethrough text']]/w:rPr/w:strike/@w:val",
      "must": "not-match",
      "value": "^(0|false|off)$",
      "description": "If w:val is present it must not explicitly disable strike."
    }
  ],
  "render_assertions": [
    {
      "id": "strike-text-rendered",
      "kind": "css_selector",
      "selector": ".docx-wrapper :is(s, strike, del), .docx-wrapper [style*='text-decoration: line-through'], .docx-wrapper [style*='text-decoration:line-through'], .docx-wrapper [style*='text-decoration-line: line-through'], .docx-wrapper [style*='text-decoration-line:line-through']",
      "must": "match-text",
      "value": "Strikethrough text",
      "description": "A DOM node marked struck (via <s>/<strike>/<del> or text-decoration: line-through) must contain the fixture text."
    },
    {
      "id": "strike-text-visible",
      "kind": "computed_style",
      "selector": ".docx-wrapper :is(s, strike, del, span):not(:has(*))",
      "style_property": "text-decoration-line",
      "value": "line-through",
      "description": "The computed text-decoration-line on the strikethrough run must include line-through."
    }
  ]
}

Fixture

Download strikethrough-text.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/strikethrough-text page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Word emits <w:strike/> to draw a single line through the run's glyphs. Empty element means true. w:val is optional; if present it must not be 0/false/off (those explicitly disable strike in a toggled style chain). <w:dstrike> is the distinct double-strike variant.