Default-section page header carrying a line of text, referenced from sectPr/headerReference.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/page-header |
|---|---|
| Format | docx |
| Category | page-layout |
| Spec | ecma-376-5-part-1 § 17.10.1 w:headerReference |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
headerReference-presentword/document.xml | existThe section must carry a default-type headerReference. | //w:sectPr/w:headerReference[@w:type='default'] | — | — |
header-text-presentword/header1.xml | existThe header part must carry the expected text in a run. | //w:p/w:r/w:t[normalize-space()='Document header text'] | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
header-element-rendered | css_selector/ match-text = Document header textA renderer-exposed header container (header / .docx-header / [data-part='header']) must contain the header text. | .docx-wrapper header, .docx-wrapper .docx-header, .docx-wrapper [data-part='header'] | — | pass |
scripts/gen_page_header.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/page-header.docx``.
A minimal document exercising the default-section page header. The
header carries a single text line; the body carries an unrelated
paragraph. python-docx emits the header as ``word/header1.xml``.
Designed to satisfy the assertions in ``features/docx/page-header.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" / "page-header.docx"
def main() -> int:
doc = Document()
section = doc.sections[0]
header = section.header
header.paragraphs[0].text = "Document header text"
doc.add_paragraph("Body paragraph one")
_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/page-header",
"title": "Page header",
"format": "docx",
"category": "page-layout",
"summary": "Default-section page header carrying a line of text, referenced from sectPr/headerReference.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.10.1",
"element": "w:headerReference",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "A page header is a separate part (<w:hdr>) reached via <w:headerReference w:type=\"default\" r:id=\"rIdN\"/> inside <w:sectPr>. python-docx emits the part as word/header1.xml."
},
"fixtures": {
"machine": "docx/page-header",
"office": "docx/page-header"
},
"generator": {
"python": "scripts/gen_page_header.py"
},
"assertions": [
{
"id": "headerReference-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
"r": "http://schemas.openxmlformats.org/officeDocument/2006/relationships"
},
"xpath": "//w:sectPr/w:headerReference[@w:type='default']",
"must": "exist",
"description": "The section must carry a default-type headerReference."
},
{
"id": "header-text-present",
"part": "word/header1.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p/w:r/w:t[normalize-space()='Document header text']",
"must": "exist",
"description": "The header part must carry the expected text in a run."
}
],
"render_assertions": [
{
"id": "header-element-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper header, .docx-wrapper .docx-header, .docx-wrapper [data-part='header']",
"must": "match-text",
"value": "Document header text",
"description": "A renderer-exposed header container (header / .docx-header / [data-part='header']) must contain the header text."
}
]
}
