all2md.renderers.pptx
PPTX rendering from AST.
This module provides the PptxRenderer class which converts AST nodes to PowerPoint presentations. The renderer uses python-pptx to generate .pptx files with proper slide layouts and formatting.
The rendering process splits the AST into slides using configurable strategies (separator-based or heading-based), converts each slide’s content to PowerPoint shapes, and assembles a complete presentation.
- class all2md.renderers.pptx.PptxRenderer
Bases:
NodeVisitor,BaseRendererRender AST nodes to PPTX format.
This class converts an AST document into a PowerPoint presentation using python-pptx. It splits the document into slides based on configured strategy and generates proper slide layouts and content.
- Parameters:
options (PptxRendererOptions or None, default = None) – PPTX rendering options
Examples
Basic usage:
>>> from all2md.options.pptx import PptxRendererOptions >>> from all2md.ast import Document, Heading, Paragraph, Text >>> from all2md.renderers.pptx import PptxRenderer >>> doc = Document(children=[ ... Heading(level=2, content=[Text(content="Slide 1")]), ... Paragraph(content=[Text(content="Content here")]) ... ]) >>> options = PptxRendererOptions() >>> renderer = PptxRenderer(options) >>> renderer.render(doc, "output.pptx")
Initialize the PPTX renderer with options.
- __init__(options: PptxRendererOptions | None = None)
Initialize the PPTX renderer with options.
- render(doc: Document, output: str | Path | IO[bytes]) None
Render the AST to a PPTX file.
- Parameters:
doc (Document) – AST Document node to render
output (str, Path, or IO[bytes]) – Output destination (file path or file-like object)
- Raises:
DependencyError – If python-pptx is not installed
RenderingError – If PPTX generation fails
- render_to_bytes(doc: Document) bytes
Render the AST to PPTX bytes.
- Returns:
PPTX file content as bytes
- Return type:
bytes
- visit_paragraph(node: Paragraph) None
Render a Paragraph node.
- Parameters:
node (Paragraph) – Paragraph to render
- visit_heading(node: Heading) None
Render a Heading node (non-title headings).
- Parameters:
node (Heading) – Heading to render
- visit_emphasis(node: Emphasis) None
Render an Emphasis node.
- Parameters:
node (Emphasis) – Emphasis to render
- visit_code_block(node: CodeBlock) None
Render a CodeBlock node.
- Parameters:
node (CodeBlock) – Code block to render
- visit_list_item(node: ListItem) None
Render a ListItem node.
- Parameters:
node (ListItem) – List item to render
Notes
Bullet Handling in Text Boxes vs Placeholders:
PowerPoint behaves differently for text boxes vs content placeholders:
Content placeholders: Bullets are enabled by default, setting
p.levelis sufficient to display bullets at the appropriate nesting level.Text boxes: Bullets are disabled by default. Setting
p.levelalone will NOT show bullets. We must explicitly enable bullets via OOXML.
This implementation uses python-pptx’s OOXML API to programmatically enable bullets for unordered lists in all contexts (both placeholders and text boxes).
- visit_block_quote(node: BlockQuote) None
Render block quote as indented text.
- Parameters:
node (BlockQuote) – Block quote to render
- visit_thematic_break(node: ThematicBreak) None
Render thematic break as separator line.
- Parameters:
node (ThematicBreak) – Thematic break to render
- visit_strikethrough(node: Strikethrough) None
Render strikethrough text.
- Parameters:
node (Strikethrough) – Strikethrough to render
- visit_subscript(node: Subscript) None
Render subscript text.
- Parameters:
node (Subscript) – Subscript to render
- visit_superscript(node: Superscript) None
Render superscript text.
- Parameters:
node (Superscript) – Superscript to render
- visit_html_block(node: HTMLBlock) None
Skip HTML blocks in PPTX rendering.
- Parameters:
node (HTMLBlock) – HTML block to skip
- visit_html_inline(node: HTMLInline) None
Skip inline HTML in PPTX rendering.
- Parameters:
node (HTMLInline) – Inline HTML to skip
- visit_footnote_reference(node: FootnoteReference) None
Render footnote reference as superscript number.
- Parameters:
node (FootnoteReference) – Footnote reference to render
- visit_footnote_definition(node: FootnoteDefinition) None
Skip footnote definitions in PPTX rendering.
- Parameters:
node (FootnoteDefinition) – Footnote definition to skip
- visit_math_inline(node: MathInline) None
Render inline math as plain text.
- Parameters:
node (MathInline) – Inline math to render
- visit_math_block(node: MathBlock) None
Render math block as plain text.
- Parameters:
node (MathBlock) – Math block to render
- visit_definition_list(node: DefinitionList) None
Render definition list.
- Parameters:
node (DefinitionList) – Definition list to render
- visit_definition_term(node: DefinitionTerm) None
Render definition term as bold text.
- Parameters:
node (DefinitionTerm) – Definition term to render
- visit_definition_description(node: DefinitionDescription) None
Render definition description as indented text.
- Parameters:
node (DefinitionDescription) – Definition description to render
- visit_comment(node: Comment) None
Render a Comment node according to comment_mode option.
- Parameters:
node (Comment) – Comment block to render
Notes
Supports multiple rendering modes via comment_mode option: - “speaker_notes”: Render in slide speaker notes (default) - “visible”: Render as visible italic text in slide content - “ignore”: Skip comment entirely
- visit_comment_inline(node: CommentInline) None
Render a CommentInline node according to comment_mode option.
- Parameters:
node (CommentInline) – Inline comment to render
Notes
Supports multiple rendering modes via comment_mode option: - “speaker_notes”: Render as italic text (for speaker notes context) - “visible”: Render as italic text (for slide content context) - “ignore”: Skip comment entirely
Both speaker_notes and visible modes render the same way for inline comments - as italic text within the current paragraph.