0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

Fix parsing of an empty literal <pre></pre> in markdown source (#1332)

This commit is contained in:
Caleb Jasik 2021-09-07 15:22:23 -05:00 committed by GitHub
parent 105be57f80
commit 00fd7ca4dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View 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

View file

@ -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'); 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 }) => { Markdown('Scoped styles should not break syntax highlight', async ({ runtime }) => {
const result = await runtime.load('/scopedStyles-code'); const result = await runtime.load('/scopedStyles-code');
assert.ok(!result.error, `build error: ${result.error}`); assert.ok(!result.error, `build error: ${result.error}`);

View 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>

View file

@ -35,6 +35,7 @@ export function rehypeCodeBlock() {
} }
if (node.tagName !== 'pre') return; if (node.tagName !== 'pre') return;
if (!node.children[0]) return;
const code = node.children[0]; const code = node.children[0];
if (code.type !== 'element' || code.tagName !== 'code') return; if (code.type !== 'element' || code.tagName !== 'code') return;
node.properties = { ...code.properties }; node.properties = { ...code.properties };