Skip to content

VidyFoo/antigravity-skill-engine / .agent/skills/4-tools/pptx-creating

pptx-creating

Verified

PPTX 演示文稿创建、编辑与分析。支持:(1) 从零创建演示文稿 (2) 编辑现有内容 (3) 使用模板创建 (4) 添加评论或演讲者备注。Presentation creation, editing, and analysis using html2pptx and OOXML.

FileKindSize
LICENSE.txtmarkdown1.4 KB
SKILL.mdskill md24.9 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-chart.xsdother73.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-chartDrawing.xsdother6.8 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-diagram.xsdother50.1 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-lockedCanvas.xsdother624 B
ooxml/schemas/ISO-IEC29500-4_2016/dml-main.xsdother148.5 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-picture.xsdother1.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-spreadsheetDrawing.xsdother8.7 KB
ooxml/schemas/ISO-IEC29500-4_2016/dml-wordprocessingDrawing.xsdother14.4 KB
ooxml/schemas/ISO-IEC29500-4_2016/pml.xsdother81.7 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-additionalCharacteristics.xsdother1.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-bibliography.xsdother7.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-commonSimpleTypes.xsdother6.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlDataProperties.xsdother1.2 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-customXmlSchemaProperties.xsdother880 B
ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesCustom.xsdother2.5 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesExtended.xsdother3.4 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-documentPropertiesVariantTypes.xsdother7.3 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-math.xsdother22.8 KB
ooxml/schemas/ISO-IEC29500-4_2016/shared-relationshipReference.xsdother1.3 KB
ooxml/schemas/ISO-IEC29500-4_2016/sml.xsdother236.6 KB
ooxml/schemas/ISO-IEC29500-4_2016/vml-main.xsdother25.5 KB
ooxml/schemas/ISO-IEC29500-4_2016/vml-officeDrawing.xsdother24.7 KB
ooxml/schemas/ISO-IEC29500-4_2016/vml-presentationDrawing.xsdother535 B
ooxml/schemas/ISO-IEC29500-4_2016/vml-spreadsheetDrawing.xsdother5.6 KB
ooxml/schemas/ISO-IEC29500-4_2016/vml-wordprocessingDrawing.xsdother3.9 KB
ooxml/schemas/ISO-IEC29500-4_2016/wml.xsdother167.4 KB
ooxml/schemas/ISO-IEC29500-4_2016/xml.xsdother4.5 KB
ooxml/schemas/ecma/fouth-edition/opc-contentTypes.xsdother1.9 KB
ooxml/schemas/ecma/fouth-edition/opc-coreProperties.xsdother2.5 KB
ooxml/schemas/ecma/fouth-edition/opc-digSig.xsdother2.8 KB
ooxml/schemas/ecma/fouth-edition/opc-relationships.xsdother1.3 KB
ooxml/schemas/mce/mc.xsdother3.1 KB
ooxml/schemas/microsoft/wml-2010.xsdother25.9 KB
ooxml/schemas/microsoft/wml-2012.xsdother3.7 KB
ooxml/schemas/microsoft/wml-2018.xsdother901 B
ooxml/schemas/microsoft/wml-cex-2018.xsdother1.7 KB
ooxml/schemas/microsoft/wml-cid-2016.xsdother1002 B
ooxml/schemas/microsoft/wml-sdtdatahash-2020.xsdother600 B
ooxml/schemas/microsoft/wml-symex-2015.xsdother745 B
ooxml/scripts/pack.pyscript5.5 KB
ooxml/scripts/unpack.pyscript1.0 KB
ooxml/scripts/validate.pyscript1.9 KB
ooxml/scripts/validation/__init__.pyscript336 B
ooxml/scripts/validation/base.pyscript39.0 KB
ooxml/scripts/validation/docx.pyscript9.8 KB
ooxml/scripts/validation/pptx.pyscript12.0 KB
ooxml/scripts/validation/redlining.pyscript10.9 KB
resources/html2pptx.mdmarkdown19.4 KB
resources/ooxml.mdmarkdown10.1 KB
scripts/html2pptx.jsscript36.9 KB
scripts/inventory.pyscript37.2 KB
scripts/rearrange.pyscript8.3 KB
scripts/replace.pyscript13.3 KB
scripts/thumbnail.pyscript15.1 KB

ooxml/scripts/pack.py

View on GitHub
#!/usr/bin/env python3
"""
Tool to pack a directory into a .docx, .pptx, or .xlsx file with XML formatting undone.

Example usage:
    python pack.py <input_directory> <office_file> [--force]
"""

import argparse
import shutil
import subprocess
import sys
import tempfile
import defusedxml.minidom
import zipfile
from pathlib import Path


