Skip to content

Commit

Permalink
fix: apply set:html for non-layouts too
Browse files Browse the repository at this point in the history
  • Loading branch information
bholmesdev committed Jul 21, 2022
1 parent a16ff2c commit 207a1fa
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/astro/src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,16 @@ const $$content = ${JSON.stringify(content)}
---`;
const imports = `${layout ? `import Layout from '${layout}';` : ''}
${setup}`.trim();

// Wrap with set:html fragment to skip
// JSX expressions and components in "plain" md mode
if (renderOpts.mode === 'md') {
astroResult = `<Fragment set:html={${JSON.stringify(astroResult)}} />`
}

// If the user imported "Layout", wrap the content in a Layout
if (/\bLayout\b/.test(imports)) {
astroResult = `${prelude}\n<Layout content={$$content}>\n\n${
renderOpts.mode === 'md' ? `<Fragment set:html={${JSON.stringify(astroResult)}} />` : astroResult
}\n\n</Layout>`;
astroResult = `${prelude}\n<Layout content={$$content}>\n\n${astroResult}\n\n</Layout>`;
} else {
astroResult = `${prelude}\n${astroResult}`;
}
Expand Down

0 comments on commit 207a1fa

Please sign in to comment.