File size: 3,303 Bytes
46a3f1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | document.addEventListener('DOMContentLoaded', function() {
// Sample markdown content
const sampleMarkdown = `# Welcome to Markdown Slides
## Create Beautiful Presentations
- Write in simple markdown
- Generate professional slides
- Export to PowerPoint
---
## Features
1. **Easy to Use** - Just write markdown
2. **Powerful** - Supports all markdown features
3. **Flexible** - Customize your slides
---
## Get Started
\`\`\`markdown
# Slide Title
- Bullet point 1
- Bullet point 2
\`\`\`
`;
// DOM Elements
const markdownInput = document.getElementById('markdown-input');
const generateBtn = document.getElementById('generate-btn');
const exportBtn = document.getElementById('export-btn');
const slidesPreview = document.getElementById('slides-preview');
const sampleBtn = document.getElementById('sample-btn');
// Load sample markdown
sampleBtn.addEventListener('click', () => {
markdownInput.value = sampleMarkdown;
generateSlides();
});
// Generate slides from markdown
generateBtn.addEventListener('click', generateSlides);
// Export to PPTX
exportBtn.addEventListener('click', exportToPPTX);
function generateSlides() {
const markdown = markdownInput.value.trim();
if (!markdown) return;
// Split markdown by slide separators (---)
const slides = markdown.split(/\n---\n/);
let html = '';
slides.forEach((slide, index) => {
const content = marked.parse(slide);
html += `
<div class="slide">
<div class="slide-title">Slide ${index + 1}</div>
<div class="slide-content">${content}</div>
</div>
`;
});
slidesPreview.innerHTML = html;
exportBtn.disabled = false;
}
function exportToPPTX() {
const markdown = markdownInput.value.trim();
if (!markdown) return;
const slides = markdown.split(/\n---\n/);
const pptx = new PptxGenJS();
slides.forEach(slide => {
const content = marked.parse(slide);
// Create a new slide
const pptxSlide = pptx.addSlide();
// Extract title (first line)
const lines = slide.split('\n');
const title = lines[0].replace(/^#\s+/, '');
// Add title and content
pptxSlide.addText(title, {
x: 0.5, y: 0.5, w: 9, h: 1,
fontSize: 24,
bold: true,
color: '4F46E5'
});
// Add content (remove title from content)
const contentWithoutTitle = lines.slice(1).join('\n');
const htmlContent = marked.parse(contentWithoutTitle);
pptxSlide.addText(htmlContent, {
x: 0.5, y: 1.5, w: 9, h: 5,
fontSize: 18,
color: '4B5563'
});
});
// Download the presentation
pptx.writeFile({ fileName: 'MarkdownSlides.pptx' });
}
// Initialize with sample if empty
if (!markdownInput.value) {
markdownInput.value = sampleMarkdown;
generateSlides();
}
}); |