Last active
January 15, 2021 21:53
-
-
Save zstix/569d01a4ab0cebad758137cb1890d5d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const visit = require('unist-util-visit'); | |
const indentedCodeBlock = () => (tree) => { | |
visit( | |
tree, | |
(node) => node.type === 'code', | |
(codeBlock, index, parent) => { | |
const values = codeBlock.value.split('```').filter(Boolean); | |
for (const value of values) { | |
const index = values.indexOf(value); | |
if (index === 0) { | |
codeBlock.value = value; | |
continue; | |
} | |
parent.children.splice(index + 1, 0, { | |
type: i % 2 !== 0 ? 'text', 'code', | |
value, | |
}); | |
}; | |
} | |
); | |
}; | |
module.exports = indentedCodeBlock; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment