-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic text not working on ember-cli 2.8 #25
Comments
Error in console while trying to use
They for some reason removed |
Hello, |
By adding |
I'm having similar problems with ember 3.1 with |
@buzzware, I have followed the solution suggested by @vasilakisfil, and have also manually added the component to my updateTemplate() {
this.set('subLayout', null);
scheduleOnce('afterRender', this, function() {
try {
let layout = null;
if (this.get('dynamic'))
layout = Ember.HTMLBars.compile(this.get('parsedMarkdownUnsafe'), false);
else
layout = Ember.HTMLBars.compile(htmlSafe(this.get('parsedMarkdownUnsafe')), false);
this.set('subLayout', layout);
}
catch(error) {}
});
}, ... or at least I believe I have edited it... I may have rolled it back to the original one somehow... but maybe this can guide you in the right direction. |
@danidr Thanks for the reply, but I haven't understood your point. I'm trying to get Ember.HTMLBars.compile to work in production for the dynamic feature of this component with Ember 3.1. There must be another step after app.import to use Ember.HTMLBars.compile as you do. The source is here https://github.com/emberjs/ember.js/blob/87f7ee8a8e76c1809ad32b59eb62fc5cd35daa58/packages/ember-template-compiler/lib/system/compile.js |
I don’t understand why it wasn’t working before, but its working now. |
@danidr I'm now having an issue with the markdown rendering working when the first route is loaded, but when I navigate and then hit the back button, the md-text component doesn't rerender. The model is a POJO, not Ember.Object. Would your updateTemplate code fix this? Can you paste the whole component? I wonder if its something to do with the convoluted way dynamic rendering is happening here eg. md-text.hbs : |
@buzzware Well, I have rewritten the component, but I honestly can't remember WHERE I edited it exactly... import Ember from 'ember';
import Component from '@ember/component';
import { computed, observer } from '@ember/object';
import { getOwner } from '@ember/application';
import { htmlSafe } from '@ember/string';
import { scheduleOnce } from '@ember/runloop';
import Remarkable from 'npm:remarkable';
export default Component.extend({
tagName: '',
text: '',
breaks: true,
typographer: true,
linkify: true,
linkTarget: '',
html: false,
extensions: true,
dynamic: true,
didInsertElement() {
scheduleOnce('afterRender', this, 'updateTemplate');
},
highlightJsExcluded: computed(function () {
let config;
if (getOwner) {
config = getOwner(this).resolveRegistration('config:environment');
} else {
let registry = this.container.registry || this.container._registry;
config = registry.resolve('config:environment');
}
let remarkableConfig = config.remarkable || {};
return remarkableConfig.excludeHighlightJs || false;
}),
highlight: computed('highlightJsExcluded', function() {
let highlightJsExcluded = this.get('highlightJsExcluded');
return (str, lang) => {
if (!highlightJsExcluded) {
if (lang === 'text' || lang === 'no-highlight') {
return '';
}
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (err) {}
}
try {
return hljs.highlightAuto(str).value;
} catch (err) {}
}
return '';
};
}),
parsedMarkdownUnsafe: computed('text', 'html', 'typographer', 'linkify', 'linkTarget', function () {
var md = new Remarkable({
breaks: this.get('breaks'),
typographer: this.get('typographer'),
linkify: this.get('linkify'),
linkTarget: this.get('linkTarget'),
html: this.get('html'),
highlight: this.get('highlight')
});
if (this.get('extensions')) {
md.core.ruler.enable([
'abbr'
]);
md.block.ruler.enable([
'footnote',
'deflist'
]);
md.inline.ruler.enable([
'footnote_inline',
'ins',
'mark',
'sub',
'sup'
]);
}
md.core.ruler.disable([ 'smartquotes' ]);
let plugins = this.get('plugins');
if (plugins) {
plugins.forEach((plugin) => md.use(plugin));
}
return md.render(this.get('text'));
}),
updateTemplate() {
this.set('subLayout', null);
scheduleOnce('afterRender', this, function() {
try {
let layout = null;
if (this.get('dynamic'))
layout = Ember.HTMLBars.compile(this.get('parsedMarkdownUnsafe'), false);
else
layout = Ember.HTMLBars.compile(htmlSafe(this.get('parsedMarkdownUnsafe')), false);
this.set('subLayout', layout);
}
catch(error) {}
});
},
observerSource: observer('text', function() { this.updateTemplate(); }),
}).reopenClass({
positionalParams: ['text']
});
import Component from '@ember/component';
export default Component.extend({
tagName: ''
});
{{#if subLayout}}
{{md-text-renderer layout=subLayout}}
{{/if}} NOTES:
Let me know if it helps somehow. |
Big thanks @danidr ! Thats working. This dynamic rendering is very cool. I'm using it with https://github.com/buzzware/broccoli-static-site-json#remove-showdown to achieve something a bit like https://www.gatsbyjs.org ie dynamically loaded markdown with ember components |
@buzzware Glad to hear it worked! I'll have a look at your code. |
Works fine without the dynamic flag. No error in console or anything, just a blank page.
The text was updated successfully, but these errors were encountered: