update code
This commit is contained in:
18
tools.py
18
tools.py
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user