docx/paragraph-indent-first-line

Indent the first line of a paragraph by 0.5 inch.

Library verdicts: python-docx: — docxjs: fail

Metadata

Feature iddocx/paragraph-indent-first-line
Formatdocx
Categoryparagraph-layout
Spececma-376-5-part-1 § 17.3.1.12 w:ind

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
first-line-indent-ind-present
word/document.xml
exist
The 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-720
word/document.xml
equal = 720
w: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

Render assertions

IDPredicateSelectorpython-docxdocxjs
first-line-indent-text-presentcss_selector/ match-text = Paragraph with first-line indent
The rendered DOM must contain the fixture text.
.docx-wrapper ppass
first-line-indent-computedcomputed_style = ^(0\.5in|4[0-9](\.[0-9]+)?px|5[0-9](\.[0-9]+)?px)$ style=text-indent
The computed text-indent must be 0.5in or ~48px (roughly 40–59px window at 96dpi).
.docx-wrapper pfail

Generator source

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())

Manifest (expanded)

{
  "$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)."
    }
  ]
}

Fixture

Download paragraph-indent-first-line.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/paragraph-indent-first-line page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec 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.