Fix double <pre> tag (#185)
This commit is contained in:
parent
8f2a58534c
commit
9feffda850
3 changed files with 14 additions and 7 deletions
5
.changeset/olive-jars-grab.md
Normal file
5
.changeset/olive-jars-grab.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Bugfix: fixes double <pre> tags generated from markdown code blocks
|
|
@ -8,7 +8,7 @@
|
|||
"exports": {
|
||||
".": "./astro.mjs",
|
||||
"./snowpack-plugin": "./snowpack-plugin.cjs",
|
||||
"./components/*.astro": "./components/*.astro",
|
||||
"./components/*": "./components/*",
|
||||
"./runtime/svelte": "./dist/frontend/runtime/svelte.js"
|
||||
},
|
||||
"imports": {
|
||||
|
|
|
@ -19,8 +19,11 @@ export default function (module: Script): Transformer {
|
|||
html: {
|
||||
Element: {
|
||||
enter(node) {
|
||||
if (node.name !== 'code') return;
|
||||
const className = getAttrValue(node.attributes, 'class') || '';
|
||||
if (node.name !== 'pre') return;
|
||||
const codeEl = node.children && node.children[0];
|
||||
if (!codeEl || codeEl.name !== 'code') return;
|
||||
|
||||
const className = getAttrValue(codeEl.attributes, 'class') || '';
|
||||
const classes = className.split(' ');
|
||||
|
||||
let lang;
|
||||
|
@ -33,10 +36,9 @@ export default function (module: Script): Transformer {
|
|||
|
||||
if (!lang) return;
|
||||
|
||||
let code;
|
||||
if (node.children?.length) {
|
||||
code = node.children[0].data;
|
||||
}
|
||||
let codeData = codeEl.children && codeEl.children[0];
|
||||
if (!codeData) return;
|
||||
let code = codeData.data as string;
|
||||
|
||||
const repl = {
|
||||
start: 0,
|
||||
|
|
Loading…
Reference in a new issue