fix: do not crash when Markdown has no content (#1702)

This commit is contained in:
Nate Moore 2021-10-29 11:22:57 -07:00 committed by GitHub
parent c9b33d2b7e
commit 6becdc8cc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
---