Skip to content

Commit 55bedd4

Browse files
farnabazlarbish
andauthored
feat(preview): use highlight options from @nuxtjs/mdc to highlight code snippets (#158)
Co-authored-by: Baptiste Leproux <leproux.baptiste@gmail.com>
1 parent 9f17b4f commit 55bedd4

File tree

12 files changed

+212
-122
lines changed

12 files changed

+212
-122
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"js-yaml": "^4.1.1",
5353
"minimatch": "^10.1.1",
5454
"nuxt-component-meta": "^0.15.0",
55+
"shiki": "^3.19.0",
5556
"unstorage": "1.17.1"
5657
},
5758
"devDependencies": {

pnpm-lock.yaml

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

src/app/src/components/content/ContentEditorTipTap.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ watch(() => `${document.value?.id}-${props.draftItem.version}-${props.draftItem.
7373
watch(tiptapJSON, async (json) => {
7474
const cleanedTiptap = removeLastEmptyParagraph(json!)
7575
76-
const { body, data } = await tiptapToMDC(cleanedTiptap)
76+
const { body, data } = await tiptapToMDC(cleanedTiptap, {
77+
highlightTheme: host.meta.getHighlightTheme(),
78+
})
7779
7880
const compressedBody: MarkdownRoot = compressTree(body)
7981
const toc: Toc = generateToc(body, { searchDepth: 2, depth: 2 } as Toc)

src/app/src/types/content.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
export interface MarkdownParsingOptions {
22
compress?: boolean
33
}
4+
5+
export interface SyntaxHighlightTheme {
6+
default: string
7+
dark?: string
8+
light?: string
9+
}

src/app/src/types/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { RouteLocationNormalized } from 'vue-router'
44
import type { MediaItem } from './media'
55
import type { Repository } from './git'
66
import type { ComponentMeta } from './component'
7-
import type { MarkdownParsingOptions } from './content'
7+
import type { MarkdownParsingOptions, SyntaxHighlightTheme } from './content'
88

99
export * from './file'
1010
export * from './item'
@@ -24,6 +24,7 @@ export interface StudioHost {
2424
dev: boolean
2525
getComponents: () => ComponentMeta[]
2626
defaultLocale: string
27+
getHighlightTheme: () => SyntaxHighlightTheme
2728
}
2829
on: {
2930
routeChange: (fn: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void) => void

0 commit comments

Comments
 (0)