mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 05:36:00 +00:00
Fixed code snippets being added as single line
TinyMCE was adding attributes to <br> elements within code blocks which would then not be converted to newlines by our code regex match. This changes the conversion to use dom querying instead. Fixes #3507
This commit is contained in:
parent
0c6f598d91
commit
9dd69b04b8
@ -86,7 +86,13 @@ function defineCodeBlockCustomElement(editor) {
|
|||||||
getContent() {
|
getContent() {
|
||||||
const code = this.querySelector('code') || this.querySelector('pre');
|
const code = this.querySelector('code') || this.querySelector('pre');
|
||||||
const tempEl = document.createElement('pre');
|
const tempEl = document.createElement('pre');
|
||||||
tempEl.innerHTML = code.innerHTML.replace().replace(/<br\s*[\/]?>/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;
|
return tempEl.textContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +110,7 @@ function defineCodeBlockCustomElement(editor) {
|
|||||||
|
|
||||||
const container = this.shadowRoot.querySelector('.CodeMirrorContainer');
|
const container = this.shadowRoot.querySelector('.CodeMirrorContainer');
|
||||||
const renderCodeMirror = (Code) => {
|
const renderCodeMirror = (Code) => {
|
||||||
|
console.log({content});
|
||||||
this.cm = Code.wysiwygView(container, content, this.getLanguage());
|
this.cm = Code.wysiwygView(container, content, this.getLanguage());
|
||||||
Code.updateLayout(this.cm);
|
Code.updateLayout(this.cm);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@ -159,6 +166,7 @@ function register(editor, url) {
|
|||||||
showPopup(editor, textContent, '', (newCode, newLang) => {
|
showPopup(editor, textContent, '', (newCode, newLang) => {
|
||||||
const pre = doc.createElement('pre');
|
const pre = doc.createElement('pre');
|
||||||
const code = doc.createElement('code');
|
const code = doc.createElement('code');
|
||||||
|
console.log(newCode);
|
||||||
code.classList.add(`language-${newLang}`);
|
code.classList.add(`language-${newLang}`);
|
||||||
code.innerText = newCode;
|
code.innerText = newCode;
|
||||||
pre.append(code);
|
pre.append(code);
|
||||||
|
Loading…
Reference in New Issue
Block a user