X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/d2b49084b082f0aa28ca6969884b88acb2c63b96..refs/pull/3616/head:/resources/js/wysiwyg/plugin-codeeditor.js diff --git a/resources/js/wysiwyg/plugin-codeeditor.js b/resources/js/wysiwyg/plugin-codeeditor.js index 82ab7d3c8..82052a40d 100644 --- a/resources/js/wysiwyg/plugin-codeeditor.js +++ b/resources/js/wysiwyg/plugin-codeeditor.js @@ -86,7 +86,13 @@ function defineCodeBlockCustomElement(editor) { getContent() { const code = this.querySelector('code') || this.querySelector('pre'); const tempEl = document.createElement('pre'); - tempEl.innerHTML = code.innerHTML.replace().replace(//gi ,'\n').replace(/\ufeff/g, ''); + tempEl.innerHTML = code.innerHTML.replace(/\ufeff/g, ''); + + const brs = tempEl.querySelectorAll('br'); + for (const br of brs) { + br.replaceWith('\n'); + } + return tempEl.textContent; } @@ -178,7 +184,7 @@ function register(editor, url) { editor.on('PreInit', () => { editor.parser.addNodeFilter('pre', function(elms) { for (const el of elms) { - const wrapper = new tinymce.html.Node.create('code-block', { + const wrapper = tinymce.html.Node.create('code-block', { contenteditable: 'false', });