siril9/presentation-skill / plugins/presentation-skill/skills/presentation-skill
presentation-skill
FlaggedBuild, edit, redesign, render, and verify content-led, structurally diverse, clean, editable, reproducible PowerPoint `.pptx` decks. Use for scientific, lab, clinical, consulting, board, investor, editorial, policy, and operational presentations where alignment, readability, contrast, and balanced density matter.
scripts/edit_deck.py
View on GitHub"""Edit an existing .pptx file in place-style (input -> output).
Three subcommands cover the most common edits on decks you didn't generate:
- `replace-text`: find/replace across every shape text frame and run.
- `list-slides`: print a 1-based index + title summary of each slide.
- `delete-slide`: drop a slide (1-based) and its presentation relationship.
These operations use python-pptx only. For XML-level edits python-pptx can't
express, use `unpack_pptx.py` / `pack_pptx.py` instead.
"""
from __future__ import annotations
import argparse
import sys
from pathlib import Path
from typing import Any
from pptx import Presentation
def _resolve_input(path_str: str) -> Path:
path = Path(path_str).expanduser().resolve()
if not path.exists():
print(f"Error: input file not found: {path}", file=sys.stderr)
raise SystemExit(2)
if not path.is_file():
print(f"Error: input is not a file: {path}", file=sys.stderr)
raise SystemExit(2)
return path
def _resolve_output(path_str: str) -> Path:
path = Path(path_str).expanduser().resolve()
path.parent.mkdir(parents=True, exist_ok=True)
return path
def _guard_output(output_path: Path, input_path: Path, overwrite: bool) -> None:
"""Refuse clobbering and same-path writes. Raises SystemExit(3) on failure."""
if output_path.resolve() == input_path.resolve():
print(
f"Error: --output resolves to the same path as --input: {output_path}. "
f"Point --output to a different file.",
file=sys.stderr,
)
raise SystemExit(3)
if output_path.exists() and not overwrite:
print(
f"Error: output exists (use --overwrite to replace): {output_path}",
file=sys.stderr,
)
raise SystemExit(3)
def _title_text(slide: Any) -> str:
try:
title_shape = slide.shapes.title
if title_shape is not None:
return (title_shape.text or "").strip()
except Exception:
pass
return ""
def _iter_text_frames(shape: Any) -> Any:
"""Yield text frames from a shape.
Descends into group shapes and table cells. Does NOT visit chart,
SmartArt, or slide-master text (see references/editing.md).
"""
# Group shape: recurse into children. Groups can themselves contain
# tables, so we route through the same dispatcher.
if getattr(shape, "shape_type", None) is not None and hasattr(shape, "shapes"):
for child in shape.shapes:
yield from _iter_text_frames(child)
return
# Table: visit every cell's text frame.
if getattr(shape, "has_table", False):
table = shape.table
for row in table.rows:
for cell in row.cells:
cell_frame = getattr(cell, "text_frame", None)
if cell_frame is not None:
yield cell_frame
return
if getattr(shape, "has_text_frame", False):
yield shape.text_frame
def _replace_in_runs(text_frame: Any, find: str, replace: str) -> int:
"""Replace occurrences of `find` inside every run of `text_frame`.
Run-level replacement preserves formatting. Matches that span run
boundaries will not be caught; this mirrors how most tooling treats
python-pptx replacements.
"""
count = 0
for paragraph in text_frame.paragraphs:
for run in paragraph.runs:
if run.text and find in run.text:
count += run.text.count(find)
run.text = run.text.replace(find, replace)
return count
def _cmd_replace_text(args: argparse.Namespace) -> int:
if args.find == "":
print("Error: --find must be a non-empty string", file=sys.stderr)
return 2
input_path = _resolve_input(args.input)
output_path = _resolve_output(args.output)
_guard_output(output_path, input_path, args.overwrite)
presentation = Presentation(str(input_path))
total = 0
for slide in presentation.slides:
for shape in slide.shapes:
for text_frame in _iter_text_frames(shape):
total += _replace_in_runs(text_frame, args.find, args.replace)
if getattr(slide, "has_notes_slide", False):
notes_frame = slide.notes_slide.notes_text_frame
total += _replace_in_runs(notes_frame, args.find, args.replace)
if total == 0 and args.require_match:
print(
f"Error: --require-match set but 0 occurrence(s) of {args.find!r} found; "
f"output not written.",
file=sys.stderr,
)
return 4
presentation.save(str(output_path))
print(f"Replaced {total} occurrence(s) of {args.find!r} -> {args.replace!r}")
print(f"Wrote {output_path}")
return 0
def _cmd_list_slides(args: argparse.Namespace) -> int:
input_path = _resolve_input(args.input)
presentation = Presentation(str(input_path))
print(f"File: {input_path}")
print(f"Slides: {len(presentation.slides)}")
for idx, slide in enumerate(presentation.slides, start=1):
title = _title_text(slide) or "(No title)"
print(f" {idx:>3}. {title}")
return 0
def _cmd_delete_slide(args: argparse.Namespace) -> int:
input_path = _resolve_input(args.input)
output_path = _resolve_output(args.output)
_guard_output(output_path, input_path, args.overwrite)
presentation = Presentation(str(input_path))
slides = presentation.slides
total = len(slides)
index = int(args.index)
if index < 1 or index > total:
print(
f"Error: --index {index} out of range (deck has {total} slide(s))",
file=sys.stderr,
)
return 2
# python-pptx has no public delete API. We remove the sldId entry from the
# presentation's sldIdLst and drop the matching relationship. The slide
# part itself is left in the package; PowerPoint ignores orphaned parts.
zero_based = index - 1
slide_id_list = slides._sldIdLst # type: ignore[attr-defined]
sld_id_elements = list(slide_id_list)
target = sld_id_elements[zero_based]
rId = target.rId
slide_id_list.remove(target)
presentation.part.drop_rel(rId)
presentation.save(str(output_path))
print(f"Deleted slide {index} of {total}; wrote {output_path}")
return 0
def _build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description="Edit an existing .pptx deck (text replace, slide list, slide delete).",
)
sub = parser.add_subparsers(dest="command", required=True)
replace = sub.add_parser(
"replace-text",
help="Replace text across shapes, table cells, groups, and notes.",
)
replace.add_argument("--input", required=True, help="Input .pptx path")
replace.add_argument("--output", required=True, help="Output .pptx path")
replace.add_argument("--find", required=True, help="Exact substring to find")
replace.add_argument("--replace", required=True, help="Replacement substring")
replace.add_argument(
"--overwrite",
action="store_true",
help="Allow overwriting an existing --output file",
)
replace.add_argument(
"--require-match",
action="store_true",
help="Exit non-zero (4) if 0 occurrences are replaced",
)
replace.set_defaults(func=_cmd_replace_text)
listing = sub.add_parser(
"list-slides",
help="Print a 1-based index + title for every slide.",
)
listing.add_argument("--input", required=True, help="Input .pptx path")
listing.set_defaults(func=_cmd_list_slides)
delete = sub.add_parser(
"delete-slide",
help="Delete a slide by 1-based index.",
)
delete.add_argument("--input", required=True, help="Input .pptx path")
delete.add_argument("--output", required=True, help="Output .pptx path")
delete.add_argument(
"--index",
required=True,
type=int,
help="1-based slide index to delete",
)
delete.add_argument(
"--overwrite",
action="store_true",
help="Allow overwriting an existing --output file",
)
delete.set_defaults(func=_cmd_delete_slide)
return parser
def main() -> int:
parser = _build_parser()
args = parser.parse_args()
return int(args.func(args))
if __name__ == "__main__":
try:
raise SystemExit(main())
except SystemExit:
raise
except Exception as exc: # pragma: no cover - CLI error path
print(f"Error: {exc}", file=sys.stderr)
raise SystemExit(1)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |