Untitled

 avatar
unknown
python
a year ago
1.8 kB
5
Indexable
from pptx import Presentation
from pptx.util import Inches, Pt
import reveal_slides as rs

def create_pptx_from_reveal_config(content, reveal_config, output_file):
    prs = Presentation()
    
    # Map reveal.js theme to PowerPoint theme (simplified)
    theme_mapping = {
        'black': prs.slide_layouts[0],
        'white': prs.slide_layouts[1],
        # Add more mappings as needed
    }
    
    # Use reveal.js theme to select PowerPoint layout
    slide_layout = theme_mapping.get(reveal_config.get('theme', 'black'), prs.slide_layouts[0])
    
    # Split content into slides
    slides = content.split('---')
    
    for slide_content in slides:
        slide = prs.slides.add_slide(slide_layout)
        
        # Add text to slide
        title_shape = slide.shapes.title
        body_shape = slide.shapes.placeholders[1]
        
        # Simple parsing of markdown (you might need a more robust parser)
        lines = slide_content.strip().split('\n')
        if lines:
            title_shape.text = lines[0].lstrip('#').strip()
            body_shape.text = '\n'.join(lines[1:])
        
        # Apply font size from reveal.js config
        font_size = reveal_config.get('fontSize', 24)
        for paragraph in body_shape.text_frame.paragraphs:
            paragraph.font.size = Pt(font_size)
    
    # Save the presentation
    prs.save(output_file)

# Example usage
content_markdown = """
# Slide 1
Content for slide 1
---
# Slide 2
Content for slide 2
"""

reveal_config = {
    'theme': 'black',
    'transition': 'slide',
    'fontSize': 24,
    # Other reveal.js config parameters
}

create_pptx_from_reveal_config(content_markdown, reveal_config, 'output.pptx')
Editor is loading...
Leave a Comment