Three consecutive paragraphs styled with the built-in List Number style to form an ordered list.
Library verdicts: python-docx: — docxjs: pass
| Feature id | docx/numbered-list |
|---|---|
| Format | docx |
| Category | lists |
| Spec | ecma-376-5-part-1 § 17.3.1.19 w:numPr |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
numbered-list-item-one-presentword/document.xml | existThe first numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item one'. | //w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item one']] | — | — |
numbered-list-item-two-presentword/document.xml | existThe second numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item two'. | //w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item two']] | — | — |
numbered-list-item-three-presentword/document.xml | existThe third numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item three'. | //w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item three']] | — | — |
numbered-list-item-countword/document.xml | match = ^3(\.0)?$Exactly three paragraphs must use the ListNumber style. | count(//w:p[w:pPr/w:pStyle[@w:val='ListNumber']]) | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
numbered-list-item-one-rendered | css_selector/ match-text = Numbered item oneA numbered list-item DOM node (ol > li, or a paragraph carrying the List Number style) must contain the first fixture item. Falls back to any paragraph since renderer conventions vary. | .docx-wrapper ol li, .docx-wrapper [data-style='List Number'], .docx-wrapper [class*='list-number'], .docx-wrapper [class*='ListNumber'], .docx-wrapper p | — | pass |
numbered-list-item-count | css_selector/ equal-countExactly three numbered list-item DOM nodes must be rendered — one per fixture bullet. Catches phantom or dropped items the match-text assertion can't see. Includes docxjs's `p.docx-num-<id>-<lvl>` list-item markup in the selector fallback chain. | .docx-wrapper ol li, .docx-wrapper [data-style='List Number'], .docx-wrapper [class*='list-number'], .docx-wrapper [class*='ListNumber'], .docx-wrapper p[class*='-num-'] | — | — |
numbered-list-item-two-rendered | css_selector/ match-text = Numbered item twoThe second list-item must contain 'Numbered item two'. Catches content-leak between sibling <li> nodes. | .docx-wrapper ol li:nth-of-type(2), .docx-wrapper [data-style='List Number']:nth-of-type(2), .docx-wrapper [class*='ListNumber']:nth-of-type(2), .docx-wrapper p:nth-of-type(2) | — | — |
numbered-list-item-three-rendered | css_selector/ match-text = Numbered item threeThe third list-item must contain 'Numbered item three'. Catches content leaks and dropped-sibling bugs. | .docx-wrapper ol li:nth-of-type(3), .docx-wrapper [data-style='List Number']:nth-of-type(3), .docx-wrapper [class*='ListNumber']:nth-of-type(3), .docx-wrapper p:nth-of-type(3) | — | — |
scripts/gen_numbered_list.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/numbered-list.docx``.
A minimal document exercising the built-in ``List Number`` paragraph
style. Three consecutive paragraphs form an ordered list. Designed to
satisfy the assertions in ``features/docx/numbered-list.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" / "numbered-list.docx"
def main() -> int:
doc = Document()
doc.add_paragraph("Numbered item one", style="List Number")
doc.add_paragraph("Numbered item two", style="List Number")
doc.add_paragraph("Numbered item three", style="List Number")
_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/numbered-list",
"title": "Numbered list",
"format": "docx",
"category": "lists",
"summary": "Three consecutive paragraphs styled with the built-in List Number style to form an ordered list.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.1.19",
"element": "w:numPr",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "List membership is expressed via the paragraph's pStyle pointing at a list style (e.g. 'ListNumber') or directly via <w:pPr><w:numPr><w:numId w:val='n'/><w:ilvl w:val='0'/></w:numPr></w:pPr>. Word collapses whitespace in style names, so the 'List Number' built-in style appears as pStyle w:val='ListNumber' in the XML, not 'List Number'."
},
"fixtures": {
"machine": "docx/numbered-list",
"office": "docx/numbered-list"
},
"generator": {
"python": "scripts/gen_numbered_list.py"
},
"assertions": [
{
"id": "numbered-list-item-one-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item one']]",
"must": "exist",
"description": "The first numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item one'."
},
{
"id": "numbered-list-item-two-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item two']]",
"must": "exist",
"description": "The second numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item two'."
},
{
"id": "numbered-list-item-three-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:pPr/w:pStyle[@w:val='ListNumber']][w:r/w:t[normalize-space()='Numbered item three']]",
"must": "exist",
"description": "The third numbered paragraph must carry pStyle='ListNumber' and contain the fixture text 'Numbered item three'."
},
{
"id": "numbered-list-item-count",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "count(//w:p[w:pPr/w:pStyle[@w:val='ListNumber']])",
"must": "match",
"value": "^3(\\.0)?$",
"description": "Exactly three paragraphs must use the ListNumber style."
}
],
"render_assertions": [
{
"id": "numbered-list-item-one-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper ol li, .docx-wrapper [data-style='List Number'], .docx-wrapper [class*='list-number'], .docx-wrapper [class*='ListNumber'], .docx-wrapper p",
"must": "match-text",
"value": "Numbered item one",
"description": "A numbered list-item DOM node (ol > li, or a paragraph carrying the List Number style) must contain the first fixture item. Falls back to any paragraph since renderer conventions vary."
},
{
"id": "numbered-list-item-count",
"kind": "css_selector",
"selector": ".docx-wrapper ol li, .docx-wrapper [data-style='List Number'], .docx-wrapper [class*='list-number'], .docx-wrapper [class*='ListNumber'], .docx-wrapper p[class*='-num-']",
"must": "equal-count",
"count": 3,
"description": "Exactly three numbered list-item DOM nodes must be rendered — one per fixture bullet. Catches phantom or dropped items the match-text assertion can't see. Includes docxjs's `p.docx-num-<id>-<lvl>` list-item markup in the selector fallback chain."
},
{
"id": "numbered-list-item-two-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper ol li:nth-of-type(2), .docx-wrapper [data-style='List Number']:nth-of-type(2), .docx-wrapper [class*='ListNumber']:nth-of-type(2), .docx-wrapper p:nth-of-type(2)",
"must": "match-text",
"value": "Numbered item two",
"description": "The second list-item must contain 'Numbered item two'. Catches content-leak between sibling <li> nodes."
},
{
"id": "numbered-list-item-three-rendered",
"kind": "css_selector",
"selector": ".docx-wrapper ol li:nth-of-type(3), .docx-wrapper [data-style='List Number']:nth-of-type(3), .docx-wrapper [class*='ListNumber']:nth-of-type(3), .docx-wrapper p:nth-of-type(3)",
"must": "match-text",
"value": "Numbered item three",
"description": "The third list-item must contain 'Numbered item three'. Catches content leaks and dropped-sibling bugs."
}
]
}
