]> BookStack Code Mirror - bookstack/commitdiff
Updated markdown editor to use svg drawio images
authorDan Brown <redacted>
Mon, 23 May 2022 13:38:34 +0000 (14:38 +0100)
committerDan Brown <redacted>
Mon, 23 May 2022 13:38:34 +0000 (14:38 +0100)
- Also tweaked page editor to not error when the current user does not
  have permission to change editor type.

resources/js/components/markdown-editor.js
resources/js/components/page-editor.js

index 71a56af552022c8ed8dccbc845596be241399bf6..8d117870c180edfc81cf81e43bd43902d128db07 100644 (file)
@@ -462,7 +462,7 @@ class MarkdownEditor {
     }
 
     insertDrawing(image, originalCursor) {
-        const newText = `<div drawio-diagram="${image.id}"><img src="${image.url}"></div>`;
+        const newText = DrawIO.buildDrawingContentHtml(image);
         this.cm.focus();
         this.cm.replaceSelection(newText);
         this.cm.setCursor(originalCursor.line, originalCursor.ch + newText.length);
@@ -488,13 +488,14 @@ class MarkdownEditor {
             };
 
             window.$http.post("/images/drawio", data).then(resp => {
-                let newText = `<div drawio-diagram="${resp.data.id}"><img src="${resp.data.url}"></div>`;
-                let newContent = this.cm.getValue().split('\n').map(line => {
-                    if (line.indexOf(`drawio-diagram="${drawingId}"`) !== -1) {
-                        return newText;
-                    }
-                    return line;
+                const image = resp.data;
+                const newText = DrawIO.buildDrawingContentHtml(image);
+
+                const newContent = this.cm.getValue().split('\n').map(line => {
+                    const isDrawing = line.includes(`drawio-diagram="${drawingId}"`);
+                    return isDrawing ? newText : line;
                 }).join('\n');
+
                 this.cm.setValue(newContent);
                 this.cm.setCursor(cursorPos);
                 this.cm.focus();
index ce123e987b055db94769f7326a8fdf63f841342b..f6e52c7073b785f53e7ab3aafcce43b1829fd339 100644 (file)
@@ -24,7 +24,7 @@ class PageEditor {
         this.draftDisplayIcon = this.$refs.draftDisplayIcon;
         this.changelogInput = this.$refs.changelogInput;
         this.changelogDisplay = this.$refs.changelogDisplay;
-        this.changeEditorButtons = this.$manyRefs.changeEditor;
+        this.changeEditorButtons = this.$manyRefs.changeEditor || [];
         this.switchDialogContainer = this.$refs.switchDialog;
 
         // Translations