#!/usr/bin/env python3
"""
Convert Markdown slides to HTML presentation
"""
import re
from pathlib import Path
def convert_md_to_html(md_file, output_file):
"""Convert Markdown to HTML presentation"""
# Read markdown content
with open(md_file, 'r', encoding='utf-8') as f:
content = f.read()
# Split by --- to get individual slides
slides = content.split('\n---\n')
# HTML template with reveal.js-like styling
html = """
"""
# Process each slide
slide_html = []
for i, slide in enumerate(slides):
if not slide.strip():
continue
# Check if it's a lead slide
is_lead = '' in slide
# Remove marp directives
slide = re.sub(r'', '', slide, flags=re.DOTALL)
slide = re.sub(r'^---.*?$', '', slide, flags=re.MULTILINE)
# Convert markdown to HTML (basic conversion)
slide = re.sub(r'^# (.*?)$', r'
\1
', slide, flags=re.MULTILINE)
slide = re.sub(r'^## (.*?)$', r'
\1
', slide, flags=re.MULTILINE)
slide = re.sub(r'^### (.*?)$', r'
\1
', slide, flags=re.MULTILINE)
slide = re.sub(r'^#### (.*?)$', r'
\1
', slide, flags=re.MULTILINE)
# Convert bold and italic
slide = re.sub(r'\*\*(.*?)\*\*', r'
\1', slide)
slide = re.sub(r'\*(.*?)\*', r'
\1', slide)
# Convert lists
slide = re.sub(r'^- (.*?)$', r'
\1', slide, flags=re.MULTILINE)
slide = re.sub(r'(
.*?)', r'
', slide, flags=re.DOTALL)
slide = re.sub(r'\s*
', '', slide)
# Convert code blocks
slide = re.sub(r'```(.*?)```', r'
\1
', slide, flags=re.DOTALL)
# Convert tables
lines = slide.split('\n')
in_table = False
table_html = []
processed_lines = []
for line in lines:
if '|' in line and not line.strip().startswith('<'):
if not in_table:
in_table = True
table_html = ['
']
cells = [cell.strip() for cell in line.split('|')[1:-1]]
if all(set(cell) <= {'-', ' ', ':'} for cell in cells):
continue # Skip separator line
if len(table_html) == 1: # First row (header)
table_html.append('')
for cell in cells:
table_html.append(f'| {cell} | ')
table_html.append('
')
else:
table_html.append('')
for cell in cells:
table_html.append(f'| {cell} | ')
table_html.append('
')
else:
if in_table:
table_html.append('
')
processed_lines.append(''.join(table_html))
in_table = False
table_html = []
processed_lines.append(line)
if in_table:
table_html.append('')
processed_lines.append(''.join(table_html))
slide = '\n'.join(processed_lines)
# Wrap paragraphs
slide = re.sub(r'^([^<\n][^\n]*?)$', r'
\1
', slide, flags=re.MULTILINE)
lead_class = ' lead' if is_lead else ''
active_class = ' active' if i == 0 else ''
slide_html.append(f'
\n{slide}\n
')
html += '\n'.join(slide_html)
# Add controls and JavaScript
html += """