An external hyperlink relationship on a PresentationML slide must declare TargetMode="External" in ppt/slides/_rels/slide1.xml.rels.
| Feature ID | Axis bindings | python-pptx | pptxjs |
|---|---|---|---|
pptx/rel-target-mode-external--https | link=https | — | — |
pptx/rel-target-mode-external--mailto | link=mailto | — | — |
| Library | Pass | Fail | Pending |
|---|---|---|---|
python-pptx | 0 | 0 | 2 |
pptxjs | 0 | 0 | 2 |
link (2 values): https, mailtoscripts/gen_pptx_rel_target_mode_external.py — runs with --arg_template --url "{link.url}" --text "{link.text}" --out fixtures/pptx/rel-target-mode-external--{link.id}.pptx
#!/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())
{
"$schema": "../manifest.schema.json",
"id": "pptx/rel-target-mode-external",
"kind": "parameterised",
"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"
},
"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"
},
"parameters": {
"link": [
{
"id": "https",
"url": "https://example.com/page",
"text": "Visit example HTTPS"
},
{
"id": "mailto",
"url": "mailto:contact@example.com",
"text": "Send email"
}
]
},
"assertions_template": [
{
"id": "slide-hyperlink-rel-exists-{link.id}",
"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='{link.url}']",
"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-{link.id}",
"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='{link.url}']/@TargetMode",
"must": "equal",
"value": "External",
"description": "TargetMode on the slide's external hyperlink rel must be 'External' (OPC §9.3)."
}
]
}