Created
March 31, 2021 02:07
-
-
Save willyarisky/890c5cd023cb7ff09be9c457085d4358 to your computer and use it in GitHub Desktop.
Nuxt.js custom plugin for converting new line to tag <br>
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
export default ({ app }, inject) => { | |
const nl2br = (str) => { | |
if (typeof str === 'undefined' || str === null) { | |
return ''; | |
} | |
return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + '<br>' + '$2'); | |
} | |
inject('nl2br', nl2br) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment