修复umeditor部分公式编辑器bug

1.公式编辑器输出 '<' 会 'undefined'

在解析LaTeX过程中,会过滤html并且转换成为root节点

/umeditor/_src/plugins/inserthtml.js

/umeditor/_src/core/htmlparser.js

这里是通过正则表达式来过滤分析节点的,造成数据变成了

<</span>

解决方法:

思路是就不动正则表达式了,可以从其他地方解决,因为这个js是单独处理表达式的,目前只有<这个存在undefined问题

\umeditor\_src\plugins\formula.js

21行:

me.addInputRule(function (root) {
        $.each(root.getNodesByTagName('span'), function (i, node) {
            if (node.hasClass('mathquill-embedded-latex')) {
                var firstChild, latex = '';
                while(firstChild = node.firstChild()){
                    latex += firstChild.data;
                    if(latex == undefined || latex == "undefined"){
                        latex = "<";
                    }
                    node.removeChild(firstChild);
                }
                node.tagName = 'iframe';
                node.setAttr({
                    'frameborder': '0',
                    'src': me.getOpt('UMEDITOR_HOME_URL') + 'dialogs/formula/formula.html',
                    'data-latex': utils.unhtml(latex)
                });
            }
        });
    });

2.这两个符号对应的公式是:\nsubseteq  和  \nsupseteq 

在编辑器中第一次输入是正确的,可是一旦保存后,被转译成 \not\subseteq 和 \not\supseteq ,显示也变成了 

原因是因为在

umeditor\dialogs\formula\formula.html 

166 行 修改源码

updateIframe: function(){
                $iframe.width(this.$mathquill.width()+8).height(this.$mathquill.height()+8);
                var latex = $iframe.attr('data-latex'),
// 页面写入时,对公式进行校验,在\nsubseteq被编译后就变成了 \not\subseteq
                    newLatex = this.getLatex();
// 检验了不相等,进行重新编译 除了出问题的两个符号
                if(latex != '\\nsubseteq' && latex != '\\nsupseteq' ){
                    if(latex != newLatex) {
                        $iframe.attr('data-latex', this.getLatex());
                        saveScene();
                    }
                }
               
            },

197 行 修改源码

getLatex: function(){
                var mqLax = this.$mathquill.mathquill('latex');
                mqLax = mqLax.replace("\\not\\subseteq","\\nsubseteq");
                mqLax = mqLax.replace("\\not\\supseteq","\\nsupseteq");
                return mqLax;
            },

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值