]> BookStack Code Mirror - bookstack/blobdiff - resources/js/services/code.js
update translation
[bookstack] / resources / js / services / code.js
index 3fcf74125169855a2a60cd7450bb4c6600b0588b..93c3e431f4f5baf7482c898539599f4f8ad2e3e8 100644 (file)
@@ -97,7 +97,7 @@ function highlight() {
 function highlightElem(elem) {
     const innerCodeElem = elem.querySelector('code[class^=language-]');
     elem.innerHTML = elem.innerHTML.replace(/<br\s*[\/]?>/gi ,'\n');
-    const content = elem.textContent.trim();
+    const content = elem.textContent;
 
     let mode = '';
     if (innerCodeElem !== null) {
@@ -258,10 +258,18 @@ function setMode(cmInstance, modeSuggestion, content) {
 function setContent(cmInstance, codeContent) {
     cmInstance.setValue(codeContent);
     setTimeout(() => {
-        cmInstance.refresh();
+        updateLayout(cmInstance);
     }, 10);
 }
 
+/**
+ * Update the layout (codemirror refresh) of a cm instance.
+ * @param cmInstance
+ */
+function updateLayout(cmInstance) {
+    cmInstance.refresh();
+}
+
 /**
  * Get a CodeMirror instance to use for the markdown editor.
  * @param {HTMLElement} elem
@@ -301,6 +309,7 @@ export default {
     popupEditor: popupEditor,
     setMode: setMode,
     setContent: setContent,
+    updateLayout: updateLayout,
     markdownEditor: markdownEditor,
     getMetaKey: getMetaKey,
 };