-
-
Save msikma/11476a5bbe029767b0d0985fc4c60de6 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 str = `this is a reddit post | |
it has code: \`\`\` | |
const getRootCommand = parserReference => function() { | |
const root = parserReference.objects.find(cmd => cmd.isRootCommand) | |
return root | |
} | |
\`\`\` | |
end of post` | |
const out = str.replace( | |
/```([\s\S]+?)```/gm, | |
(_, code) => `\n${code.split('\n').map(l => ` ${l}`).join('\n')}\n` | |
) | |
console.log(out) | |
// this is a reddit post | |
// | |
// it has code: | |
// | |
// const getRootCommand = parserReference => function() { | |
// const root = parserReference.objects.find(cmd => cmd.isRootCommand) | |
// return root | |
// } | |
// | |
// | |
// | |
// end of post |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment