import re
from fpdf import FPDF

def md_to_html(md_text):
    if not md_text:
        return ""
    paragraphs = md_text.split('\n\n')
    html_paragraphs = []
    for p in paragraphs:
        lines = p.split('\n')
        p_html = []
        for line in lines:
            line = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', line)
            line = re.sub(r'(?<!\*)\*(?!\*)(.+?)(?<!\*)\*(?!\*)', r'<i>\1</i>', line)
            line = re.sub(r'~~(.+?)~~', r'\1', line)
            line = re.sub(r'^#{1,6}\s+(.*)$', r'<b>\1</b>', line)
            line = re.sub(r'^[-*+]\s+(.*)$', '  - \\1', line)
            p_html.append(line)
        html_paragraphs.append('<p>' + '<br/>'.join(p_html) + '</p>')
    return ''.join(html_paragraphs)

pdf = FPDF()
pdf.add_page()
pdf.set_font("helvetica", size=12)

# Simulate the layout
html = md_to_html("@SoulSync can you please verify it")
pdf.write_html(html)

pdf.output("test2.pdf")
