экранирование символов при помощи html.encode, теперь сгенерированные документы открываются

This commit is contained in:
Vladislav Ostapov 2025-05-27 11:20:10 +03:00
parent 683e32bee8
commit 30a567fc9d

View File

@ -1,6 +1,7 @@
from docxtpl import DocxTemplate
from pathlib import Path
import sys
import html
# Загрузка шаблона
doc = DocxTemplate("template/source-code-template.docx")
@ -14,9 +15,10 @@ def get_sources(source_root):
def _get_file_context(source_root, filename):
with open(source_root + filename, 'r', encoding="utf8") as f:
content = f.read()
return {
'filename': filename.replace('\\', '/'), # для шиндовс, чтобы правильно генерить пути
'content': f.read()
'content': html.escape(content, quote=True)
}