fix: TinyMCE 允许 style 属性 + 对齐支持扩展到标题和列表
- Editor: valid_elements + extended_valid_elements 保留内联 style - docx_to_html: 对齐注入覆盖 p/h1-h6/li 块级元素
This commit is contained in:
parent
81cb155e3f
commit
b1de886828
|
|
@ -21,18 +21,18 @@ async def docx_to_html(file_content: bytes) -> str:
|
||||||
doc = Document(BytesIO(file_content))
|
doc = Document(BytesIO(file_content))
|
||||||
soup = BeautifulSoup(html, "html.parser")
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
paragraphs = doc.paragraphs
|
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):
|
for i, para in enumerate(paragraphs):
|
||||||
if i >= len(html_paras):
|
if i >= len(html_blocks):
|
||||||
break
|
break
|
||||||
if para.alignment and para.alignment in ALIGN_MAP:
|
if para.alignment and para.alignment in ALIGN_MAP:
|
||||||
css = ALIGN_MAP[para.alignment]
|
css = ALIGN_MAP[para.alignment]
|
||||||
existing_style = html_paras[i].get("style", "")
|
existing = html_blocks[i].get("style", "")
|
||||||
styles = f"text-align:{css}"
|
styles = f"text-align:{css}"
|
||||||
if existing_style:
|
if existing:
|
||||||
styles = existing_style.rstrip(";") + ";" + styles
|
styles = existing.rstrip(";") + ";" + styles
|
||||||
html_paras[i]["style"] = styles
|
html_blocks[i]["style"] = styles
|
||||||
|
|
||||||
html = str(soup)
|
html = str(soup)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,8 @@ export default function TemplateEditor() {
|
||||||
toolbar:
|
toolbar:
|
||||||
"undo redo | blocks | bold italic forecolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help",
|
"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; }",
|
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]",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Content>
|
</Content>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue