mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-16 13:31:25 +00:00
Updated markdown preview to update on diff-basis
Uses vdom system to diff and update the current markdown preview view instead of requiring a full HTML replace change. This should provide better performance, expecially where dynamically loaded content such as iframes were in use. Closes #3454
This commit is contained in:
parent
3fe666f36a
commit
e00d88f45d
4 changed files with 61 additions and 2 deletions
resources/js/components
|
@ -2,7 +2,7 @@ import MarkdownIt from "markdown-it";
|
|||
import mdTasksLists from 'markdown-it-task-lists';
|
||||
import Clipboard from "../services/clipboard";
|
||||
import {debounce} from "../services/util";
|
||||
|
||||
import {patchDomFromHtmlString} from "../services/vdom";
|
||||
import DrawIO from "../services/drawio";
|
||||
|
||||
class MarkdownEditor {
|
||||
|
@ -127,18 +127,31 @@ class MarkdownEditor {
|
|||
updateAndRender() {
|
||||
const content = this.cm.getValue();
|
||||
this.input.value = content;
|
||||
|
||||
const html = this.markdown.render(content);
|
||||
window.$events.emit('editor-html-change', html);
|
||||
window.$events.emit('editor-markdown-change', content);
|
||||
|
||||
// Set body content
|
||||
const target = this.getDisplayTarget();
|
||||
this.displayDoc.body.className = 'page-content';
|
||||
this.displayDoc.body.innerHTML = html;
|
||||
patchDomFromHtmlString(target, html);
|
||||
|
||||
// Copy styles from page head and set custom styles for editor
|
||||
this.loadStylesIntoDisplay();
|
||||
}
|
||||
|
||||
getDisplayTarget() {
|
||||
const body = this.displayDoc.body;
|
||||
|
||||
if (body.children.length === 0) {
|
||||
const wrap = document.createElement('div');
|
||||
this.displayDoc.body.append(wrap);
|
||||
}
|
||||
|
||||
return body.children[0];
|
||||
}
|
||||
|
||||
loadStylesIntoDisplay() {
|
||||
if (this.displayStylesLoaded) return;
|
||||
this.displayDoc.documentElement.classList.add('markdown-editor-display');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue