Convert preformatted blocks

My wordpress blog had a lot of <pre> sections. The conversion to
markdown ignored those. This change did what I wanted, which was to
turn all of these into markdown code blocks. In my case, there was no
language set on any of my sections to carry over into markdown, so
that isn't handled at all.
This commit is contained in:
Russell Bryant
2023-11-01 19:21:22 -04:00
committed by Will Boyd
parent 6c8e0c8b21
commit de842e51d9
+14
View File
@@ -79,6 +79,20 @@ function initTurndownService() {
}
});
turndownService.addRule("pre", {
filter: (node, options) => {
return (
options.codeBlockStyle === "fenced" &&
node.nodeName === "PRE" &&
node.firstChild
);
},
replacement: (content, node) => {
const code = node.textContent;
return "\n" + "```" + "\n" + code + "\n" + "```" + "\n";
}
});
return turndownService;
}