rag_chat_with_analytics / helper_functions_api.py
pvanand's picture
Upload helper_functions_api.py
a99c2b6 verified
raw
history blame
1.3 kB
import mistune
from mistune.plugins.table import table
import re
def md_to_html(md_text):
renderer = mistune.HTMLRenderer()
markdown_renderer = mistune.Markdown(renderer, plugins=[table])
html_content = markdown_renderer(md_text)
top = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
/* Add your Streamlit-like CSS styles here */
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
background-color: #f0f2f6;
color: #262730;
}
h1, h2, h3 {
color: #262730;
margin-bottom: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 20px;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
th {
background-color: #f2f2f2;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
</style>
<body>"""
bottom = """</body>
</html>"""
html_report = top+html_content+bottom
return html_report.replace('\n', '')