Fix double <pre> tag (#185)

This commit is contained in:
Drew Powers 2021-05-07 15:48:45 -06:00 committed by GitHub
parent 8f2a58534c
commit 9feffda850
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Bugfix: fixes double <pre> tags generated from markdown code blocks

View file

@ -8,7 +8,7 @@
"exports": { "exports": {
".": "./astro.mjs", ".": "./astro.mjs",
"./snowpack-plugin": "./snowpack-plugin.cjs", "./snowpack-plugin": "./snowpack-plugin.cjs",
"./components/*.astro": "./components/*.astro", "./components/*": "./components/*",
"./runtime/svelte": "./dist/frontend/runtime/svelte.js" "./runtime/svelte": "./dist/frontend/runtime/svelte.js"
}, },
"imports": { "imports": {

View file

@ -19,8 +19,11 @@ export default function (module: Script): Transformer {
html: { html: {
Element: { Element: {
enter(node) { enter(node) {
if (node.name !== 'code') return; if (node.name !== 'pre') return;
const className = getAttrValue(node.attributes, 'class') || ''; const codeEl = node.children && node.children[0];
if (!codeEl || codeEl.name !== 'code') return;
const className = getAttrValue(codeEl.attributes, 'class') || '';
const classes = className.split(' '); const classes = className.split(' ');
let lang; let lang;
@ -33,10 +36,9 @@ export default function (module: Script): Transformer {
if (!lang) return; if (!lang) return;
let code; let codeData = codeEl.children && codeEl.children[0];
if (node.children?.length) { if (!codeData) return;
code = node.children[0].data; let code = codeData.data as string;
}
const repl = { const repl = {
start: 0, start: 0,