Skip to content

Commit fe04f74

Browse files
committed
feat: pass components to render
1 parent 7b1d660 commit fe04f74

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.vscode/settings.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"changelogithub",
77
"commitlint",
88
"mdast",
9+
"micromark",
910
"preid",
1011
"shiki",
11-
"unplugin"
12+
"unplugin",
13+
"vnode"
1214
],
1315
// Disable the default formatter, use eslint instead
1416
"prettier.enable": false,

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,18 @@ Markdown string to render.
4343
type md = string
4444
```
4545
46+
#### components
47+
48+
Customize how nodes are rendered.
49+
50+
```ts
51+
type ComponentReturn = Component | [Component, Record<string, any> | undefined]
52+
53+
// default: undefined
54+
type components = Partial<Record<Nodes['type'], ComponentReturn |
55+
((node: Node) => ComponentReturn)>>
56+
```
57+
4658
#### shiki
4759
4860
options of shiki for render code block.

src/VueMarkdown.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script setup lang="ts">
2+
import type { ToVNodeOptions } from 'mdast-util-to-vnode'
23
import type { HighlighterCore, LanguageRegistration, ThemeRegistration } from 'shiki'
34
import { fromMarkdown } from 'mdast-util-from-markdown'
45
import { gfmFromMarkdown } from 'mdast-util-gfm'
@@ -43,6 +44,7 @@ const props = withDefaults(defineProps<VueMarkdownProps>(), {
4344
})
4445
interface VueMarkdownProps {
4546
md: string
47+
components?: ToVNodeOptions['components']
4648
shiki?: {
4749
themes?: Record<string, ThemeRegistration>
4850
langs?: LanguageRegistration[][]
@@ -57,6 +59,7 @@ const vNode = computed(() => {
5759
return toVNode(ast, {
5860
components: {
5961
code: CodeBlock,
62+
...props.components,
6063
},
6164
})
6265
})

0 commit comments

Comments
 (0)