Skip to content

Instantly share code, notes, and snippets.

@msikma
Created September 16, 2021 12:24
Show Gist options
  • Save msikma/11476a5bbe029767b0d0985fc4c60de6 to your computer and use it in GitHub Desktop.
Save msikma/11476a5bbe029767b0d0985fc4c60de6 to your computer and use it in GitHub Desktop.
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