feat: support for $ rendering katex (#251)

This commit is contained in:
YangQi 2023-11-06 17:35:15 -06:00 committed by GitHub
parent 192c7878f9
commit effb43d7d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 53 additions and 1235 deletions

1257
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,7 @@
"juice": "^8.0.0",
"katex": "^0.16.9",
"marked": "^4.0.18",
"marked-katex-extension": "^4.0.3",
"minio": "7.0.33",
"node-fetch": "^3.2.10",
"pinia": "^2.1.6",

View File

@ -28,10 +28,18 @@
rel="stylesheet"
href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/wechatsync/article-syncjs@latest/dist/styles.css"
/>
<script src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/prettify/r298/prettify.min.js"></script>
<!-- KaTeX CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css" integrity="sha384-n8MVd4RsNIU0tAv4ct0nTaAbDJwPJzDEaqSD1odI+WdtXRGWt2kTvGFasHpSy3SV" crossorigin="anonymous">
<script src="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/npm/prettify/r298/prettify.min.js"></script>
<style>
/**
解决公众号复制字体问题
*/
.katex .mathnormal {
font-family: "Times New Roman" !important;
}
</style>
</head>
<body>

View File

@ -1,6 +1,12 @@
import { Renderer } from "marked";
import marked, { Renderer } from "marked";
import hljs from "highlight.js";
import katex from "katex";
import markedKatex from "marked-katex-extension";
marked.use(markedKatex({
throwOnError: false,
output: `html`
}));
class WxRenderer {
constructor(opts) {
this.opts = opts;
@ -121,10 +127,6 @@ class WxRenderer {
return `<blockquote ${getStyles("blockquote")}>${text}</blockquote>`;
};
renderer.code = (text, lang) => {
if (lang === "katex") {
const html = katex.renderToString(text);
return `${html}`;
}
if (lang.startsWith("mermaid")) {
setTimeout(() => {
window.mermaid?.run();

View File

@ -341,6 +341,10 @@ export default {
const clipboardDiv = document.getElementById(`output`)
clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML)
// katex
clipboardDiv.innerHTML = clipboardDiv.innerHTML.replace(/class="base"( style="display: inline")*/g, `class="base" style="display: inline"`)
if (this.isMacCodeBlock) {
clipboardDiv.innerHTML = clipboardDiv.innerHTML.replaceAll(
/(<code class="prettyprint[^>]*)(style=")/g,