mirror of
https://github.com/ChomeNS/chomens-bot-mc.git
synced 2024-11-14 10:44:55 -05:00
18 lines
457 B
JavaScript
18 lines
457 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
|
|
* @return {String}
|
|
*/
|
|
function escapeMarkdown(text) {
|
|
try {
|
|
var unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1');
|
|
var escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, '\\$1');
|
|
} catch (e) {
|
|
return unescaped;
|
|
}
|
|
return escaped;
|
|
}
|
|
|
|
module.exports = {escapeMarkdown};
|