This commit is contained in:
杜恒
2021-05-31 10:30:10 +08:00
parent cbecb2a699
commit 31e15ebf06
6 changed files with 11 additions and 11 deletions

View File

@@ -99,8 +99,7 @@ export default function createPreviewHtml(str) {
if (str.indexOf('{gird') !== -1) {
str = str.replace(/{gird([^}]*)}([\s\S]*?){\/gird}/g, '<section style="margin-bottom: 15px"><joe-gird $1><span class="_temp" style="display: none">$2</span></joe-gird></section>');
}
$('.cm-preview-content').html(str);
$('.cm-preview-content p:empty').remove();
$('.cm-preview-content pre code').each((i, el) => Prism.highlightElement(el));
Prism.highlightAll();
}

File diff suppressed because one or more lines are too long

View File

@@ -43,8 +43,9 @@ class Joe extends JoeAction {
<div class="cm-progress-right"></div>
</div>
`);
createPreviewHtml($('#text').val());
createPreviewHtml(null);
let _temp = null;
let _debounce = null;
const cm = new EditorView({
state: EditorState.create({
doc: $('#text').val(),
@@ -58,8 +59,8 @@ class Joe extends JoeAction {
if (!update.docChanged) return;
if (_temp !== update.state.doc.toString()) {
_temp = update.state.doc.toString();
if (window.requestAnimationFrame) window.requestAnimationFrame(() => createPreviewHtml(update.state.doc.toString()));
else createPreviewHtml(update.state.doc.toString());
clearTimeout(_debounce);
_debounce = setTimeout(createPreviewHtml.bind(null, update.state.doc.toString()), 150);
}
}),
EditorView.domEventHandlers({