diff options
author | 2021-09-15 08:03:45 +0800 | |
---|---|---|
committer | 2021-09-14 17:03:45 -0700 | |
commit | 09b2f0e470493c97c8ca3ee9784a18ec33b936ec (patch) | |
tree | 98c5ff77e6d0fc1b8b19c035cf09624db041a3e9 | |
parent | 9cf2df81db9efa6fdaa716a7f7c25323bfeabf9e (diff) | |
download | astro-09b2f0e470493c97c8ca3ee9784a18ec33b936ec.tar.gz astro-09b2f0e470493c97c8ca3ee9784a18ec33b936ec.tar.zst astro-09b2f0e470493c97c8ca3ee9784a18ec33b936ec.zip |
Fix passing Markdown content through props (#1259) (#1343)
Co-authored-by: Kelvin Soh <kelvinsoh@pop-os.localdomain>
Co-authored-by: Fred K. Schott <fkschott@gmail.com>
-rw-r--r-- | .changeset/thirty-clouds-end.md | 5 | ||||
-rw-r--r-- | packages/astro/src/compiler/codegen/index.ts | 1 | ||||
-rw-r--r-- | packages/astro/test/astro-markdown.test.js | 10 | ||||
-rw-r--r-- | packages/astro/test/fixtures/astro-markdown/src/pages/content.astro | 6 |
4 files changed, 22 insertions, 0 deletions
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'; +--- + +<Markdown content={content} />
\ No newline at end of file |