KindEditor.plugin('math', function (K) { var self = this, name = 'math', lang = self.lang(name + '.'); self.clickToolbar(name, function () { var img = self.plugin.getSelectedImage(); var latex = $(img).data("latex") || ''; var html = [ '
', '
', '
', '
' ].join(''); var iframe = K(''); var dialog = self.createDialog({ name: name, width: Math.min(document.body.clientWidth, 500), height: 380, title: "插入公式", body: html, yesBtn: { name: '插入', click: function (e) { var win = iframe[0].contentWindow; var currentSVG = win.$("#preview-body")[0].querySelector("svg"); if (!currentSVG) { alert("请输入正确的公式"); } const blob = new Blob([currentSVG.outerHTML], { type: 'image/svg+xml' }); const file = new File([blob], "latex.svg", { type: 'image/svg+xml' }); require(['upload'], function(Upload){ Upload.api.send(file, function (data, ret) { var url = Fast.api.cdnurl(ret.data.url); var latex = win.$("#latex-source").val(); if (latex == '') { Layer.msg("请选择或输入公式"); return false; } self.insertHtml(""); self.hideDialog().focus(); }); }); return; } }, noBtn: { name: self.lang('no'), click: function (e) { self.hideDialog().focus(); } } }), div = dialog.div; K('.ke-formula', div).replaceWith(iframe); return; }); });