mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-12-18 03:12:23 -05:00
19 lines
532 B
JavaScript
19 lines
532 B
JavaScript
/* eslint-disable no-var */
|
|
/* eslint-disable max-len */
|
|
/**
|
|
* escape markdown so on discord it will be \_ChipMC\_ instead of ChipMC in italic
|
|
* @param {String} text
|
|
* @param {Boolean} zwsp
|
|
* @return {String}
|
|
*/
|
|
function escapeMarkdown(text, zwsp) {
|
|
try {
|
|
var unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1');
|
|
var escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp ? '\u200b\u200b\u200b\u200b\u200b$1' : '\\$1');
|
|
} catch (e) {
|
|
return unescaped;
|
|
}
|
|
return escaped;
|
|
}
|
|
|
|
module.exports = {escapeMarkdown};
|