1- import { RenderableTreeNode , Tag , renderers , NodeType } from '@markdoc/markdoc' ;
1+ import type { RenderableTreeNode , Tag } from '@markdoc/markdoc' ;
22import { escape } from 'html-escaper' ;
33
44// TODO: expose `AstroComponentFactory` type from core
55type AstroComponentFactory = ( props : Record < string , any > ) => any & {
66 isAstroComponentFactory : true ;
77} ;
88
9+ /**
10+ * Copied from Markdoc Tag.isTag implementation
11+ * to avoid dragging the whole 40kb Markdoc bundle into your build!
12+ */
13+ function isTag ( tag : any ) : tag is Tag {
14+ return ! ! ( tag ?. $$mdtype === 'Tag' ) ;
15+ }
16+
917export type ComponentRenderer =
1018 | AstroComponentFactory
1119 | {
1220 component : AstroComponentFactory ;
13- props ?( params : { attributes : Record < string , any > ; getTreeNode ( ) : Tag } ) : Record < string , any > ;
21+ props ?( params : {
22+ attributes : Record < string , any > ;
23+ getTreeNode ( ) : import ( '@markdoc/markdoc' ) . Tag ;
24+ } ) : Record < string , any > ;
1425 } ;
1526
1627export type AstroNode =
@@ -32,7 +43,7 @@ export function createAstroNode(
3243) : AstroNode {
3344 if ( typeof node === 'string' || typeof node === 'number' ) {
3445 return escape ( String ( node ) ) ;
35- } else if ( node === null || typeof node !== 'object' || ! Tag . isTag ( node ) ) {
46+ } else if ( node === null || typeof node !== 'object' || ! isTag ( node ) ) {
3647 return '' ;
3748 }
3849
0 commit comments