Spaces:
Sleeping
Sleeping
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', '') |