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/validation/docx.py

View on GitHub
"""
Validator for Word document XML files against XSD schemas.
"""

import re
import tempfile
import zipfile

import lxml.etree

from .base import BaseSchemaValidator


class DOCXSchemaValidator(BaseSchemaValidator):
    """Validator for Word document XML files against XSD schemas."""

    # Word-specific namespace
    WORD_2006_NAMESPACE = "http://schemas.openxmlformats.org/wordprocessingml/2006/main"

    # Word-specific element to relationship type mappings
    # Start with empty mapping - add specific cases as we discover them
    ELEMENT_RELATIONSHIP_TYPES = {}

    def validate(self):
        """Run all validation checks and return True if all pass."""
        # Test 0: XML well-formedness
        if not self.validate_xml():
            return False

        # Test 1: Namespace declarations
        all_valid = True
        if not self.validate_namespaces():
            all_valid = False

        # Test 2: Unique IDs
        if not self.validate_unique_ids():
            all_valid = False

        # Test 3: Relationship and file reference validation
        if not self.validate_file_references():
            all_valid = False

        # Test 4: Content type declarations
        if not self.validate_content_types():
            all_valid = False

        # Test 5: XSD schema validation
        if not self.validate_against_xsd():
            all_valid = False

        # Test 6: Whitespace preservation
        if not self.validate_whitespace_preservation():
            all_valid = False

        # Test 7: Deletion validation
        if not self.validate_deletions():
            all_valid = False

        # Test 8: Insertion validation
        if not self.validate_insertions():
            all_valid = False

        # Test 9: Relationship ID reference validation
        if not self.validate_all_relationship_ids():
            all_valid = False

        # Count and compare paragraphs
        self.compare_paragraph_counts()

        return all_valid

    def validate_whitespace_preservation(self):
        """
        Validate that w:t elements with whitespace have xml:space='preserve'.
        """
        errors = []

        for xml_file in self.xml_files:
            # Only check document.xml files
            if xml_file.name != "document.xml":
                continue

            try:
                root = lxml.etree.parse(str(xml_file)).getroot()

                # Find all w:t elements
                for elem in root.iter(f"{{{self.WORD_2006_NAMESPACE}}}t"):
                    if elem.text:
                        text = elem.text
                        # Check if text starts or ends with whitespace
                        if re.match(r"^\s.*", text) or re.match(r".*\s$", text):
                            # Check if xml:space="preserve" attribute exists
                            xml_space_attr = f"{{{self.XML_NAMESPACE}}}space"
                            if (
                                xml_space_attr not in elem.attrib
                                or elem.attrib[xml_space_attr] != "preserve"
                            ):
                                # Show a preview of the text
                                text_preview = (
                                    repr(text)[:50] + "..."
                                    if len(repr(text)) > 50
                                    else repr(text)
                                )
                                errors.append(
                                    f"  {xml_file.relative_to(self.unpacked_dir)}: "
                                    f"Line {elem.sourceline}: w:t element with whitespace missing xml:space='preserve': {text_preview}"
                                )

            except (lxml.etree.XMLSyntaxError, Exception) as e:
                errors.append(
                    f"  {xml_file.relative_to(self.unpacked_dir)}: Error: {e}"
                )

        if errors:
            print(f"FAILED - Found {len(errors)} whitespace preservation violations:")
            for error in errors:
                print(error)
            return False
        else:
            if self.verbose:
                print("PASSED - All whitespace is properly preserved")
            return True

    def validate_deletions(self):
        """
        Validate that w:t elements are not within w:del elements.
        For some reason, XSD validation does not catch this, so we do it manually.
        """
        errors = []

        for xml_file in self.xml_files:
            # Only check document.xml files
            if xml_file.name != "document.xml":
                continue

            try:
                root = lxml.etree.parse(str(xml_file)).getroot()

                # Find all w:t elements that are descendants of w:del elements
                namespaces = {"w": self.WORD_2006_NAMESPACE}
                xpath_expression = ".//w:del//w:t"
                problematic_t_elements = root.xpath(
                    xpath_expression, namespaces=namespaces
                )
                for t_elem in problematic_t_elements:
                    if t_elem.text:
                        # Show a preview of the text
                        text_preview = (
                            repr(t_elem.text)[:50] + "..."
                            if len(repr(t_elem.text)) > 50
                            else repr(t_elem.text)
                        )
                        errors.append(
                            f"  {xml_file.relative_to(self.unpacked_dir)}: "
                            f"Line {t_elem.sourceline}: <w:t> found within <w:del>: {text_preview}"
                        )

            except (lxml.etree.XMLSyntaxError, Exception) as e:
                errors.append(
                    f"  {xml_file.relative_to(self.unpacked_dir)}: Error: {e}"
                )

        if errors:
            print(f"FAILED - Found {len(errors)} deletion validation violations:")
            for error in errors:
                print(error)
            return False
        else:
            if self.verbose:
                print("PASSED - No w:t elements found within w:del elements")
            return True

    def count_paragraphs_in_unpacked(self):
        """Count the number of paragraphs in the unpacked document."""
        count = 0

        for xml_file in self.xml_files:
            # Only check document.xml files
            if xml_file.name != "document.xml":
                continue

            try:
                root = lxml.etree.parse(str(xml_file)).getroot()
                # Count all w:p elements
                paragraphs = root.findall(f".//{{{self.WORD_2006_NAMESPACE}}}p")
                count = len(paragraphs)
            except Exception as e:
                print(f"Error counting paragraphs in unpacked document: {e}")

        return count

    def count_paragraphs_in_original(self):
        """Count the number of paragraphs in the original docx file."""
        count = 0

        try:
            # Create temporary directory to unpack original
            with tempfile.TemporaryDirectory() as temp_dir:
                # Unpack original docx
                with zipfile.ZipFile(self.original_file, "r") as zip_ref:
                    zip_ref.extractall(temp_dir)

                # Parse document.xml
                doc_xml_path = temp_dir + "/word/document.xml"
                root = lxml.etree.parse(doc_xml_path).getroot()

                # Count all w:p elements
                paragraphs = root.findall(f".//{{{self.WORD_2006_NAMESPACE}}}p")
                count = len(paragraphs)

        except Exception as e:
            print(f"Error counting paragraphs in original document: {e}")

        return count

    def validate_insertions(self):
        """
        Validate that w:delText elements are not within w:ins elements.
        w:delText is only allowed in w:ins if nested within a w:del.
        """
        errors = []

        for xml_file in self.xml_files:
            if xml_file.name != "document.xml":
                continue

            try:
                root = lxml.etree.parse(str(xml_file)).getroot()
                namespaces = {"w": self.WORD_2006_NAMESPACE}

                # Find w:delText in w:ins that are NOT within w:del
                invalid_elements = root.xpath(
                    ".//w:ins//w:delText[not(ancestor::w:del)]",
                    namespaces=namespaces
                )

                for elem in invalid_elements:
                    text_preview = (
                        repr(elem.text or "")[:50] + "..."
                        if len(repr(elem.text or "")) > 50
                        else repr(elem.text or "")
                    )
                    errors.append(
                        f"  {xml_file.relative_to(self.unpacked_dir)}: "
                        f"Line {elem.sourceline}: <w:delText> within <w:ins>: {text_preview}"
                    )

            except (lxml.etree.XMLSyntaxError, Exception) as e:
                errors.append(
                    f"  {xml_file.relative_to(self.unpacked_dir)}: Error: {e}"
                )

        if errors:
            print(f"FAILED - Found {len(errors)} insertion validation violations:")
            for error in errors:
                print(error)
            return False
        else:
            if self.verbose:
                print("PASSED - No w:delText elements within w:ins elements")
            return True

    def compare_paragraph_counts(self):
        """Compare paragraph counts between original and new document."""
        original_count = self.count_paragraphs_in_original()
        new_count = self.count_paragraphs_in_unpacked()

        diff = new_count - original_count
        diff_str = f"+{diff}" if diff > 0 else str(diff)
        print(f"\nParagraphs: {original_count} → {new_count} ({diff_str})")


if __name__ == "__main__":
    raise RuntimeError("This module should not be run directly.")
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