#!/usr/bin/env python3 """ Markdown to HTML Converter for Cursor AI Transcripts Converts markdown chat transcripts to styled HTML files for better browser viewing. Usage: python3 md_to_html_converter.py [title] [description] Example: python3 md_to_html_converter.py cursor_chats/example.md cursor_chats/example.html "Example Chat" "Example conversation transcript" """ import sys import re import os from datetime import datetime def create_html_template(title, description, back_link="../week1.html"): """Create the HTML template with consistent styling.""" return f""" Cursor AI Transcript · {title} · HTMAA 2025
Saleem A. Al Dajani

{title}

Cursor AI Transcript · HTMAA 2025

Overview

{description}

Full Conversation

{{CONTENT_PLACEHOLDER}}

Download Options

For the complete technical details and full conversation transcript:

© 2025 Saleem A. Al Dajani
HTMAA 2025 • Cursor AI Transcript
""" def parse_markdown_to_html(md_content): """Parse markdown content and convert to HTML message format.""" lines = md_content.split('\n') messages = [] current_message = None current_content = [] for line in lines: # Check for user/assistant headers if line.startswith('**User**'): if current_message: current_message['content'] = current_content messages.append(current_message) current_message = { 'author': 'user', 'content': [], 'time': 'Unknown' } current_content = [] elif line.startswith('**Cursor**') or line.startswith('**Assistant**'): if current_message: current_message['content'] = current_content messages.append(current_message) current_message = { 'author': 'assistant', 'content': [], 'time': 'Unknown' } current_content = [] elif line.startswith('---'): # Skip separator lines continue elif current_message and line.strip(): # Add content to current message current_content.append(line) elif current_message and not line.strip(): # Empty line - add to content if we have content if current_content: current_content.append('') # Add the last message if current_message: current_message['content'] = current_content messages.append(current_message) # Convert messages to HTML html_messages = [] for msg in messages: if not msg['content']: continue content_html = convert_markdown_content('\n'.join(msg['content'])) html_message = f"""
{msg['author'].title()} {msg['time']}
{content_html}
""" html_messages.append(html_message) return '\n'.join(html_messages) def convert_markdown_content(content): """Convert markdown content to HTML.""" # Basic markdown to HTML conversion html = content # Convert code blocks html = re.sub(r'```(\w+)?\n(.*?)\n```', r'
\2
', html, flags=re.DOTALL) # Convert inline code html = re.sub(r'`([^`]+)`', r'\1', html) # Convert bold html = re.sub(r'\*\*(.*?)\*\*', r'\1', html) # Convert italic html = re.sub(r'\*(.*?)\*', r'\1', html) # Convert headers html = re.sub(r'^### (.*?)$', r'

\1

', html, flags=re.MULTILINE) html = re.sub(r'^## (.*?)$', r'

\1

', html, flags=re.MULTILINE) html = re.sub(r'^# (.*?)$', r'

\1

', html, flags=re.MULTILINE) # Convert lists html = re.sub(r'^- (.*?)$', r'
  • \1
  • ', html, flags=re.MULTILINE) html = re.sub(r'(
  • .*
  • )', r'', html, flags=re.DOTALL) # Convert paragraphs paragraphs = html.split('\n\n') html_paragraphs = [] for para in paragraphs: para = para.strip() if para and not para.startswith('<'): para = f'

    {para}

    ' html_paragraphs.append(para) html = '\n\n'.join(html_paragraphs) return html def main(): if len(sys.argv) < 3: print("Usage: python3 md_to_html_converter.py [title] [description]") sys.exit(1) input_file = sys.argv[1] output_file = sys.argv[2] title = sys.argv[3] if len(sys.argv) > 3 else "Cursor AI Transcript" description = sys.argv[4] if len(sys.argv) > 4 else "Complete transcript of Cursor AI assistance" try: # Read markdown file with open(input_file, 'r', encoding='utf-8') as f: md_content = f.read() # Parse and convert to HTML html_content = parse_markdown_to_html(md_content) # Create HTML template template = create_html_template(title, description) # Replace content placeholder final_html = template.replace('{CONTENT_PLACEHOLDER}', html_content) # Write HTML file with open(output_file, 'w', encoding='utf-8') as f: f.write(final_html) print(f"Successfully converted {input_file} to {output_file}") except FileNotFoundError: print(f"Error: File {input_file} not found") sys.exit(1) except Exception as e: print(f"Error: {e}") sys.exit(1) if __name__ == "__main__": main()