Trilium 博客美化及修复


C、C++代码高亮Bug修复

.ejs 添加替换:

.replaceAll( /class="language-application-(\w+)"/g , (...match) => {
        match[0] = match[0].replace("-application", "");
        return match[0];
    }).replaceAll(/-csrc"/g , (...match) => {
        match[0] = match[0].replace("-csrc", "-c");
        return match[0];
    }).replaceAll(/language-text-x-c-src"/g , (...match) => {
        match[0] = match[0].replace("-text-x-c-src", "-c");
        return match[0];
    })

然后用下面的命令打包

npm install uglifycss uglify-js -g
uglifycss .\Ankia-Theme.css --output .\Ankia-Theme.min.css
uglifyjs  .\Ankia-Theme.js -o .\Ankia-Theme.min.js

 

在非 Ankia 主题的分享中加入语法高亮

访问 https://prismjs.com/download.html 然后选择主题、插件、语言,下面是选好的:

Download ▲ Prism (prismjs.com)

然后在 prism.js 前面加一些代码

document.querySelectorAll("#content > pre > code").forEach(element => {
    element.outerHTML = element.outerHTML
        .replaceAll(/class="language-text-x-(\w+)"/g, (match, p1) => {
            return `class="language-${p1}"`;
        })
        .replaceAll(/class="language-text-(\w+)"/g, (match, p1) => {
            return `class="language-${p1}"`;
        })
        .replaceAll(/class="language-application-x-(\w+)"/g, (match, p1) => {
            return `class="language-${p1}"`;
        })
        .replaceAll(/class="language-application-(\w+)"/g, (match, p1) => {
            return `class="language-${p1}"`;
        })
        .replaceAll(/-csrc"/g, () => {
            return '-c"';
        })
        .replaceAll(/language-text-x-c-src"/g, () => {
            return 'language-c"';
        })
        .replaceAll("language-application-javascript-env-backend", "language-javascript")
        .replaceAll("language-application-javascript-env-frontend", "language-javascript");
});

给文章或者根目录添加新关系:

 ~shareCss(可继承的)=prism.css
 ~shareJs(可继承的)=prism.js

 

 

 


运行时间 427 天 | 总访问量