pptx/rel-target-mode-external--https

An external hyperlink relationship on a PresentationML slide must declare TargetMode="External" in ppt/slides/_rels/slide1.xml.rels.

Library verdicts: python-pptx: — pptxjs: —

Metadata

Feature idpptx/rel-target-mode-external--https
Formatpptx
Categoryopc-packaging
Familypptx/rel-target-mode-external
Axis valueslink=https
Spececma-376-5-part-2 § 9.3 r:Relationship

XPath assertions

ID / partPredicateXPathpython-pptxpptxjs
slide-hyperlink-rel-exists-https
ppt/slides/_rels/slide1.xml.rels
exist
The slide's rels part must declare a hyperlink relationship whose Target is the fixture URL.
//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']
slide-hyperlink-target-mode-external-https
ppt/slides/_rels/slide1.xml.rels
equal = External
TargetMode on the slide's external hyperlink rel must be 'External' (OPC §9.3).
//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']/@TargetMode

Render assertions

No render assertions declared.

Generator source

scripts/gen_pptx_rel_target_mode_external.py

#!/usr/bin/env python3
"""Generate ``fixtures/pptx/rel-target-mode-external--<id>.pptx`` fixtures.

One blank slide with a single textbox; the textbox's sole run carries an
external hyperlink. python-pptx routes the URL through ``run.hyperlink.address
= url`` which serialises an ``r:id`` on the run and a Relationship entry
carrying ``TargetMode="External"`` in ``ppt/slides/_rels/slide1.xml.rels``.

Manifest: ``features/pptx/rel-target-mode-external.json``
"""

from __future__ import annotations

import argparse
from pathlib import Path

from pptx import Presentation
from pptx.util import Inches

_REPO_ROOT = Path(__file__).resolve().parent.parent


def _write(url: str, text: str, out: Path) -> None:
    prs = Presentation()
    # layout index 5 is Title Only in the default master; a blank layout
    # would work equally well but Title Only is universally present.
    slide = prs.slides.add_slide(prs.slide_layouts[5])
    textbox = slide.shapes.add_textbox(Inches(1), Inches(1), Inches(5), Inches(1))
    text_frame = textbox.text_frame
    text_frame.text = text
    run = text_frame.paragraphs[0].runs[0]
    run.hyperlink.address = url
    out.parent.mkdir(parents=True, exist_ok=True)
    prs.save(str(out), zip_date_time=(1980, 1, 1, 0, 0, 0))


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--url", required=True, help="External URI for the slide hyperlink")
    parser.add_argument("--text", required=True, help="Visible link text")
    parser.add_argument("--out", required=True, help="Output fixture path (repo-relative or absolute)")
    args = parser.parse_args()

    out_path = Path(args.out)
    if not out_path.is_absolute():
        out_path = _REPO_ROOT / out_path
    _write(args.url, args.text, out_path)
    print(out_path)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "pptx/rel-target-mode-external--https",
  "kind": "literal",
  "title": "External relationship target mode (pptx)",
  "format": "pptx",
  "category": "opc-packaging",
  "summary": "An external hyperlink relationship on a PresentationML slide must declare TargetMode=\"External\" in ppt/slides/_rels/slide1.xml.rels.",
  "spec": {
    "source": "ecma-376-5-part-2",
    "clause": "9.3",
    "element": "r:Relationship",
    "notes": "ECMA-376 Part 2 (OPC) §9.3 — the TargetMode attribute on a <Relationship> element is optional; when absent the implicit value is Internal. Slide-level hyperlinks set via python-pptx (`run.hyperlink.address = '<url>'`) must emit the hyperlink rel on the slide's rels part with TargetMode=\"External\". Two URI schemes are parameterised (https, mailto) to cover the common cases."
  },
  "fixtures": {
    "machine": "pptx/rel-target-mode-external--https"
  },
  "generator": {
    "python": "scripts/gen_pptx_rel_target_mode_external.py",
    "arg_template": "--url \"{link.url}\" --text \"{link.text}\" --out fixtures/pptx/rel-target-mode-external--{link.id}.pptx"
  },
  "_expansion": {
    "parent_id": "pptx/rel-target-mode-external",
    "bindings": {
      "link": "https"
    }
  },
  "assertions": [
    {
      "id": "slide-hyperlink-rel-exists-https",
      "part": "ppt/slides/_rels/slide1.xml.rels",
      "namespaces": {
        "r": "http://schemas.openxmlformats.org/package/2006/relationships"
      },
      "xpath": "//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']",
      "must": "exist",
      "description": "The slide's rels part must declare a hyperlink relationship whose Target is the fixture URL."
    },
    {
      "id": "slide-hyperlink-target-mode-external-https",
      "part": "ppt/slides/_rels/slide1.xml.rels",
      "namespaces": {
        "r": "http://schemas.openxmlformats.org/package/2006/relationships"
      },
      "xpath": "//r:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink' and @Target='https://example.com/page']/@TargetMode",
      "must": "equal",
      "value": "External",
      "description": "TargetMode on the slide's external hyperlink rel must be 'External' (OPC §9.3)."
    }
  ]
}

Fixture

Download rel-target-mode-external--https.pptx (27.6 KB)

Reference preview

No rendered reference is available for this case.

Spec notes

ECMA-376 Part 2 (OPC) §9.3 — the TargetMode attribute on a <Relationship> element is optional; when absent the implicit value is Internal. Slide-level hyperlinks set via python-pptx (`run.hyperlink.address = '<url>'`) must emit the hyperlink rel on the slide's rels part with TargetMode="External". Two URI schemes are parameterised (https, mailto) to cover the common cases.