pedrosancao / asciimath-tinymce4

AsciiMath plugin for TinyMCE 4
https://pedrosancao.github.io/asciimath-tinymce4/
GNU General Public License v2.0
1 stars 2 forks source link

Wordcount Plugin + Asciimath = content uneditable #2

Open TuningGuide opened 8 years ago

TuningGuide commented 8 years ago

Hi, i use the wordcount and asciimath plugins (among others).

The wordcount plugin triggers the editor.on('GetContent', cleanup). The cleanup method resets the cursor to the beginning of the editor.

Do you have any idea how a fix could look like? (Except disabling wordcount or asciimath ;)

TuningGuide commented 8 years ago

Hmm, it also is problematic with the localautosave plugin as it also call the getContent function obviously.

TuningGuide commented 8 years ago

I have rewritten the cleanup function so it operates on an unhinged dom element:

, cleanup = function(e) {
                var html = editor.getBody().innerHTML;
                var div = document.createElement('div');
                div.innerHTML = html;

                var emptyNode = div.querySelectorAll('#MathJax_Hidden,#MathJax_Message,#MathJax_Font_Test')
                    , nodes = div.querySelectorAll('span.asciimath4-root-node');

                tinymce.each(emptyNode, function(node) {
                    var parent = node.parentNode;

                    // already at highlevel dom element
                    if(parent.parentNode == null) {
                        parent.removeChild(node);
                    }
                    else {
                        parent.parentNode.removeChild(parent);
                    }
                });
                tinymce.each(nodes, function(node) {
                    node.outerHTML = '`' + node.getAttribute(attrData) + '`';
                });
                if (e.format === 'text') {
                    e.content = div.innerText || div.textContent;
                } else {
                    e.content = div.innerHTML;
                }

                return e.content;
            }