From 09b2f0e470493c97c8ca3ee9784a18ec33b936ec Mon Sep 17 00:00:00 2001 From: kelvinsjk <64682375+kelvinsjk@users.noreply.github.com> Date: Wed, 15 Sep 2021 08:03:45 +0800 Subject: [PATCH] Fix passing Markdown content through props (#1259) (#1343) Co-authored-by: Kelvin Soh Co-authored-by: Fred K. Schott --- .changeset/thirty-clouds-end.md | 5 +++++ packages/astro/src/compiler/codegen/index.ts | 1 + packages/astro/test/astro-markdown.test.js | 10 ++++++++++ .../fixtures/astro-markdown/src/pages/content.astro | 6 ++++++ 4 files changed, 22 insertions(+) create mode 100644 .changeset/thirty-clouds-end.md create mode 100644 packages/astro/test/fixtures/astro-markdown/src/pages/content.astro diff --git a/.changeset/thirty-clouds-end.md b/.changeset/thirty-clouds-end.md new file mode 100644 index 000000000..e783e39a3 --- /dev/null +++ b/.changeset/thirty-clouds-end.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix passing Markdown content through props (#1259) diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts index ff807108e..dd83cdea5 100644 --- a/packages/astro/src/compiler/codegen/index.ts +++ b/packages/astro/src/compiler/codegen/index.ts @@ -810,6 +810,7 @@ async function compileHtml(enterNode: TemplateNode, state: CodegenState, compile async leave(node, parent, prop, index) { switch (node.type) { case 'Fragment': { + if (curr === 'markdown') curr = 'out'; buffers[curr] += `)`; break; } diff --git a/packages/astro/test/astro-markdown.test.js b/packages/astro/test/astro-markdown.test.js index 9e13c0dc2..cf7511dc9 100644 --- a/packages/astro/test/astro-markdown.test.js +++ b/packages/astro/test/astro-markdown.test.js @@ -128,4 +128,14 @@ Markdown('Can render markdown with --- for horizontal rule', async ({ runtime }) // It works! }); +Markdown('Can render markdown content prop (#1259)', async ({ runtime }) => { + const result = await runtime.load('/content'); + assert.ok(!result.error, `build error: ${result.error}`); + + const $ = doc(result.contents); + assert.equal($('h1').text(), 'Foo', 'Markdown rendered correctly via content prop'); + + // It works! +}); + Markdown.run(); diff --git a/packages/astro/test/fixtures/astro-markdown/src/pages/content.astro b/packages/astro/test/fixtures/astro-markdown/src/pages/content.astro new file mode 100644 index 000000000..8c07debd2 --- /dev/null +++ b/packages/astro/test/fixtures/astro-markdown/src/pages/content.astro @@ -0,0 +1,6 @@ +--- +import { Markdown } from 'astro/components'; +const content = '# Foo'; +--- + + \ No newline at end of file