Add escapeMarkdown util function

This commit is contained in:
Schuyler Cebulskie
2016-10-09 14:32:48 -04:00
parent 3e2d6ccc48
commit 7b571f9729
4 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
module.exports = function escapeMarkdown(text, onlyCodeBlock = false) {
if (onlyCodeBlock) return text.replace(/```/g, '`\u200b``');
return text.replace(/\\(\*|_|`|~|\\)/g, '$1').replace(/(\*|_|`|~|\\)/g, '\\$1');
};