Files
webpreview/src/main.ts
yuetsh 2bd9382c8c
Some checks failed
Deploy / deploy (build, debian, 22) (push) Has been cancelled
Deploy / deploy (build:staging, school, 8822) (push) Has been cancelled
fix: register plaintext hljs language and handle profile fetch error
- Register highlight.js plaintext language to fix "Unknown language" error
- Add try/catch around getMyProfile() to handle network errors gracefully
- Add components.d.ts to .gitignore (auto-generated by unplugin-vue-components)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-10 11:59:18 +08:00

59 lines
1.6 KiB
TypeScript

import { createApp } from "vue"
import { create } from "naive-ui"
import App from "./App.vue"
import { addAPIProvider } from "@iconify/vue"
//@ts-ignore
import "github-markdown-css/github-markdown-light.css"
import { marked } from "marked"
import alert from "marked-alert"
import { markedHighlight } from "marked-highlight"
import preview from "marked-code-preview"
import { alertVariants } from "./utils/const"
import hljs from "highlight.js/lib/core"
import xml from "highlight.js/lib/languages/xml"
import css from "highlight.js/lib/languages/css"
import javascript from "highlight.js/lib/languages/javascript"
import plaintext from "highlight.js/lib/languages/plaintext"
//@ts-ignore
import "highlight.js/styles/github.min.css"
import { router } from "./router"
hljs.registerLanguage("html", xml)
hljs.registerLanguage("css", css)
hljs.registerLanguage("js", javascript)
hljs.registerLanguage("javascript", javascript)
hljs.registerLanguage("plaintext", plaintext)
marked.use({
gfm: true,
})
marked.use(
markedHighlight({
langPrefix: "hljs language-",
highlight(code, lang) {
const language = hljs.getLanguage(lang) ? lang : "plaintext"
return hljs.highlight(code, { language }).value
},
}),
)
marked.use(alert({ variants: alertVariants }))
const template = `<div class="markedown-body-preview">{preview}</div>`
marked.use(preview({ template }))
const app = createApp(App)
const naive = create()
app.use(naive)
app.use(router)
app.mount("#app")
if (!!import.meta.env.PUBLIC_ICONIFY_URL) {
addAPIProvider("", {
resources: [import.meta.env.PUBLIC_ICONIFY_URL],
})
}