def main():
    parser = argparse.ArgumentParser(description="Pack a directory into an Office file")
    parser.add_argument("input_directory", help="Unpacked Office document directory")
    parser.add_argument("output_file", help="Output Office file (.docx/.pptx/.xlsx)")
    parser.add_argument("--force", action="store_true", help="Skip validation")
    args = parser.parse_args()

    try:
        success = pack_document(
            args.input_directory, args.output_file, validate=not args.force
        )

        # Show warning if validation was skipped
        if args.force:
            print("Warning: Skipped validation, file may be corrupt", file=sys.stderr)
        # Exit with error if validation failed
        elif not success:
            print("Contents would produce a corrupt file.", file=sys.stderr)
            print("Please validate XML before repacking.", file=sys.stderr)
            print("Use --force to skip validation and pack anyway.", file=sys.stderr)
            sys.exit(1)

    except ValueError as e:
        sys.exit(f"Error: {e}")


def pack_document(input_dir, output_file, validate=False):
    """Pack a directory into an Office file (.docx/.pptx/.xlsx).

    Args:
        input_dir: Path to unpacked Office document directory
        output_file: Path to output Office file
        validate: If True, validates with soffice (default: False)

    Returns:
        bool: True if successful, False if validation failed
    """
    input_dir = Path(input_dir)
    output_file = Path(output_file)

    if not input_dir.is_dir():
        raise ValueError(f"{input_dir} is not a directory")
    if output_file.suffix.lower() not in {".docx", ".pptx", ".xlsx"}:
        raise ValueError(f"{output_file} must be a .docx, .pptx, or .xlsx file")

    # Work in temporary directory to avoid modifying original
    with tempfile.TemporaryDirectory() as temp_dir:
        temp_content_dir = Path(temp_dir) / "content"
        shutil.copytree(input_dir, temp_content_dir)

        # Process XML files to remove pretty-printing whitespace
        for pattern in ["*.xml", "*.rels"]:
            for xml_file in temp_content_dir.rglob(pattern):
                condense_xml(xml_file)

        # Create final Office file as zip archive
        output_file.parent.mkdir(parents=True, exist_ok=True)
        with zipfile.ZipFile(output_file, "w", zipfile.ZIP_DEFLATED) as zf:
            for f in temp_content_dir.rglob("*"):
                if f.is_file():
                    zf.write(f, f.relative_to(temp_content_dir))

        # Validate if requested
        if validate:
            if not validate_document(output_file):
                output_file.unlink()  # Delete the corrupt file
                return False

    return True


def validate_document(doc_path):
    """Validate document by converting to HTML with soffice."""
    # Determine the correct filter based on file extension
    match doc_path.suffix.lower():
        case ".docx":
            filter_name = "html:HTML"
        case ".pptx":
            filter_name = "html:impress_html_Export"
        case ".xlsx":
            filter_name = "html:HTML (StarCalc)"

    with tempfile.TemporaryDirectory() as temp_dir:
        try:
            result = subprocess.run(
                [
                    "soffice",
                    "--headless",
                    "--convert-to",
                    filter_name,
                    "--outdir",
                    temp_dir,
                    str(doc_path),
                ],
                capture_output=True,
                timeout=10,
                text=True,
            )
            if not (Path(temp_dir) / f"{doc_path.stem}.html").exists():
                error_msg = result.stderr.strip() or "Document validation failed"
                print(f"Validation error: {error_msg}", file=sys.stderr)
                return False
            return True
        except FileNotFoundError:
            print("Warning: soffice not found. Skipping validation.", file=sys.stderr)
            return True
        except subprocess.TimeoutExpired:
            print("Validation error: Timeout during conversion", file=sys.stderr)
            return False
        except Exception as e:
            print(f"Validation error: {e}", file=sys.stderr)
            return False


def condense_xml(xml_file):
    """Strip unnecessary whitespace and remove comments."""
    with open(xml_file, "r", encoding="utf-8") as f:
        dom = defusedxml.minidom.parse(f)

    # Process each element to remove whitespace and comments
    for element in dom.getElementsByTagName("*"):
        # Skip w:t elements and their processing
        if element.tagName.endswith(":t"):
            continue

        # Remove whitespace-only text nodes and comment nodes
        for child in list(element.childNodes):
            if (
                child.nodeType == child.TEXT_NODE
                and child.nodeValue
                and child.nodeValue.strip() == ""
            ) or child.nodeType == child.COMMENT_NODE:
                element.removeChild(child)

    # Write back the condensed XML
    with open(xml_file, "wb") as f:
        f.write(dom.toxml(encoding="UTF-8"))


if __name__ == "__main__":
    main()
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: 197kUpdated Claude CodeCodexVerifiedInstall
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: 197kUpdated Claude CodeCodexVerifiedInstall
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: 197kUpdated Claude CodeCodexVerifiedInstall
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: 197kUpdated Claude CodeCodexVerifiedInstall