print('🟣 MARKDOWN_UTILS.PY: Starting import...', flush=True) #!/usr/bin/env python3 import re import requests import json def send_to_api_and_get_haste_link(markdown_content, document_title): """Send FULL structured markdown to API and get both raw markdown and HTML URLs""" try: print("Sending to API for URLs...", flush=True) # Send the FULL structured markdown - NO STRIPPING, NO CLEANING # Only remove local image references since they won't work online online_markdown = re.sub(r'!\[Slide (\d+)\]\(slides/[^\)]+\)', r'**[Slide \1 Image]**', markdown_content) # First, send to haste.nixc.us for raw markdown raw_haste_url = None try: print(" 📝 Creating raw markdown URL...", flush=True) raw_response = requests.post( "https://haste.nixc.us/documents", data=online_markdown.encode('utf-8'), headers={"Content-Type": "text/plain"}, timeout=30 ) if raw_response.status_code == 200: response_data = raw_response.json() raw_token = response_data.get('key', '') raw_haste_url = f"https://haste.nixc.us/{raw_token}" print(f" ✅ Raw markdown URL created", flush=True) else: print(f" ⚠️ Raw markdown upload failed with status {raw_response.status_code}", flush=True) except Exception as e: print(f" ⚠️ Failed to create raw markdown URL: {e}", flush=True) # Then, send to md.colinknapp.com for HTML version html_url = None try: print(" 🎨 Creating HTML version URL...", flush=True) api_data = { "title": f"Pitch Deck Analysis: {document_title}", "content": online_markdown } response = requests.post( "https://md.colinknapp.com/haste", headers={"Content-Type": "application/json"}, json=api_data, timeout=30 ) if response.status_code == 200: result = response.json() html_url = result.get('url', '') print(f" ✅ HTML version URL created", flush=True) else: print(f" ⚠️ HTML API request failed with status {response.status_code}", flush=True) print(f" Response: {response.text[:200]}", flush=True) except Exception as e: print(f" ⚠️ Failed to create HTML URL: {e}", flush=True) return raw_haste_url, html_url except Exception as e: print(f"⚠️ Failed to send to API: {e}", flush=True) return None, None print('🟣 MARKDOWN_UTILS.PY: Import complete!', flush=True)