Render the run's lowercase letters as full-size uppercase letters.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/all-caps-text |
|---|---|
| Format | docx |
| Category | text-formatting |
| Spec | ecma-376-5-part-1 § 17.3.2.3 w:caps |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
all-caps-element-presentword/document.xml | existThe run carrying the all-caps text must have a <w:caps> child inside <w:rPr>. | //w:r[w:t[normalize-space()='All caps text']]/w:rPr/w:caps | — | — |
all-caps-val-not-falseword/document.xml | not-match = ^(0|false|off)$If w:val is present it must not explicitly disable caps. | //w:r[w:t[normalize-space()='All caps text']]/w:rPr/w:caps/@w:val | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
all-caps-text-rendered | css_selector/ match-text = All caps textA DOM node marked uppercase (via text-transform: uppercase) must contain the fixture text. | .docx-wrapper [style*='text-transform: uppercase'], .docx-wrapper [style*='text-transform:uppercase'] | — | pass |
all-caps-text-visible | computed_style = uppercase style=text-transformThe computed text-transform on the all-caps run must be uppercase. | .docx-wrapper span:not(:has(*)) | — | pass |
scripts/gen_all_caps_text.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/all-caps-text.docx``.
A minimal document exercising the ``w:caps`` element. One paragraph
containing one run presented as full-size capitals.
Satisfies the assertions in ``features/docx/all-caps-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" / "all-caps-text.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph()
run = paragraph.add_run("All caps text")
run.font.all_caps = 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/all-caps-text",
"title": "All caps text",
"format": "docx",
"category": "text-formatting",
"summary": "Render the run's lowercase letters as full-size uppercase letters.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.2.3",
"element": "w:caps",
"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:caps/> to display the run's lowercase glyphs as full-size capitals. The stored text is unchanged — this is a presentational transform. Empty element means true. w:val is optional; if present it must not be 0/false/off. Mutually exclusive with <w:smallCaps> in practice."
},
"fixtures": {
"machine": "docx/all-caps-text",
"office": "docx/all-caps-text"
},
"generator": {
"python": "scripts/gen_all_caps_text.py"
},
"assertions": [
{
"id": "all-caps-element-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='All caps text']]/w:rPr/w:caps",
"must": "exist",
"description": "The run carrying the all-caps text must have a <w:caps> child inside <w:rPr>."
},
{
"id": "all-caps-val-not-false",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:r[w:t[normalize-space()='All caps text']]/w:rPr/w:caps/@w:val",
"must": "not-match",
"value": "^(0|false|off)$",
"description": "If w:val is present it must not explicitly disable caps."
}
],
"render_assertions": [
{
"id": "all-caps-text-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper [style*='text-transform: uppercase'], .docx-wrapper [style*='text-transform:uppercase']",
"must": "match-text",
"value": "All caps text",
"description": "A DOM node marked uppercase (via text-transform: uppercase) must contain the fixture text."
},
{
"id": "all-caps-text-visible",
"kind": "computed_style",
"selector": ".docx-wrapper span:not(:has(*))",
"style_property": "text-transform",
"value": "uppercase",
"description": "The computed text-transform on the all-caps run must be uppercase."
}
]
}
