diff --git a/app/assets/javascripts/discourse/components/cook-text.js.es6 b/app/assets/javascripts/discourse/components/cook-text.js.es6 new file mode 100644 index 00000000000..80ed6935632 --- /dev/null +++ b/app/assets/javascripts/discourse/components/cook-text.js.es6 @@ -0,0 +1,15 @@ +import { cookAsync } from 'discourse/lib/text'; + +const CookText = Ember.Component.extend({ + tagName: '', + cooked: null, + + didReceiveAttrs() { + this._super(...arguments); + cookAsync(this.get('rawText')).then(cooked => this.set('cooked', cooked)); + } +}); + +CookText.reopenClass({ positionalParams: ['rawText'] }); + +export default CookText; diff --git a/app/assets/javascripts/discourse/helpers/cook-text.js.es6 b/app/assets/javascripts/discourse/helpers/cook-text.js.es6 deleted file mode 100644 index c636f0a385b..00000000000 --- a/app/assets/javascripts/discourse/helpers/cook-text.js.es6 +++ /dev/null @@ -1,18 +0,0 @@ -import { cookAsync } from 'discourse/lib/text'; -import guid from 'pretty-text/guid'; -import { registerUnbound } from 'discourse-common/lib/helpers'; - -function cookText(text) { - const id = `${guid().replace(/-/g, '')}`; - - cookAsync(text) - .then(cooked => { - Em.run.next(()=>{ - $('#' + id).html(cooked.string); - }); - }); - - return new Handlebars.SafeString(`
`); -} - -registerUnbound('cook-text', cookText); diff --git a/app/assets/javascripts/discourse/templates/components/cook-text.hbs b/app/assets/javascripts/discourse/templates/components/cook-text.hbs new file mode 100644 index 00000000000..1732a781917 --- /dev/null +++ b/app/assets/javascripts/discourse/templates/components/cook-text.hbs @@ -0,0 +1 @@ +{{cooked}} diff --git a/app/assets/javascripts/discourse/templates/components/queued-post.hbs b/app/assets/javascripts/discourse/templates/components/queued-post.hbs index 6ddd37b864a..4b094fdb210 100644 --- a/app/assets/javascripts/discourse/templates/components/queued-post.hbs +++ b/app/assets/javascripts/discourse/templates/components/queued-post.hbs @@ -34,7 +34,7 @@ {{#if editing}} {{d-editor value=buffered.raw}} {{else}} - {{{cook-text post.raw}}} + {{cook-text post.raw}} {{/if}}