<commit_before>// In order to stick with the format used in Fidus Writer 1.1-2.0,
// we do a few smaller modifications to the node before it is saved.

export class ModNodeConvert {
    constructor(editor) {
        editor.mod.nodeConvert = this
        this.editor = editor
    }

    modelToEditorNode(node) {
        let fnNodes = node.querySelectorAll('span.footnote')

          for (let i = 0; i < fnNodes.length; i++) {
              let newNode = document.createElement('span')
              newNode.setAttribute('contents',fnNodes[i].innerHTML)
              newNode.classList.add('footnote-marker')
              fnNodes[i].parentNode.replaceChild(newNode, fnNodes[i])
          }
          return node
    }

    editorToModelNode(node) {
        let fnNodes = node.querySelectorAll('.footnote-marker')

        for (let i = 0; i < fnNodes.length; i++) {
            let newNode = document.createElement('span')
            newNode.innerHTML = fnNodes[i].getAttribute('contents')
            newNode.classList.add('footnote')
            fnNodes[i].parentNode.replaceChild(newNode, fnNodes[i])
        }

        let strongNodes = node.querySelectorAll('strong')

        for (let i = 0; i < strongNodes.length; i++) {
            let newNode = document.createElement('b')
            while (strongNodes[i].firstChild) {
                newNode.appendChild(strongNodes[i].firstChild)
            }
            strongNodes[i].parentNode.replaceChild(newNode, strongNodes[i])
        }

        let emNodes = node.querySelectorAll('em')

        for (let i = 0; i < emNodes.length; i++) {
            let newNode = document.createElement('i')
            while (emNodes[i].firstChild) {
                newNode.appendChild(emNodes[i].firstChild)
            }
            emNodes[i].parentNode.replaceChild(newNode, emNodes[i])
        }

        // Remove katex contents of <span class="equation" >
        let mathNodes = node.querySelectorAll('span.equation')

        for (let i = 0; i < mathNodes.length; i++) {
            while (mathNodes[i].firstChild) {
                mathNodes[i].removeChild(mathNodes[i].firstChild)
            }
        }

        // Remove all rendered contents (euqations and images) of figures.
        let figureNodes = node.querySelectorAll('figure')

        for (let i = 0; i < figureNodes.length; i++) {
            while (figureNodes[i].firstChild) {
                figureNodes[i].removeChild(figureNodes[i].firstChild)
            }
        }

        // Remove all contenteditable attributes
        let ceNodes = node.querySelectorAll('[contenteditable]')

        for (let i = 0; i < ceNodes.length; i++) {
            ceNodes[i].removeAttribute('contenteditable')
        }

        return node
    }

}<commit_msg>fix figure export, fixes #272 for 3.0<commit_after>// In order to stick with the format used in Fidus Writer 1.1-2.0,
// we do a few smaller modifications to the node before it is saved.

export class ModNodeConvert {
    constructor(editor) {
        editor.mod.nodeConvert = this
        this.editor = editor
    }

    modelToEditorNode(node) {
        let fnNodes = node.querySelectorAll('span.footnote')

          for (let i = 0; i < fnNodes.length; i++) {
              let newNode = document.createElement('span')
              newNode.setAttribute('contents',fnNodes[i].innerHTML)
              newNode.classList.add('footnote-marker')
              fnNodes[i].parentNode.replaceChild(newNode, fnNodes[i])
          }
          return node
    }

    editorToModelNode(node) {
        let fnNodes = node.querySelectorAll('.footnote-marker')

        for (let i = 0; i < fnNodes.length; i++) {
            let newNode = document.createElement('span')
            newNode.innerHTML = fnNodes[i].getAttribute('contents')
            newNode.classList.add('footnote')
            fnNodes[i].parentNode.replaceChild(newNode, fnNodes[i])
        }

        let strongNodes = node.querySelectorAll('strong')

        for (let i = 0; i < strongNodes.length; i++) {
            let newNode = document.createElement('b')
            while (strongNodes[i].firstChild) {
                newNode.appendChild(strongNodes[i].firstChild)
            }
            strongNodes[i].parentNode.replaceChild(newNode, strongNodes[i])
        }

        let emNodes = node.querySelectorAll('em')

        for (let i = 0; i < emNodes.length; i++) {
            let newNode = document.createElement('i')
            while (emNodes[i].firstChild) {
                newNode.appendChild(emNodes[i].firstChild)
            }
            emNodes[i].parentNode.replaceChild(newNode, emNodes[i])
        }

        // Remove katex contents of <span class="equation" >
        let mathNodes = node.querySelectorAll('span.equation')

        for (let i = 0; i < mathNodes.length; i++) {
            while (mathNodes[i].firstChild) {
                mathNodes[i].removeChild(mathNodes[i].firstChild)
            }
        }

        // TODO: Possibly enable this, but only for saving on server, not for exports.
        // Remove all rendered contents (equations and images) of figures.
        //let figureNodes = node.querySelectorAll('figure')
        //
        //for (let i = 0; i < figureNodes.length; i++) {
        //    while (figureNodes[i].firstChild) {
        //        figureNodes[i].removeChild(figureNodes[i].firstChild)
        //    }
        //}

        // Remove all contenteditable attributes
        let ceNodes = node.querySelectorAll('[contenteditable]')

        for (let i = 0; i < ceNodes.length; i++) {
            ceNodes[i].removeAttribute('contenteditable')
        }

        return node
    }

}
{'fraction_non_alphanumeric': 0.11827956989247312, 'fraction_numerical': 0.004759386567953464, 'mean_word_length': 2.078676071622355, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 5, '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': '1558496', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1565, 'n_words': 353}