diff --git a/backend/app/services/document_processor.py b/backend/app/services/document_processor.py index f540c76..df16857 100644 --- a/backend/app/services/document_processor.py +++ b/backend/app/services/document_processor.py @@ -21,18 +21,18 @@ async def docx_to_html(file_content: bytes) -> str: doc = Document(BytesIO(file_content)) soup = BeautifulSoup(html, "html.parser") paragraphs = doc.paragraphs - html_paras = soup.find_all("p") + html_blocks = soup.find_all(["p", "h1", "h2", "h3", "h4", "h5", "h6", "li"]) for i, para in enumerate(paragraphs): - if i >= len(html_paras): + if i >= len(html_blocks): break if para.alignment and para.alignment in ALIGN_MAP: css = ALIGN_MAP[para.alignment] - existing_style = html_paras[i].get("style", "") + existing = html_blocks[i].get("style", "") styles = f"text-align:{css}" - if existing_style: - styles = existing_style.rstrip(";") + ";" + styles - html_paras[i]["style"] = styles + if existing: + styles = existing.rstrip(";") + ";" + styles + html_blocks[i]["style"] = styles html = str(soup) except Exception: diff --git a/web/src/pages/TemplateEditor.tsx b/web/src/pages/TemplateEditor.tsx index da05ee7..1d079e5 100644 --- a/web/src/pages/TemplateEditor.tsx +++ b/web/src/pages/TemplateEditor.tsx @@ -363,6 +363,8 @@ export default function TemplateEditor() { toolbar: "undo redo | blocks | bold italic forecolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help", content_style: "body { font-family: Arial, sans-serif; font-size: 14px; }", + valid_elements: "*[*]", + extended_valid_elements: "p[style],h1[style],h2[style],h3[style],h4[style],h5[style],h6[style],div[style],span[style],li[style]", }} />