Spaces:
Running
Running
Upload helper_functions_api.py
Browse files- helper_functions_api.py +54 -0
helper_functions_api.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import mistune
|
| 2 |
+
from mistune.plugins.table import table
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def md_to_html(md_text):
|
| 7 |
+
renderer = mistune.HTMLRenderer()
|
| 8 |
+
markdown_renderer = mistune.Markdown(renderer, plugins=[table])
|
| 9 |
+
html_content = markdown_renderer(md_text)
|
| 10 |
+
|
| 11 |
+
top = """<!DOCTYPE html>
|
| 12 |
+
<html lang="en">
|
| 13 |
+
<head>
|
| 14 |
+
<meta charset="UTF-8">
|
| 15 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 16 |
+
</head>
|
| 17 |
+
<style>
|
| 18 |
+
/* Add your Streamlit-like CSS styles here */
|
| 19 |
+
body {
|
| 20 |
+
font-family: Arial, sans-serif;
|
| 21 |
+
line-height: 1.6;
|
| 22 |
+
padding: 20px;
|
| 23 |
+
background-color: #f0f2f6;
|
| 24 |
+
color: #262730;
|
| 25 |
+
}
|
| 26 |
+
h1, h2, h3 {
|
| 27 |
+
color: #262730;
|
| 28 |
+
margin-bottom: 20px;
|
| 29 |
+
}
|
| 30 |
+
table {
|
| 31 |
+
width: 100%;
|
| 32 |
+
border-collapse: collapse;
|
| 33 |
+
margin-bottom: 20px;
|
| 34 |
+
}
|
| 35 |
+
th, td {
|
| 36 |
+
padding: 10px;
|
| 37 |
+
text-align: left;
|
| 38 |
+
border-bottom: 1px solid #ddd;
|
| 39 |
+
}
|
| 40 |
+
th {
|
| 41 |
+
background-color: #f2f2f2;
|
| 42 |
+
}
|
| 43 |
+
tr:nth-child(even) {
|
| 44 |
+
background-color: #f2f2f2;
|
| 45 |
+
}
|
| 46 |
+
</style>
|
| 47 |
+
<body>"""
|
| 48 |
+
|
| 49 |
+
bottom = """</body>
|
| 50 |
+
</html>"""
|
| 51 |
+
|
| 52 |
+
html_report = top+html_content+bottom
|
| 53 |
+
|
| 54 |
+
return html_report.replace('\n', '')
|