Apply single-line strikethrough formatting to a run of text.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/strikethrough-text |
|---|---|
| Format | docx |
| Category | text-formatting |
| Spec | ecma-376-5-part-1 § 17.3.2.37 w:strike |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
strike-element-presentword/document.xml | existThe 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-falseword/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 | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
strike-text-rendered | css_selector/ match-text = Strikethrough textA 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-visible | computed_style = line-through style=text-decoration-lineThe computed text-decoration-line on the strikethrough run must include line-through. | .docx-wrapper :is(s, strike, del, span):not(:has(*)) | — | pass |
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())
{
"$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."
}
]
}
