Last active
August 26, 2022 02:08
-
-
Save nathan-cruz77/6e43ac375103de597edf52e07abfcbff to your computer and use it in GitHub Desktop.
Whatsapp text formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regex to format text to whatsapp format | |
function whatsToHtml(msg) { | |
if (!msg) return; | |
return msg | |
.replace(/~(~*[^~\n]+~*)~/g, '<del>$1</del>') | |
.replace(/_(_*[^_\n]+_*)_/g, '<em>$1</em>') | |
.replace(/\*(\**[^*\n]+\**)\*/g, '<strong>$1</strong>'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For monospace:
And in
CSS
to keep it inline: