pptx2md Documentation

repository·master·Indexed 22 days ago

https://github.com/ssine/pptx2md

A tool and Python library (version 2.0.6) for converting PowerPoint (.pptx) files into Markdown formats, including standard Markdown, TiddlyWiki, Madoko, and Quarto. It preserves lists, bold/italic text, hyperlinks, images, and tables with merged cells. The tool provides both a CLI and a Python API via the `convert` function and `ConversionConfig` class, allowing for custom title hierarchies, image extraction control, and multi-column slide detection.

Tokens
3.9K
Snippets
9
Records
19
Agent score
73%

What's inside pptx2md

  1. Configure custom title hierarchies

    master

    By default, all PPTX titles are parsed as level 1 markdown titles. To create a hierarchical table of contents, provide a predefined title list using the -t argument.

    Title File Format: Use indentation (spaces) to define heading levels. The number of spaces in the first indented line determines the indentation unit.

    Example titles.txt:

    Heading 1
      Heading 1.1
        Heading 1.1.1
      Heading 1.2

    Matching Logic:

    • Titles are matched using fuzzy matching (score must be > 92).
    • Unmatched titles default to the deepest header level.
    • Similar titles (score > 92) are omitted by default unless --keep-similar-titles is used.

    Usage:

    pptx2md [filename] -t titles.txt
  2. Convert PPTX to Markdown via CLI

    master

    Use the pptx2md command followed by the path to your .pptx file.

    Note: Older .ppt files are not supported; convert them to .pptx before use.

    By default, the output is saved as out.md and extracted images are placed in an /img/ folder.

    pptx2md [pptx filename]
  3. Understand the parsed data structure: ParsedPresentation

    master

    The ParsedPresentation object is the top-level container for the results of a conversion. It contains a list of Slide objects.

    A Slide can be one of two types:

    1. GeneralSlide: A standard slide containing a list of elements (Title, Paragraph, etc.) and optional notes.
    2. MultiColumnSlide: A slide with a preface section followed by multiple columns, each containing its own elements.

    Element Types (ElementType):

    • Title
    • ListItem
    • Paragraph
    • Image
    • Table
  4. Use the pptx2md Python API

    master

    You can integrate pptx2md into your Python projects using the convert function and the ConversionConfig class. The ConversionConfig object accepts the same parameters as the CLI.

    from pptx2md import convert, ConversionConfig
    from pathlib import Path
    
    # Basic usage
    convert(
        ConversionConfig(
            pptx_path=Path('presentation.pptx'),
            output_path=Path('output.md'),
            image_dir=Path('img'),
            disable_notes=True
        )
    )
  5. Configure conversion with ConversionConfig

    master

    The ConversionConfig class (a Pydantic model) defines the settings for the PowerPoint to Markdown conversion process. Use it to specify input/output paths and toggle various processing features like image extraction, color tags, or specific markdown flavors.

    Key Configuration Options:

    • pptx_path: Path to the source .pptx file.
    • output_path: Path where the markdown file will be saved.
    • image_dir: Directory for extracted images.
    • disable_image: If True, skips image extraction.
    • enable_slides: If True, delineates slides using \n---\n.
    • is_wiki, is_mdk, is_qmd: Toggles for specific markdown formats (TiddlyWiki, Madoko, or Quarto).
    • custom_titles: A dictionary mapping custom titles to their heading levels.
    • try_multi_column: Enables detection of multi-column slide layouts.
  6. Reference the pptx2md CLI arguments

    master

    The following flags are available for the pptx2md command line interface:

    FlagDescription
    -t [filename]Provide the title file
    -o [filename]Path of the output file
    -i [path]Directory of the extracted pictures
    --image-width [width]Maximum width of the pictures in px (uses HTML <img> tags)
    --disable-imageDisable image extraction
    --disable-escapingDo not attempt to escape special characters
    --disable-notesDo not add presenter notes
    --disable-wmfKeep WMF formatted images untouched (avoids Linux exceptions)
    --disable-colorDisable color tags in HTML
    --enable-slidesDelineate slides using \n---\n
    --try-multi-columnTry to detect multi-column slides (slow)
    --min-block-size [size]Minimum number of characters for a text block to be outputted
    --wikiOutput in TiddlyWiki wikitext format
    --mdkOutput in Madoko format
    --qmdOutput in Quarto (qmd) format
    --page [number]Only convert the specified page
    --keep-similar-titlesKeep similar titles and add (cont.) to repeated slide titles
  7. Use Formatter classes to export presentation data

    master

    The Formatter class and its subclasses are responsible for converting ParsedPresentation data into specific text formats. You can instantiate a specific formatter based on your target output format and call its .output(presentation_data) method.

    Available formatters:

    • MarkdownFormatter: Standard Markdown output.
    • WikiFormatter: Wikitext format.
    • MadokoFormatter: Madoko-flavored Markdown (includes a Table of Contents).
    • QuartoFormatter: Quarto Markdown specifically optimized for revealjs presentations.

    Each formatter requires a ConversionConfig object during initialization to handle paths and formatting preferences (like color or escaping).

  8. Convert PPTX to Markdown or other formats using convert()

    master

    The convert function is the primary entry point for programmatically converting PowerPoint (.pptx) files into Markdown, Wiki, Madoko, or Quarto formats. It accepts a ConversionConfig object which defines the input path, output path, and formatting preferences.

    Workflow:

    1. If config.title_path is provided, custom titles are prepared from that path.
    2. The PPTX file is loaded.
    3. The content is parsed into an Abstract Syntax Tree (AST).
    4. If the output_path ends in .json, the AST is saved as a JSON file.
    5. Otherwise, the AST is passed to a formatter (Wiki, Madoko, Quarto, or standard Markdown) based on the configuration flags, and the resulting document is written to the output_path.
  9. Reference: pptx2md CLI arguments

    master

    The following arguments are available for the pptx2md command:

    ArgumentFlagDescription
    pptx_path(positional)Path to the .pptx file to be converted
    title-t, --titlePath to a custom title list file
    output-o, --outputPath of the output file
    image-dir-i, --image-dirDirectory where extracted images will be stored
    image-width--image-widthMaximum image width in pixels
    disable-image--disable-imageDisable image extraction
    disable-wmf--disable-wmfKeep WMF formatted images untouched (avoids exceptions on Linux)
    disable-color--disable-colorDo not add color HTML tags
    disable-escaping--disable-escapingDo not attempt to escape special characters
    disable-notes--disable-notesDo not add presenter notes
    enable-slides--enable-slidesDelineate slides using \n---\n
    try-multi-column--try-multi-columnAttempt to detect multi-column slides
    wiki--wikiGenerate output as wikitext (TiddlyWiki)
    mdk--mdkGenerate output as Madoko markdown
    qmd--qmdGenerate output as Quarto markdown presentation
    min-block-size--min-block-sizeMinimum character count for a text block to be converted (default: 15)
    page--pageOnly convert the specified page number
    keep-similar-titles--keep-similar-titlesKeep similar titles (allows repeated slide titles by adding '(cont.)')
  10. Reference: Element Types and Data Models

    master

    The following models define the individual components extracted from slides:

    • TitleElement: Contains content (str) and level (int).
    • ListItemElement: Contains content (List of TextRun) and level (int).
    • ParagraphElement: Contains content (List of TextRun).
    • ImageElement: Contains path (str), width (Optional[int]), original_ext (str), and alt_text (str).
    • TableElement: Contains content (a 3D list: rows -> cols -> List[TextRun]).

    TextRun and TextStyle provide rich text information:

    • TextRun: text (str) and style (TextStyle).
    • TextStyle: is_accent (bool), is_strong (bool), color_rgb (Optional[tuple[int, int, int]]), and hyperlink (Optional[str]).
    # Summary of Element schemas
    class TitleElement(BaseElement):
        type: ElementType = ElementType.Title
        content: str
        level: int
    
    class ListItemElement(BaseElement):
        type: ElementType = ElementType.ListItem
        content: List[TextRun]
        level: int = 1
    
    class ParagraphElement(BaseElement):
        type: ElementType = ElementType.Paragraph
        content: List[TextRun]
    
    class ImageElement(BaseElement):
        type: ElementType = ElementType.Image
        path: str
        width: Optional[int] = None
        original_ext: str = ""
        alt_text: str = ""
    
    class TableElement(BaseElement):
        type: ElementType = ElementType.Table
        content: List[List[List[TextRun]]]