2022-08-14 05:51:45 -04:00
|
|
|
/**
|
2022-11-15 21:33:16 -05:00
|
|
|
* escape markdown so on discord it will be \_ChipMC\_ instead of _ChipMC_
|
2022-08-14 05:51:45 -04:00
|
|
|
* @param {String} text
|
2022-10-16 02:19:14 -04:00
|
|
|
* @param {Boolean} zwsp
|
2022-08-14 05:51:45 -04:00
|
|
|
* @return {String}
|
|
|
|
*/
|
2022-11-27 02:35:28 -05:00
|
|
|
function escapeMarkdown (text, zwsp) {
|
|
|
|
let unescaped
|
|
|
|
let escaped
|
2022-08-14 05:51:45 -04:00
|
|
|
try {
|
2022-11-27 02:35:28 -05:00
|
|
|
unescaped = text.replace(/\\(\*|@|_|`|~|\\)/g, '$1')
|
|
|
|
escaped = unescaped.replace(/(\*|@|_|`|~|\\)/g, zwsp
|
|
|
|
? '\u200b\u200b$1'
|
|
|
|
: '\\$1'
|
|
|
|
)
|
2022-08-14 05:51:45 -04:00
|
|
|
} catch (e) {
|
2022-11-27 02:35:28 -05:00
|
|
|
return unescaped
|
2022-08-14 05:51:45 -04:00
|
|
|
}
|
2022-11-27 02:35:28 -05:00
|
|
|
return escaped
|
2022-08-14 05:51:45 -04:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
module.exports = { escapeMarkdown }
|