mirror of
https://github.com/doocs/md.git
synced 2024-11-25 03:18:36 +08:00
feat: support for $
rendering katex (#251)
This commit is contained in:
parent
192c7878f9
commit
effb43d7d9
1257
package-lock.json
generated
1257
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -25,6 +25,7 @@
|
|||||||
"juice": "^8.0.0",
|
"juice": "^8.0.0",
|
||||||
"katex": "^0.16.9",
|
"katex": "^0.16.9",
|
||||||
"marked": "^4.0.18",
|
"marked": "^4.0.18",
|
||||||
|
"marked-katex-extension": "^4.0.3",
|
||||||
"minio": "7.0.33",
|
"minio": "7.0.33",
|
||||||
"node-fetch": "^3.2.10",
|
"node-fetch": "^3.2.10",
|
||||||
"pinia": "^2.1.6",
|
"pinia": "^2.1.6",
|
||||||
|
@ -28,10 +28,18 @@
|
|||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdn-doocs.oss-cn-shenzhen.aliyuncs.com/gh/wechatsync/article-syncjs@latest/dist/styles.css"
|
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 -->
|
<!-- 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">
|
<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>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
@ -1,6 +1,12 @@
|
|||||||
import { Renderer } from "marked";
|
import marked, { Renderer } from "marked";
|
||||||
import hljs from "highlight.js";
|
import hljs from "highlight.js";
|
||||||
import katex from "katex";
|
import markedKatex from "marked-katex-extension";
|
||||||
|
|
||||||
|
marked.use(markedKatex({
|
||||||
|
throwOnError: false,
|
||||||
|
output: `html`
|
||||||
|
}));
|
||||||
|
|
||||||
class WxRenderer {
|
class WxRenderer {
|
||||||
constructor(opts) {
|
constructor(opts) {
|
||||||
this.opts = opts;
|
this.opts = opts;
|
||||||
@ -121,10 +127,6 @@ class WxRenderer {
|
|||||||
return `<blockquote ${getStyles("blockquote")}>${text}</blockquote>`;
|
return `<blockquote ${getStyles("blockquote")}>${text}</blockquote>`;
|
||||||
};
|
};
|
||||||
renderer.code = (text, lang) => {
|
renderer.code = (text, lang) => {
|
||||||
if (lang === "katex") {
|
|
||||||
const html = katex.renderToString(text);
|
|
||||||
return `${html}`;
|
|
||||||
}
|
|
||||||
if (lang.startsWith("mermaid")) {
|
if (lang.startsWith("mermaid")) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
window.mermaid?.run();
|
window.mermaid?.run();
|
||||||
|
@ -341,6 +341,10 @@ export default {
|
|||||||
|
|
||||||
const clipboardDiv = document.getElementById(`output`)
|
const clipboardDiv = document.getElementById(`output`)
|
||||||
clipboardDiv.innerHTML = mergeCss(clipboardDiv.innerHTML)
|
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) {
|
if (this.isMacCodeBlock) {
|
||||||
clipboardDiv.innerHTML = clipboardDiv.innerHTML.replaceAll(
|
clipboardDiv.innerHTML = clipboardDiv.innerHTML.replaceAll(
|
||||||
/(<code class="prettyprint[^>]*)(style=")/g,
|
/(<code class="prettyprint[^>]*)(style=")/g,
|
||||||
|
Loading…
Reference in New Issue
Block a user