Indent the first line of a paragraph by 0.5 inch.
Library verdicts: python-docx: — docxjs: fail
| Feature id | docx/paragraph-indent-first-line |
|---|---|
| Format | docx |
| Category | paragraph-layout |
| Spec | ecma-376-5-part-1 § 17.3.1.12 w:ind |
| ID / part | Predicate | XPath | python-docx | docxjs |
|---|---|---|---|---|
first-line-indent-ind-presentword/document.xml | existThe paragraph must have a <w:ind> child inside <w:pPr>. | //w:p[w:r/w:t[normalize-space()='Paragraph with first-line indent']]/w:pPr/w:ind | — | — |
first-line-indent-firstLine-720word/document.xml | equal = 720w:ind@w:firstLine must be 720 (twips) = 0.5 inch. | //w:p[w:r/w:t[normalize-space()='Paragraph with first-line indent']]/w:pPr/w:ind/@w:firstLine | — | — |
| ID | Predicate | Selector | python-docx | docxjs |
|---|---|---|---|---|
first-line-indent-text-present | css_selector/ match-text = Paragraph with first-line indentThe rendered DOM must contain the fixture text. | .docx-wrapper p | — | pass |
first-line-indent-computed | computed_style = ^(0\.5in|4[0-9](\.[0-9]+)?px|5[0-9](\.[0-9]+)?px)$ style=text-indentThe computed text-indent must be 0.5in or ~48px (roughly 40–59px window at 96dpi). | .docx-wrapper p | — | fail |
scripts/gen_paragraph_indent_first_line.py
#!/usr/bin/env python3
"""Generate ``fixtures/docx/paragraph-indent-first-line.docx``.
A minimal document exercising ``w:ind`` with a first-line indent of
0.5 inch (720 twips). Designed to satisfy the assertions in
``features/docx/paragraph-indent-first-line.json``.
"""
from __future__ import annotations
from pathlib import Path
from docx import Document
from docx.shared import Inches
_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "paragraph-indent-first-line.docx"
def main() -> int:
doc = Document()
paragraph = doc.add_paragraph("Paragraph with first-line indent")
paragraph.paragraph_format.first_line_indent = Inches(0.5)
_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/paragraph-indent-first-line",
"title": "Paragraph first-line indent",
"format": "docx",
"category": "paragraph-layout",
"summary": "Indent the first line of a paragraph by 0.5 inch.",
"spec": {
"source": "ecma-376-5-part-1",
"clause": "17.3.1.12",
"element": "w:ind",
"rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
"xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
"notes": "First-line indent is carried by <w:ind w:firstLine=\"...\"/> inside <w:pPr>. Units are twentieths of a point (twips): 720 = 0.5 inch (720 twips = 720/1440 in). See also 17.3.1.1 for pPr."
},
"fixtures": {
"machine": "docx/paragraph-indent-first-line",
"office": "docx/paragraph-indent-first-line"
},
"generator": {
"python": "scripts/gen_paragraph_indent_first_line.py"
},
"assertions": [
{
"id": "first-line-indent-ind-present",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:r/w:t[normalize-space()='Paragraph with first-line indent']]/w:pPr/w:ind",
"must": "exist",
"description": "The paragraph must have a <w:ind> child inside <w:pPr>."
},
{
"id": "first-line-indent-firstLine-720",
"part": "word/document.xml",
"namespaces": {
"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
},
"xpath": "//w:p[w:r/w:t[normalize-space()='Paragraph with first-line indent']]/w:pPr/w:ind/@w:firstLine",
"must": "equal",
"value": "720",
"description": "w:ind@w:firstLine must be 720 (twips) = 0.5 inch."
}
],
"render_assertions": [
{
"id": "first-line-indent-text-present",
"kind": "css_selector",
"selector": ".docx-wrapper p",
"must": "match-text",
"value": "Paragraph with first-line indent",
"description": "The rendered DOM must contain the fixture text."
},
{
"id": "first-line-indent-computed",
"kind": "computed_style",
"selector": ".docx-wrapper p",
"style_property": "text-indent",
"value": "^(0\\.5in|4[0-9](\\.[0-9]+)?px|5[0-9](\\.[0-9]+)?px)$",
"description": "The computed text-indent must be 0.5in or ~48px (roughly 40–59px window at 96dpi)."
}
]
}
