Skip to content

Commit a18efa5

Browse files
committed
fix: markdown render with new Vue
1 parent 5289b14 commit a18efa5

3 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/assets/style/docs.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
line-height: 24px;
4444
}
4545

46-
:not(pre) code {
46+
:not(pre) > code {
4747
color: var(--color-code);
4848
background: var(--color-code-bg);
4949
}

src/components/markdown-render/index.vue

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
<!-- eslint-disable vue/one-component-per-file -->
12
<script>
2-
import { compile, h } from 'vue'
3+
import { h, defineComponent } from 'vue'
34
import meta from 'markdown-it-meta'
45
import MarkdownIt from 'markdown-it'
56
import plugins from './plugins'
@@ -41,11 +42,29 @@
4142
immediate: true,
4243
},
4344
},
44-
mounted: () => {
45+
mounted() {
4546
codeGroups()
4647
},
4748
render() {
48-
return h(compile(this.renderedDocument)(this))
49+
if (!this.renderedDocument) {
50+
return h('div')
51+
}
52+
53+
try {
54+
// Create a wrapper component with the rendered markdown
55+
const template = `<div class="markdown-content">${this.renderedDocument}</div>`
56+
const component = defineComponent({
57+
template,
58+
components: this.$options.components,
59+
})
60+
return h(component)
61+
} catch (error) {
62+
console.error('Markdown render error:', error)
63+
return h('div', {
64+
class: 'markdown-error',
65+
innerHTML: this.renderedDocument,
66+
})
67+
}
4968
},
5069
}
5170
</script>

src/components/simple-markdown/index.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,19 @@
3737
},
3838
3939
render() {
40-
return h(compile(this.renderedDocument, { delimiters: ['${{', '}}'] })(this))
40+
if (!this.renderedDocument) {
41+
return h('div')
42+
}
43+
44+
try {
45+
return h('div', {
46+
class: 'markdown-render',
47+
innerHTML: this.renderedDocument,
48+
})
49+
} catch (error) {
50+
console.error('Markdown render error:', error)
51+
return h('div', { class: 'markdown-error' }, 'Error rendering content')
52+
}
4153
},
4254
}
4355
</script>

0 commit comments

Comments
 (0)