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": {
|
"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": {
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue