feat: add twoslash js/ts highlight

This commit is contained in:
camera-2018
2024-06-03 22:14:51 +08:00
parent 6b9e972463
commit b5b72ee931
5 changed files with 4011 additions and 2 deletions

View File

@@ -6,6 +6,7 @@ import { nav } from './nav.js';
import PanguPlugin from 'markdown-it-pangu' import PanguPlugin from 'markdown-it-pangu'
import { fileURLToPath, URL } from 'node:url' import { fileURLToPath, URL } from 'node:url'
import VueMacros from 'unplugin-vue-macros/vite' import VueMacros from 'unplugin-vue-macros/vite'
import { transformerTwoslash } from '@shikijs/vitepress-twoslash'
// https://vitepress.dev/reference/site-config // https://vitepress.dev/reference/site-config
export default withMermaid({ export default withMermaid({
@@ -85,7 +86,10 @@ export default withMermaid({
config: (md) => { config: (md) => {
md.use(PanguPlugin); md.use(PanguPlugin);
}, },
math: true math: true,
codeTransformers: [
transformerTwoslash()
]
}, },
sitemap: { sitemap: {
hostname: 'https://hdu-cs.wiki' hostname: 'https://hdu-cs.wiki'

View File

@@ -9,6 +9,8 @@ import Bilibili from '../../components/Bilibili.vue'
import Parallax from '../../components/Parallax.vue' import Parallax from '../../components/Parallax.vue'
import './style.css' import './style.css'
import './rainbow.css' import './rainbow.css'
import TwoslashFloatingVue from '@shikijs/vitepress-twoslash/client'
import '@shikijs/vitepress-twoslash/style.css'
let homePageStyle = undefined let homePageStyle = undefined
@@ -21,6 +23,7 @@ export default {
ctx.app.component('Download', Download) ctx.app.component('Download', Download)
ctx.app.component('Bilibili', Bilibili) ctx.app.component('Bilibili', Bilibili)
ctx.app.component('Parallax', Parallax) ctx.app.component('Parallax', Parallax)
ctx.app.use(TwoslashFloatingVue)
if (typeof window === 'undefined') if (typeof window === 'undefined')
return return
watch( watch(

View File

@@ -39,7 +39,7 @@
5. 代码块使用 ` ``` ` 包裹,并标注常见的语言标识符,如 ` ```python ` ,其作用是使代码正常高亮。 5. 代码块使用 ` ``` ` 包裹,并标注常见的语言标识符,如 ` ```python ` ,其作用是使代码正常高亮。
::: details 代码高亮支持的语言 ::: details 代码高亮支持的语言
```ts ```ts twoslash
export type Lang = export type Lang =
| 'abap' | 'abap'
| 'actionscript-3' | 'actionscript-3'

4000
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,5 @@
{ {
"type": "module",
"scripts": { "scripts": {
"docs:dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' vitepress dev --host", "docs:dev": "cross-env NODE_OPTIONS='--max-old-space-size=8192' vitepress dev --host",
"docs:build": "cross-env NODE_OPTIONS='--max-old-space-size=8192' vitepress build", "docs:build": "cross-env NODE_OPTIONS='--max-old-space-size=8192' vitepress build",
@@ -23,6 +24,7 @@
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^10.0.5", "@semantic-release/github": "^10.0.5",
"@semantic-release/release-notes-generator": "^13.0.0", "@semantic-release/release-notes-generator": "^13.0.0",
"@shikijs/vitepress-twoslash": "^1.6.1",
"@vitejs/plugin-vue": "^5.0.4", "@vitejs/plugin-vue": "^5.0.4",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"markdown-it-mathjax3": "^4.3.2", "markdown-it-mathjax3": "^4.3.2",