diff options
author | 2023-03-21 08:17:20 -0400 | |
---|---|---|
committer | 2023-03-21 08:17:20 -0400 | |
commit | 86273b5881cc61ebee11d40280b4c0aba8f4bb2e (patch) | |
tree | e8846e535df75ddecfc83c092bf8cdff5144c5c3 /packages/integrations/markdoc/components/astroNode.ts | |
parent | 6afb1efea8601cc2bfacec27a8d09c2533fb704a (diff) | |
download | astro-86273b5881cc61ebee11d40280b4c0aba8f4bb2e.tar.gz astro-86273b5881cc61ebee11d40280b4c0aba8f4bb2e.tar.zst astro-86273b5881cc61ebee11d40280b4c0aba8f4bb2e.zip |
[Markdoc] Refactor Renderer internals to use `renderComponent()` (#6607)
* wip: new TreeNode setup
* fix: pass children through `render`
* deps: remove stringify-attributes
* chore: changeset
---------
Co-authored-by: Nate Moore <nate@astro.build>
Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Diffstat (limited to 'packages/integrations/markdoc/components/astroNode.ts')
-rw-r--r-- | packages/integrations/markdoc/components/astroNode.ts | 51 |
1 files changed, 0 insertions, 51 deletions
diff --git a/packages/integrations/markdoc/components/astroNode.ts b/packages/integrations/markdoc/components/astroNode.ts deleted file mode 100644 index 12a0cd0a6..000000000 --- a/packages/integrations/markdoc/components/astroNode.ts +++ /dev/null @@ -1,51 +0,0 @@ -import type { AstroInstance } from 'astro'; -import type { RenderableTreeNode } from '@markdoc/markdoc'; -import Markdoc from '@markdoc/markdoc'; -import { MarkdocError, isCapitalized } from '../dist/utils.js'; - -export type AstroNode = - | string - | { - component: AstroInstance['default']; - props: Record<string, any>; - children: AstroNode[]; - } - | { - tag: string; - attributes: Record<string, any>; - children: AstroNode[]; - }; - -export function createAstroNode( - node: RenderableTreeNode, - components: Record<string, AstroInstance['default']> = {} -): AstroNode { - if (typeof node === 'string' || typeof node === 'number') { - return String(node); - } else if (node === null || typeof node !== 'object' || !Markdoc.Tag.isTag(node)) { - return ''; - } - - if (node.name in components) { - const component = components[node.name]; - const props = node.attributes; - const children = node.children.map((child) => createAstroNode(child, components)); - - return { - component, - props, - children, - }; - } else if (isCapitalized(node.name)) { - throw new MarkdocError({ - message: `Unable to render ${JSON.stringify(node.name)}.`, - hint: 'Did you add this to the "components" prop on your <Content /> component?', - }); - } else { - return { - tag: node.name, - attributes: node.attributes, - children: node.children.map((child) => createAstroNode(child, components)), - }; - } -} |