update code

This commit is contained in:
lychang
2025-11-20 02:27:22 +08:00
parent 8ff1b80be6
commit bf7ec6737d
10 changed files with 229 additions and 243 deletions

View File

@@ -6,13 +6,12 @@ import sqlite3
from file import ObjectFileManager, LocalFileManager
import re
import html2text
from io import BytesIO
import jinja2
import mammoth
def transform_docx2md(file_bytes: bytes, data: dict):
def transform_template(file_bytes: bytes):
html_head = """
<!DOCTYPE html>
<html lang="en">
@@ -31,8 +30,8 @@ def transform_docx2md(file_bytes: bytes, data: dict):
html_tail = """
</body>
</html>"""
result = mammoth.convert_to_html(file_bytes)
file_obj = BytesIO(file_bytes)
result = mammoth.convert_to_html(file_obj)
html = result.value
html = re.sub('<img.*?>', '', html)
c = re.compile(r'{(.*?)}')
@@ -62,9 +61,12 @@ def transform_docx2md(file_bytes: bytes, data: dict):
'\n{% for ' + lc[0] + ' in data.' + lc[0] + ' %}\n<tr><td><p>')
else:
print(lc[0], lc)
html = jinja2.Template(html_head + html + html_tail).render(data=data)
markdown = html2text.html2text(html)
return html, markdown
return html_head + html + html_tail
def report_template_render(template: str, data: dict):
html = jinja2.Template(template).render(data=data)
return html
class DatabaseManager: