Skip to content

Commit 2783071

Browse files
committed
add code highlighting and math formatting
1 parent 9fdb124 commit 2783071

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed

examples/server/webui/package-lock.json

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/server/webui/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
"dependencies": {
1515
"autoprefixer": "^10.4.20",
1616
"daisyui": "^4.12.14",
17+
"highlight.js": "^11.10.0",
1718
"markdown-it": "^14.1.0",
19+
"markdown-it-highlightjs": "^4.2.0",
20+
"markdown-it-katex-gpt": "^1.1.0",
1821
"postcss": "^8.4.49",
1922
"tailwindcss": "^3.4.15",
2023
"textlinestream": "^1.1.1",

examples/server/webui/src/main.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { createApp, defineComponent, shallowRef, computed, h } from 'vue/dist/vu
33
import MarkdownIt from 'markdown-it';
44
import TextLineStream from 'textlinestream';
55

6+
// code highlighting
7+
import hljs from 'highlight.js';
8+
import HighlightJS from 'markdown-it-highlightjs' // used integrate highlight.js into markdown-it
9+
import 'highlight.js/styles/github-dark.min.css';
10+
// math formula rendering
11+
import 'katex/dist/katex.min.css'
12+
import markdownItKatexGpt from 'markdown-it-katex-gpt'
13+
614
const isDev = import.meta.env.MODE === 'development';
715

816
// utility functions
@@ -74,7 +82,9 @@ const THEMES = ['light', 'dark', 'cupcake', 'bumblebee', 'emerald', 'corporate',
7482
// markdown support
7583
const VueMarkdown = defineComponent(
7684
(props) => {
77-
const md = shallowRef(new MarkdownIt({ breaks: true }));
85+
const md = shallowRef(new MarkdownIt({ breaks: true}))
86+
md.value.use(HighlightJS,{hljs})
87+
md.value.use(markdownItKatexGpt)
7888
const origFenchRenderer = md.value.renderer.rules.fence;
7989
md.value.renderer.rules.fence = (tokens, idx, ...args) => {
8090
const content = tokens[idx].content;

0 commit comments

Comments
 (0)