Skip to content

Commit a0dcbff

Browse files
committed
fix: stop bundling markdoc for isTag
1 parent cb19048 commit a0dcbff

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

packages/integrations/markdoc/components/astroNode.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import { RenderableTreeNode, Tag, renderers, NodeType } from '@markdoc/markdoc';
1+
import type { RenderableTreeNode, Tag } from '@markdoc/markdoc';
22
import { escape } from 'html-escaper';
33

44
// TODO: expose `AstroComponentFactory` type from core
55
type 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+
917
export 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

1627
export 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

Comments
 (0)