mirror of
https://github.com/10h30/wordpress-export-to-markdown.git
synced 2026-07-12 03:06:30 +09:00
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:
committed by
Will Boyd
parent
6c8e0c8b21
commit
de842e51d9
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user