fix: Codeblocks

This commit is contained in:
Laegel
2021-04-29 11:59:47 +02:00
parent 29b439bc1f
commit a69856c489
2 changed files with 7 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"rustdocusaurus": patch
---
Generated codeblocks are now valid MD codeblocks with "rs" flavor.

View File

@@ -48,7 +48,7 @@ const removeRustdocTools = (dom) => {
const transformCodeBlocks = (dom) => {
Array.from(dom.window.document.querySelectorAll("pre")).forEach((element) => {
element.prepend(dom.window.document.createTextNode("```\r"));
element.prepend(dom.window.document.createTextNode("```rs\r"));
element.append(dom.window.document.createTextNode("\r```"));
});
};
@@ -80,7 +80,7 @@ const transform = async (contents, crate) => {
let doc = unified().use(stringify).stringify(mdast);
doc
.match(/ *```[\s\S]*```/g)
.match(/ *```rs[\s\S]*```/g)
.map((codeblock) => [codeblock, codeblock.replace(/^ {4}/gm, "")])
.forEach(([original, replacement]) => {
doc = doc.replace(original, replacement);