@@ -9,6 +9,7 @@ import { VFile } from 'vfile';
99import { computed , defineComponent , PropType , shallowRef , watch , h } from 'vue' ;
1010import { Fragment , JSX } from 'vue/jsx-runtime' ;
1111import { Root as HastRoot , Element , Parents } from 'hast' ;
12+ import { computedAsync } from '@vueuse/core' ;
1213import { defaultUrlTransform } from './utils' ;
1314
1415// 替换 vue3 中的实现,vue3 实现后续参数中不存在 children,渲染函数无法处理 children 的渲染
@@ -123,7 +124,7 @@ export default defineComponent({
123124 } ,
124125 ) ;
125126
126- const renderTree = computed ( ( ) => {
127+ const renderTree = computedAsync ( async ( ) => {
127128 const file = new VFile ( ) ;
128129
129130 // 检测类型
@@ -139,7 +140,7 @@ export default defineComponent({
139140 }
140141
141142 const mdAstTree = processor . value . parse ( file ) ;
142- let hastTree = processor . value . runSync ( mdAstTree , file ) ;
143+ let hastTree = await processor . value . run ( mdAstTree , file ) ;
143144
144145 if ( props . className ) {
145146 hastTree = {
@@ -226,17 +227,21 @@ export default defineComponent({
226227
227228 // 返回渲染函数结果
228229 return ( ) =>
229- toJsxRuntime ( renderTree . value , {
230- Fragment,
231- components : {
232- ...props . components ,
233- ...componentsWithSlot . value ,
234- } ,
235- ignoreInvalidStyle : true ,
236- jsx : jsxWithChildren ,
237- jsxs : jsxWithChildren ,
238- passKeys : true ,
239- passNode : true ,
240- } ) ;
230+ renderTree . value ? (
231+ toJsxRuntime ( renderTree . value , {
232+ Fragment,
233+ components : {
234+ ...props . components ,
235+ ...componentsWithSlot . value ,
236+ } ,
237+ ignoreInvalidStyle : true ,
238+ jsx : jsxWithChildren ,
239+ jsxs : jsxWithChildren ,
240+ passKeys : true ,
241+ passNode : true ,
242+ } )
243+ ) : (
244+ < > </ >
245+ ) ;
241246 } ,
242247} ) ;
0 commit comments