Skip to content

Instantly share code, notes, and snippets.

@HyShai
Last active March 2, 2017 17:35
Show Gist options
  • Save HyShai/1b6d7f1392e730b2db5e to your computer and use it in GitHub Desktop.
Save HyShai/1b6d7f1392e730b2db5e to your computer and use it in GitHub Desktop.
convert new lines to <br/> tags for rendering
//helpers/newline-br.js
import Ember from 'ember';
export function newlineBr(text) {
var breakTag = '<br />';
return new Ember.Handlebars.SafeString((text + '')
.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1' + breakTag + '$2'));
}
export default Ember.Handlebars.helper('newLineBr',newlineBr);
// Ember.Handlebars.registerBoundHelper('nl2br', function (text) {
// });
<p>
{{#newline-br}}
{{model.stuff}}
{{/newline-br}}
</p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment