Skip to content

Commit

Permalink
Markdown bug bash! (withastro#1789)
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re authored Nov 10, 2021
1 parent 036588e commit bb11c63
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/runtime/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export function createAstro(fileURLStr: string, site: string): TopLevelAstro {
};
}

const toAttributeString = (value: any) => String(value).replace(/&/g, '&').replace(/"/g, '"')

// A helper used to turn expressions into attribute key/value
export function addAttribute(value: any, key: string) {
if (value == null || value === false) {
Expand All @@ -216,10 +218,10 @@ export function addAttribute(value: any, key: string) {

// support "class" from an expression passed into an element (#782)
if (key === 'class:list') {
return ` ${key.slice(0, -5)}="${serializeListValue(value)}"`;
return ` ${key.slice(0, -5)}="${toAttributeString(serializeListValue(value))}"`;
}

return ` ${key}="${value}"`;
return ` ${key}="${toAttributeString(value)}"`;
}

// Adds support for `<Component {...value} />
Expand Down
3 changes: 2 additions & 1 deletion src/vite-plugin-markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ export default function markdown({ config }: AstroPluginOptions): Plugin {
${layout ? `import Layout from '${layout}';` : ''}
${components ? `import * from '${components}';` : ''}
${setup}
const $$content = ${JSON.stringify(content)}
---`;
// If the user imported "Layout", wrap the content in a Layout
if (/\bLayout\b/.test(prelude)) {
astroResult = `${prelude}\n<Layout content={${JSON.stringify(content)}}>\n\n${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 bb11c63

Please sign in to comment.