<commit_before>///import core
///import commands/inserthtml.js
///commands 插入公式
///commandsName  insertFormula
///commandsTitle  插入公式
///commandsDialog  dialogs\formula\formula.html

UE.plugins['formula'] = function () {
    var me = this;

    var fnInline = function (node) {
        return domUtils.findParent(node, function (node) {
            return node.nodeType == 1 && node.tagName.toLowerCase() == 'span' && domUtils.hasClass(node, 'MathJax')
        }, true);
    };

    var fnBlock = function (node) {
        return domUtils.findParent(node, function (node) {
            return node.nodeType == 1 && node.tagName.toLowerCase() == 'table' && domUtils.hasClass(node, 'MathJaxer')
        }, true);
    };

    var setCursorPos = function (range,start, end, callback) {
        if (start && end && start === end) {
            if (start.nextSibling) {
                range.setStart(start.nextSibling, 0)
            } else {
                if (start.previousSibling) {
                    range.setStartAtLast(start.previousSibling)
                } else {
                    var p = me.document.createElement('p');
                    domUtils.fillNode(me.document, p);
                    range.setStart(p, 0)
                }
            }
            range.setCursor(false, true);
            callback();
        }
    };

    function queryState() {
        try {
            var range = this.selection.getRange();
            range.adjustmentBoundary();
            var start = fnInline(range.startContainer);
            end = fnInline(range.endContainer);
            if (start && end && start == end) {
                this.body.contentEditable = "false";
                return 1;
            } else {
                this.body.contentEditable = "true";
                return 0;
            }
        }
        catch (e) {
            return 0;
        }
    }

    //不需要判断highlight的command列表
    me.notNeedHighlightQuery = {
        help:1,
        undo:1,
        redo:1,
        source:1,
        print:1,
        searchreplace:1,
        fullscreen:1,
        autotypeset:1,
        pasteplain:1,
        preview:1,
        insertparagraph:1,
        elementpath:1,
        formula:1,
        formulablock:1,
        formulainline:1
    };

    //将queyCommamndState重置
    var orgQuery = me.queryCommandState;
    me.queryCommandState = function (cmd) {
        if (!me.notNeedHighlightQuery[cmd.toLowerCase()] && queryState.call(this) == 1) {
            return -1;
        }
        return orgQuery.apply(this, arguments)
    };

    //避免table插件对于公式的影响
    me.addListener('excludetable excludeNodeinautotype', function (cmd, target) {
        if (target && domUtils.findParent(target, function (node) {
            return domUtils.hasClass(node, 'MathJaxer')
        }, true)) {
            return true;
        }
    });

    me.addOutputRule(function (root) {
        me._MathJaxList = [];
        utils.each(root.getNodesByTagName('table'), function (pi) {
            var cls;
            if ((cls = pi.getAttr('class')) && /MathJaxer/.test(cls)) {
                var tmpNode = UE.uNode.createElement(pi.toHtml());
                me._MathJaxList.push(tmpNode);

                utils.each(pi.getNodesByTagName('span'), function (node) {
                    var val;<commit_msg>[fixed] byxuheng<commit_after>///import core
///import commands/inserthtml.js
///commands 插入公式
///commandsName  insertFormula
///commandsTitle  插入公式
///commandsDialog  dialogs\formula\formula.html

UE.plugins['formula'] = function () {
    var me = this;

    var fnInline = function (node) {
        return domUtils.findParent(node, function (node) {
            return node.nodeType == 1 && node.tagName.toLowerCase() == 'span' && domUtils.hasClass(node, 'MathJax')
        }, true);
    };

    var fnBlock = function (node) {
        return domUtils.findParent(node, function (node) {
            return node.nodeType == 1 && node.tagName.toLowerCase() == 'table' && domUtils.hasClass(node, 'MathJaxer')
        }, true);
    };

    var setCursorPos = function (range,start, end, callback) {
        if (start && end && start === end) {
            if (start.nextSibling) {
                range.setStart(start.nextSibling, 0)
            } else {
                if (start.previousSibling) {
                    range.setStartAtLast(start.previousSibling)
                } else {
                    var p = me.document.createElement('p');
                    domUtils.fillNode(me.document, p);
                    range.setStart(p, 0)
                }
            }
            range.setCursor(false, true);
            callback();
        }
    };

    function queryState() {
        try {
            var range = this.selection.getRange();
            range.adjustmentBoundary();
            var start = fnInline(range.startContainer);
            end = fnInline(range.endContainer);
            if (start && end && start == end) {
                this.body.contentEditable = "false";
                return 1;
            } else {
                this.body.contentEditable = "true";
                return 0;
            }
        }
        catch (e) {
            return 0;
        }
    }

    //不需要判断highlight的command列表
    me.notNeedFormulaQuery = {
        help:1,
        undo:1,
        redo:1,
        source:1,
        print:1,
        searchreplace:1,
        fullscreen:1,
        autotypeset:1,
        pasteplain:1,
        preview:1,
        insertparagraph:1,
        elementpath:1,
        formula:1,
        formulablock:1,
        formulainline:1
    };

    //将queyCommamndState重置
    var orgQuery = me.queryCommandState;
    me.queryCommandState = function (cmd) {
        if (!me.notNeedFormulaQuery[cmd.toLowerCase()] && queryState.call(this) == 1) {
            return -1;
        }
        return orgQuery.apply(this, arguments)
    };

    //避免table插件对于公式的影响
    me.addListener('excludetable excludeNodeinautotype', function (cmd, target) {
        if (target && domUtils.findParent(target, function (node) {
            return domUtils.hasClass(node, 'MathJaxer')
        }, true)) {
            return true;
        }
    });

    me.addOutputRule(function (root) {
        me._MathJaxList = [];
        utils.each(root.getNodesByTagName('table'), function (pi) {
            var cls;
            if ((cls = pi.getAttr('class')) && /MathJaxer/.test(cls)) {
                var tmpNode = UE.uNode.createElement(pi.toHtml());
                me._MathJaxList.push(tmpNode);

                utils.each(pi.getNodesByTagName('span'), function (node) {
                    var val;
{'fraction_non_alphanumeric': 0.124264816769718, 'fraction_numerical': 0.007238727190469009, 'mean_word_length': 1.7091503267973855, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1322397', 'n_tokens_mistral': 1999, 'n_tokens_neox': 1953, 'n_words': 360}