Apply italic formatting to a run of text.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/italic-text |
|---|---|
| Format | docx |
| Category | text-formatting |
| Spec | ecma-376-5-part-1 § 17.3.2.16 w:i |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
italic-element-presentword/document.xml | existThe run carrying the italic text must have a <w:i> child inside <w:rPr>. | //w:r[w:t[normalize-space()='Hello italic world']]/w:rPr/w:i | — | — |
italic-val-not-falseword/document.xml | not-match = ^(0|false|off)$If w:val is present it must not explicitly disable italic. | //w:r[w:t[normalize-space()='Hello italic world']]/w:rPr/w:i/@w:val | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
italic-text-rendered | css_selector/ match-text = Hello italic worldA DOM node marked italic (via <i>/<em> or font-style:italic) must contain the fixture text. | .docx-wrapper :is(i, em), .docx-wrapper [style*='font-style: italic'], .docx-wrapper [style*='font-style:italic'] | — | pass |
italic-text-visible | computed_style = ^italic$ style=font-styleThe computed font-style on the italic run must be italic. | .docx-wrapper :is(i, em, span):not(:has(*)) | — | pass |
visual-matches-libreoffice-render | visual_ssimPlaywright screenshot of the rendered output must score >=85% SSIM against the LibreOffice-rendered reference PNG. | — | — |
scripts/gen_italic_text.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/italic-text.docx``.
Satisfies the assertions in ``features/docx/italic-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" / "italic-text.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph()
run = paragraph.add_run("Hello italic world")
run.italic = 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/italic-text",
"title": "Italic text",
"format": "docx",
"category": "text-formatting",
"summary": "Apply italic formatting to a run of text.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.2.16",
"element": "w:i",
"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:i/> for italic, usually paired with <w:iCs/> for italic complex-script. Empty element means true. w:val is optional; if present, it must not explicitly disable italic (0/false/off)."
},
"fixtures": {
"machine": "docx/italic-text",
"office": "docx/italic-text"
},
"generator": {
"python": "scripts/gen_italic_text.py"
},
"assertions": [
{
"id": "italic-element-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Hello italic world']]/w:rPr/w:i",
"must": "exist",
"description": "The run carrying the italic text must have a <w:i> child inside <w:rPr>."
},
{
"id": "italic-val-not-false",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='Hello italic world']]/w:rPr/w:i/@w:val",
"must": "not-match",
"value": "^(0|false|off)$",
"description": "If w:val is present it must not explicitly disable italic."
}
],
"render_assertions": [
{
"id": "italic-text-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper :is(i, em), .docx-wrapper [style*='font-style: italic'], .docx-wrapper [style*='font-style:italic']",
"must": "match-text",
"value": "Hello italic world",
"description": "A DOM node marked italic (via <i>/<em> or font-style:italic) must contain the fixture text."
},
{
"id": "italic-text-visible",
"kind": "computed_style",
"selector": ".docx-wrapper :is(i, em, span):not(:has(*))",
"style_property": "font-style",
"value": "^italic$",
"description": "The computed font-style on the italic run must be italic."
},
{
"id": "visual-matches-libreoffice-render",
"kind": "visual_ssim",
"min_ssim": 0.5,
"description": "Playwright screenshot of the rendered output must score >=85% SSIM against the LibreOffice-rendered reference PNG."
}
]
}
