katex 生成的上标显示不正确。样式虽然正确保存在数据库中,但未显示在显示页面中,但在编辑操作中正确显示。在简单函数 3^5 中,显示页面中的 5 不是“上标”
数据库中保存的内容:
<p><span class=\"ql-formula\" data-value=\"3^5\" contenteditable=\"false\"><span class=\"katex\"><span class=\"katex-mathml\"><math><semantics><mrow><msup><mn>3</mn><mn>5</mn></msup></mrow><annotation encoding=\"application/x-tex\">3^5</annotation></semantics></math></span><span class=\"katex-html\" aria-hidden=\"true\"><span class=\"strut\" style=\"height: 0.814108em;\"></span><span class=\"strut bottom\" style=\"height: 0.814108em; vertical-align: 0em;\"></span><span class=\"base textstyle uncramped\"><span class=\"mord\"><span class=\"mord mathrm\">3</span><span class=\"msupsub\"><span class=\"vlist\"><span class=\"\" style=\"top: -0.363em; margin-right: 0.05em;\"><span class=\"fontsize-ensurer reset-size5 size5\"><span class=\"\" style=\"font-size: 0em;\"></span></span><span class=\"reset-textstyle scriptstyle uncramped mtight\"><span class=\"mord mathrm mtight\">5</span></span></span><span class=\"baseline-fix\"><span class=\"fontsize-ensurer reset-size5 size5\"><span class=\"\" style=\"font-size: 0em;\"></span></span></span></span></span></span></span></span></span></span></p>"
编辑页面中显示的内容
<span class="ql-formula" data-value="3^5" contenteditable="false"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><msup><mn>3</mn><mn>5</mn></msup></mrow><annotation encoding="application/x-tex">3^5</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height: 0.814108em;"></span><span class="strut bottom" style="height: 0.814108em; vertical-align: 0em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathrm">3</span><span class="msupsub"><span class="vlist"><span class="" style="top: -0.363em; margin-right: 0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span class="" style="font-size: 0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord mathrm mtight">5</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span class="" style="font-size: 0em;">​</span></span>​</span></span></span></span></span></span></span></span>
显示页面中显示的内容
<span class="ql-formula" data-value="3^5" contenteditable="false"><span class="katex"><span class="katex-mathml"><math><semantics><mrow><msup><mn>3</mn><mn>5</mn></msup></mrow><annotation encoding="application/x-tex">3^5</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height: 0.814108em;"></span><span class="strut bottom" style="height: 0.814108em; vertical-align: 0em;"></span><span class="base textstyle uncramped"><span class="mord"><span class="mord mathrm">3</span><span class="msupsub"><span class="vlist"><span class="" style=""><span class="fontsize-ensurer reset-size5 size5"><span class="" style="font-size: 0em;">​</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord mathrm mtight">5</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span class="" style="font-size: 0em;">​</span></span>​</span></span></span></span></span></span></span></span>
唯一的区别似乎是style="top: -0.363em; margin-right: 0.05em
没有出现在显示页面中。
我尝试将顶部和边距添加为允许的属性,但它没有帮助。
我对编辑操作的消毒功能:
<%= raw sanitize @post.description, tags: %w(strong em span div a p br ul ol li math semantics mi mo mrow msup mn), attributes: %w(href class style data-value contenteditable) %>
我对表演动作的消毒功能:
<%= raw sanitize @post.description, tags: %w(strong em span div a p br ul ol li math semantics mi mo mrow msup annotation mn), attributes: %w(href class style data-value contenteditable encoding aria-hidden top margin-right ) %>