Skip to content

Instantly share code, notes, and snippets.

@willyarisky
Created March 31, 2021 02:07
Show Gist options
  • Save willyarisky/890c5cd023cb7ff09be9c457085d4358 to your computer and use it in GitHub Desktop.
Save willyarisky/890c5cd023cb7ff09be9c457085d4358 to your computer and use it in GitHub Desktop.
Nuxt.js custom plugin for converting new line to tag <br>
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