docx/alignment-right

Paragraph horizontal alignment set to right.

Library verdicts: python-docx: — docxjs: pass

Metadata

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

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
alignment-right-jc-present
word/document.xml
exist
The paragraph must have a <w:jc> child inside <w:pPr>.
//w:p[w:r/w:t[normalize-space()='Right aligned paragraph']]/w:pPr/w:jc
alignment-right-val
word/document.xml
equal = right
w:jc@w:val must be exactly 'right'.
//w:p[w:r/w:t[normalize-space()='Right aligned paragraph']]/w:pPr/w:jc/@w:val

Render assertions

IDPredicateSelectorpython-docxdocxjs
alignment-right-text-presentcss_selector/ match-text = Right aligned paragraph
The rendered DOM must contain the fixture text.
.docx-wrapper ppass
alignment-right-computedcomputed_style = ^right$ style=text-align
The computed text-align on the paragraph must be 'right'.
.docx-wrapper ppass

Generator source

scripts/gen_alignment_right.py

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

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


def main() -> int:
    doc = Document()
    paragraph = doc.add_paragraph("Right aligned paragraph")
    paragraph.alignment = WD_ALIGN_PARAGRAPH.RIGHT
    _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-right",
  "title": "Paragraph alignment — right",
  "format": "docx",
  "category": "paragraph-layout",
  "summary": "Paragraph horizontal alignment set to right.",
  "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=\"right\"/> inside <w:pPr>. See also 17.3.1.1 for pPr."
  },
  "fixtures": {
    "machine": "docx/alignment-right",
    "office": "docx/alignment-right"
  },
  "generator": {
    "python": "scripts/gen_alignment_right.py"
  },
  "assertions": [
    {
      "id": "alignment-right-jc-present",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Right aligned paragraph']]/w:pPr/w:jc",
      "must": "exist",
      "description": "The paragraph must have a <w:jc> child inside <w:pPr>."
    },
    {
      "id": "alignment-right-val",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:p[w:r/w:t[normalize-space()='Right aligned paragraph']]/w:pPr/w:jc/@w:val",
      "must": "equal",
      "value": "right",
      "description": "w:jc@w:val must be exactly 'right'."
    }
  ],
  "render_assertions": [
    {
      "id": "alignment-right-text-present",
      "kind": "css_selector",
      "selector": ".docx-wrapper p",
      "must": "match-text",
      "value": "Right aligned paragraph",
      "description": "The rendered DOM must contain the fixture text."
    },
    {
      "id": "alignment-right-computed",
      "kind": "computed_style",
      "selector": ".docx-wrapper p",
      "style_property": "text-align",
      "value": "^right$",
      "description": "The computed text-align on the paragraph must be 'right'."
    }
  ]
}

Fixture

Download alignment-right.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/alignment-right page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Horizontal alignment is carried by <w:jc w:val="right"/> inside <w:pPr>. See also 17.3.1.1 for pPr.