mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Fix parsing of an empty literal <pre></pre>
in markdown source (#1332)
This commit is contained in:
parent
105be57f80
commit
00fd7ca4dc
4 changed files with 38 additions and 0 deletions
6
.changeset/four-plums-train.md
Normal file
6
.changeset/four-plums-train.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
'astro': patch
|
||||
'@astrojs/markdown-support': patch
|
||||
---
|
||||
|
||||
Fix parsing of an empty `<pre></pre>` tag in markdown files, which expected the pre tag to have a child
|
|
@ -35,6 +35,17 @@ Markdown('Runs code blocks through syntax highlighter', async ({ runtime }) => {
|
|||
assert.ok($el.length > 0, 'There are child spans in code blocks');
|
||||
});
|
||||
|
||||
Markdown('Empty code blocks do not fail', async ({ runtime }) => {
|
||||
const result = await runtime.load('/empty-code');
|
||||
assert.ok(!result.error, `build error: ${result.error}`);
|
||||
|
||||
const $ = doc(result.contents);
|
||||
|
||||
const $el = $('pre');
|
||||
assert.ok($el[0].children.length === 1, "There is not a `<code>` in the codeblock");
|
||||
assert.ok($el[1].children.length === 0, "The empty `<pre>` failed to render");
|
||||
});
|
||||
|
||||
Markdown('Scoped styles should not break syntax highlight', async ({ runtime }) => {
|
||||
const result = await runtime.load('/scopedStyles-code');
|
||||
assert.ok(!result.error, `build error: ${result.error}`);
|
||||
|
|
20
packages/astro/test/fixtures/astro-markdown/src/pages/empty-code.md
vendored
Normal file
20
packages/astro/test/fixtures/astro-markdown/src/pages/empty-code.md
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
---
|
||||
title: My Blog Post
|
||||
layout: ../layouts/content.astro
|
||||
---
|
||||
|
||||
## Title
|
||||
|
||||
Hello world
|
||||
|
||||
With this in the body ---
|
||||
|
||||
## Another
|
||||
|
||||
more content
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
|
||||
<pre></pre>
|
|
@ -35,6 +35,7 @@ export function rehypeCodeBlock() {
|
|||
}
|
||||
|
||||
if (node.tagName !== 'pre') return;
|
||||
if (!node.children[0]) return;
|
||||
const code = node.children[0];
|
||||
if (code.type !== 'element' || code.tagName !== 'code') return;
|
||||
node.properties = { ...code.properties };
|
||||
|
|
Loading…
Reference in a new issue