From 6becdc8cc043fc924ddc2aae9c3382cd56ab8f88 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 29 Oct 2021 11:22:57 -0700 Subject: [PATCH] fix: do not crash when Markdown has no content (#1702) --- packages/astro/components/Markdown.astro | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/packages/astro/components/Markdown.astro b/packages/astro/components/Markdown.astro index 85bc66d5e..862b3a2d4 100644 --- a/packages/astro/components/Markdown.astro +++ b/packages/astro/components/Markdown.astro @@ -12,21 +12,27 @@ interface InternalProps extends Props { let { content, class: className } = Astro.props as InternalProps; let html = null; +let htmlContent = ''; const { privateRenderMarkdownDoNotUse: renderMarkdown } = (Astro as any); // If no content prop provided, use the slot. if (!content) { const { privateRenderSlotDoNotUse: renderSlot } = (Astro as any); - content = dedent(await renderSlot('default')); + content = await renderSlot('default'); + if (content.trim().length > 0) { + content = dedent(content); + } } -const htmlContent = await renderMarkdown(content, { - mode: 'md', - $: { - scopedClassName: className - } -}); +if (content) { + htmlContent = await renderMarkdown(content, { + mode: 'md', + $: { + scopedClassName: className + } + }); +} html = htmlContent; ---