docx/alignment-left

Paragraph horizontal alignment set to left (the default).

Library verdicts: python-docx: — docxjs: pass

Metadata

Feature iddocx/alignment-left
Formatdocx
Categoryparagraph-layout
Spececma-376-5-part-1 § 17.3.1.13 w:jc

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
alignment-not-non-left
word/document.xml
not-match = ^(center|right|both|distribute)$
The paragraph must not declare a non-left alignment. An absent <w:jc> or val="left"/"start" both satisfy this.
//w:p[w:r/w:t[normalize-space()='Left aligned paragraph']]/w:pPr/w:jc/@w:val

Render assertions

IDPredicateSelectorpython-docxdocxjs
alignment-left-text-presentcss_selector/ match-text = Left aligned paragraph
The rendered DOM must contain the fixture text.
.docx-wrapper ppass
alignment-left-computedcomputed_style = ^(left|start|)$ style=text-align
The computed text-align on the paragraph must be 'left', 'start', or empty (browser default, which is left for LTR).
.docx-wrapper ppass

Generator source

scripts/gen_alignment_left.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/alignment-left.docx``.

A minimal document exercising ``w:jc`` with left alignment (the default).
One paragraph containing a run whose paragraph is explicitly left-aligned.
Designed to satisfy the assertions in
``features/docx/alignment-left.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-left.docx"


def main() -> int:
    doc = Document()
    paragraph = doc.add_paragraph("Left aligned paragraph")
    paragraph.alignment = WD_ALIGN_PARAGRAPH.LEFT
    _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/alignment-left",
  "title": "Paragraph alignment — left",
  "format": "docx",
  "category": "paragraph-layout",
  "summary": "Paragraph horizontal alignment set to left (the default).",
  "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=\"...\"/> inside <w:pPr>. Left is the default paragraph alignment: conformant writers may emit <w:jc w:val=\"left\"/> OR omit the element entirely. The assertion therefore uses 'not-match': whatever is emitted must not claim center/right/both/distribute. See also 17.3.1.1 for pPr."
  },
  "fixtures": {
    "machine": "docx/alignment-left",
    "office": "docx/alignment-left"
  },
  "generator": {
    "python": "scripts/gen_alignment_left.py"
  },
  "assertions": [
    {
      "id": "alignment-not-non-left",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Left aligned paragraph']]/w:pPr/w:jc/@w:val",
      "must": "not-match",
      "value": "^(center|right|both|distribute)$",
      "description": "The paragraph must not declare a non-left alignment. An absent <w:jc> or val=\"left\"/\"start\" both satisfy this."
    }
  ],
  "render_assertions": [
    {
      "id": "alignment-left-text-present",
      "kind": "css_selector",
      "selector": ".docx-wrapper p",
      "must": "match-text",
      "value": "Left aligned paragraph",
      "description": "The rendered DOM must contain the fixture text."
    },
    {
      "id": "alignment-left-computed",
      "kind": "computed_style",
      "selector": ".docx-wrapper p",
      "style_property": "text-align",
      "value": "^(left|start|)$",
      "description": "The computed text-align on the paragraph must be 'left', 'start', or empty (browser default, which is left for LTR)."
    }
  ]
}

Fixture

Download alignment-left.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/alignment-left page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Horizontal alignment is carried by <w:jc w:val="..."/> inside <w:pPr>. Left is the default paragraph alignment: conformant writers may emit <w:jc w:val="left"/> OR omit the element entirely. The assertion therefore uses 'not-match': whatever is emitted must not claim center/right/both/distribute. See also 17.3.1.1 for pPr.