html_template = """ {content} """ import markdown from weasyprint import HTML def export_to_pdf(inputText, filename): # Step 1: Convert Markdown components to HTML chunks. # The 'tables' and 'fenced_code' extensions keep standard LLM formatting neat. html_content = markdown.markdown(inputText, extensions=['tables', 'fenced_code']) # Step 2: Inject the content into our CSS-styled HTML boilerplate template final_html = html_template.format(content=html_content) # Step 3: Render directly to a high-fidelity PDF file HTML(string=final_html).write_pdf(filename) #print(f"Successfully generated styled PDF at: {output_pdf_path}")