为什么 Python 在我为文档文件替换 HTML 模板中的字符串时更改字体设置

Why Python changes font settings when I replace a string in HTML template for a doc file

我有一个 HTML 内容作为字符串(模板),需要在从 HTML 内容创建文档文件之前替换 HTML 内容中的名称和地址字段。 当数据库中没有名称时,我将替换为空引号。但是当我们打开doc文件时,这个空字符串的替换改变了HTML内容中给出的字体设置。

如何纠正?

我试过在空字符串中设置字体标签,但仍然没有用。

Python Code:

html_content.replace('[[FULL NAME]]',full_name or '<font color="blue"><font face="arial"><font style="font-size: 8pt" size="1"></font></font></font>')

Piece of HTML template

    <td style="border: 1px solid #ffffff; padding-top: 0in; padding-bottom: 0in; padding-left: 0.04in; padding-right: 0in">

    <p style="margin-left: -0.02in; font-weight: normal"><font color="blue"><font face="arial"><font style="font-size: 8pt" size="1">[[FULL NAME]]</font></font></font>    
</p></td>

要纠正此问题,请在空字符串内发送 <br> 标记。它会工作!

相反,如果我们在空字符串中发送 &nbsp;,在 libre writer 的 .doc 文件中,如果在编辑模式下打开文档,它将显示 Field Shadings .这是主要问题,这就是我在这里问这个问题的原因。