Paragraph horizontal alignment set to center.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/alignment-center |
|---|---|
| Format | docx |
| Category | paragraph-layout |
| Spec | ecma-376-5-part-1 § 17.3.1.13 w:jc |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
alignment-center-jc-presentword/document.xml | existThe paragraph must have a <w:jc> child inside <w:pPr>. | //w:p[w:r/w:t[normalize-space()='Center aligned paragraph']]/w:pPr/w:jc | — | — |
alignment-center-valword/document.xml | equal = centerw:jc@w:val must be exactly 'center'. | //w:p[w:r/w:t[normalize-space()='Center aligned paragraph']]/w:pPr/w:jc/@w:val | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
alignment-center-text-present | css_selector/ match-text = Center aligned paragraphThe rendered DOM must contain the fixture text. | .docx-wrapper p | — | pass |
alignment-center-computed | computed_style = ^center$ style=text-alignThe computed text-align on the paragraph must be 'center'. | .docx-wrapper p | — | pass |
scripts/gen_alignment_center.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/alignment-center.docx``.
A minimal document exercising ``w:jc`` with center alignment. One
paragraph containing a center-aligned run. Designed to satisfy the
assertions in ``features/docx/alignment-center.json``.
"""
from __future__ import annotations
from pathlib import Path
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "alignment-center.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph("Center aligned paragraph")
paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
_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/alignment-center",
"title": "Paragraph alignment — center",
"format": "docx",
"category": "paragraph-layout",
"summary": "Paragraph horizontal alignment set to center.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.1.13",
"element": "w:jc",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "Horizontal alignment is carried by <w:jc w:val=\"center\"/> inside <w:pPr>. See also 17.3.1.1 for pPr."
},
"fixtures": {
"machine": "docx/alignment-center",
"office": "docx/alignment-center"
},
"generator": {
"python": "scripts/gen_alignment_center.py"
},
"assertions": [
{
"id": "alignment-center-jc-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:r/w:t[normalize-space()='Center aligned paragraph']]/w:pPr/w:jc",
"must": "exist",
"description": "The paragraph must have a <w:jc> child inside <w:pPr>."
},
{
"id": "alignment-center-val",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:r/w:t[normalize-space()='Center aligned paragraph']]/w:pPr/w:jc/@w:val",
"must": "equal",
"value": "center",
"description": "w:jc@w:val must be exactly 'center'."
}
],
"render_assertions": [
{
"id": "alignment-center-text-present",
"kind": "css_selector",
"selector": ".docx-wrapper p",
"must": "match-text",
"value": "Center aligned paragraph",
"description": "The rendered DOM must contain the fixture text."
},
{
"id": "alignment-center-computed",
"kind": "computed_style",
"selector": ".docx-wrapper p",
"style_property": "text-align",
"value": "^center$",
"description": "The computed text-align on the paragraph must be 'center'."
}
]
}
