🎨 Rename render script
This commit is contained in:
parent
527ce8ceab
commit
968b7d0a7f
|
@ -1,6 +1,7 @@
|
|||
package top.mczhengyi.vditor.extension;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -27,7 +28,9 @@ public class VditorSinglePageContentHandler implements ReactiveSinglePageContent
|
|||
return contentContext;
|
||||
})
|
||||
.onErrorResume(e -> {
|
||||
log.error("VditorHeadProcessor process failed", Throwables.getRootCause(e));
|
||||
if (e instanceof Throwable) {
|
||||
log.error("VditorHeadProcessor process failed", Throwables.getRootCause(e));
|
||||
}
|
||||
return Mono.empty();
|
||||
});
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class ScriptUtils {
|
|||
script.sign("article-sign")
|
||||
.stylesheet("vditor-render.css", "style")
|
||||
.script("https://cdn.jsdelivr.net/npm/vditor@3.9.9/dist/method.min.js", "methods")
|
||||
.script("render.js", "render"); // 标记文章位置
|
||||
.script("render-utils.js", "render-utils"); // 标记文章位置
|
||||
if (renderConfig.getMediaRender())
|
||||
script.script("external/media-render.js", "media");
|
||||
if (!renderConfig.getDarkMode().equals("disabled")) {
|
||||
|
@ -23,7 +23,7 @@ public class ScriptUtils {
|
|||
script.script("halo-renders/index.js", "halo-render-js")
|
||||
.stylesheet("halo-renders/index.css", "halo-render-css")
|
||||
.script("external/halo-renders.js", "halo-render")
|
||||
.script("pjax.js", "vditor-pjax"); // 完成操作后渲染
|
||||
.script("render.js", "render"); // 完成操作后渲染
|
||||
return script.getScript();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
if (!window.vditorPjax) {
|
||||
window.vditorPjax = true
|
||||
// 当网页已经准备就绪则直接执行渲染任务
|
||||
if (document.readyState === "complete") {
|
||||
vditorRender.render()
|
||||
} else {
|
||||
window.addEventListener('load', () => vditorRender.render())
|
||||
}
|
||||
// 兼容 PJAX
|
||||
$(document).on('pjax:complete', function() {
|
||||
vditorRender.render()
|
||||
console.log("[Vditor Render] PJAX END")
|
||||
})
|
||||
// 兼容 Jquery-Pjax
|
||||
$(document).on('pjax:end', function() {
|
||||
vditorRender.render()
|
||||
console.log("[Vditor Render] PJAX END")
|
||||
})
|
||||
console.log("[Vditor Render] PJAX Injected")
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
(function (win) {
|
||||
if (win.vditorRender) return;
|
||||
|
||||
const THEME_PREFIX="/plugins/vditor-mde/assets/static/themes"
|
||||
const CDN = "https://cdn.jsdelivr.net/npm/vditor@3.9.9"
|
||||
|
||||
/** 拓展处理 ({dark}) => void */
|
||||
let functionList = []
|
||||
let darkMode = false
|
||||
|
||||
/**
|
||||
* 处理渲染
|
||||
* @param func
|
||||
*/
|
||||
function addExternal(func) {
|
||||
functionList.push(func)
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置暗色模式
|
||||
* @param {Boolean} dark
|
||||
*/
|
||||
function setDarkMode(dark = false) {
|
||||
darkMode = dark
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染
|
||||
* @param elId 搜寻位置
|
||||
*/
|
||||
function vditorRender(elId="vditor-article-sign") {
|
||||
Vditor.setContentTheme(darkMode?"dark":"light", THEME_PREFIX)
|
||||
let root = document.getElementById(elId)
|
||||
if (!root) {
|
||||
console.log("[Vditor Render] Can't Found Article Root Element!");
|
||||
return
|
||||
}
|
||||
root = root.parentElement
|
||||
root.classList.add("vditor-reset")
|
||||
// Render
|
||||
const renderTheme = darkMode?"dark":"classic"
|
||||
Vditor.mathRender(root, {cdn: CDN})
|
||||
Vditor.mindmapRender(root, CDN, renderTheme)
|
||||
Vditor.mermaidRender(root, CDN, renderTheme)
|
||||
Vditor.chartRender(root, CDN, renderTheme)
|
||||
Vditor.abcRender(root, CDN)
|
||||
Vditor.graphvizRender(root, CDN)
|
||||
Vditor.flowchartRender(root, CDN)
|
||||
// Run External Plugin
|
||||
functionList.forEach(func => {
|
||||
func({
|
||||
darkMode
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
win.vditorRender = {
|
||||
THEME_PREFIX,
|
||||
CDN,
|
||||
functionList,
|
||||
darkMode,
|
||||
addExternal,
|
||||
setDarkMode,
|
||||
vditorRender,
|
||||
render: vditorRender
|
||||
}
|
||||
})(window)
|
|
@ -1,67 +1,20 @@
|
|||
(function (win) {
|
||||
if (win.vditorRender) return;
|
||||
|
||||
const THEME_PREFIX="/plugins/vditor-mde/assets/static/themes"
|
||||
const CDN = "https://cdn.jsdelivr.net/npm/vditor@3.9.9"
|
||||
|
||||
/** 拓展处理 ({dark}) => void */
|
||||
let functionList = []
|
||||
let darkMode = false
|
||||
|
||||
/**
|
||||
* 处理渲染
|
||||
* @param func
|
||||
*/
|
||||
function addExternal(func) {
|
||||
functionList.push(func)
|
||||
if (!window.vditorPjax) {
|
||||
window.vditorPjax = true
|
||||
// 当网页已经准备就绪则直接执行渲染任务
|
||||
if (document.readyState === "complete") {
|
||||
vditorRender.render()
|
||||
} else {
|
||||
window.addEventListener('load', () => vditorRender.render())
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置暗色模式
|
||||
* @param {Boolean} dark
|
||||
*/
|
||||
function setDarkMode(dark = false) {
|
||||
darkMode = dark
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染
|
||||
* @param elId 搜寻位置
|
||||
*/
|
||||
function vditorRender(elId="vditor-article-sign") {
|
||||
Vditor.setContentTheme(darkMode?"dark":"light", THEME_PREFIX)
|
||||
let root = document.getElementById(elId)
|
||||
if (!root) {
|
||||
console.log("[Vditor Render] Can't Found Article Root Element!");
|
||||
return
|
||||
}
|
||||
root = root.parentElement
|
||||
root.classList.add("vditor-reset")
|
||||
// Render
|
||||
const renderTheme = darkMode?"dark":"classic"
|
||||
Vditor.mathRender(root, {cdn: CDN})
|
||||
Vditor.mindmapRender(root, CDN, renderTheme)
|
||||
Vditor.mermaidRender(root, CDN, renderTheme)
|
||||
Vditor.chartRender(root, CDN, renderTheme)
|
||||
Vditor.abcRender(root, CDN)
|
||||
Vditor.graphvizRender(root, CDN)
|
||||
Vditor.flowchartRender(root, CDN)
|
||||
// Run External Plugin
|
||||
functionList.forEach(func => {
|
||||
func({
|
||||
darkMode
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
win.vditorRender = {
|
||||
THEME_PREFIX,
|
||||
CDN,
|
||||
functionList,
|
||||
darkMode,
|
||||
addExternal,
|
||||
setDarkMode,
|
||||
vditorRender,
|
||||
render: vditorRender
|
||||
}
|
||||
})(window)
|
||||
// 兼容 PJAX
|
||||
$(document).on('pjax:complete', function() {
|
||||
vditorRender.render()
|
||||
console.log("[Vditor Render] PJAX END")
|
||||
})
|
||||
// 兼容 Jquery-Pjax
|
||||
$(document).on('pjax:end', function() {
|
||||
vditorRender.render()
|
||||
console.log("[Vditor Render] PJAX END")
|
||||
})
|
||||
console.log("[Vditor Render] PJAX Injected")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue