mirror of
https://github.com/flarum/framework.git
synced 2025-01-31 14:11:01 +08:00
Ensure scripts provided by textformatter are run (#2415)
This commit is contained in:
parent
89f7827f6b
commit
90584bd6ef
|
@ -56,9 +56,7 @@ export default class CommentPost extends Post {
|
|||
]);
|
||||
}
|
||||
|
||||
onupdate(vnode) {
|
||||
super.onupdate();
|
||||
|
||||
refreshContent() {
|
||||
const contentHtml = this.isEditing() ? '' : this.attrs.post.contentHtml();
|
||||
|
||||
// If the post content has changed since the last render, we'll run through
|
||||
|
@ -66,13 +64,28 @@ export default class CommentPost extends Post {
|
|||
// necessary because TextFormatter outputs them for e.g. syntax highlighting.
|
||||
if (this.contentHtml !== contentHtml) {
|
||||
this.$('.Post-body script').each(function () {
|
||||
eval.call(window, $(this).text());
|
||||
const script = document.createElement('script');
|
||||
script.textContent = this.textContent;
|
||||
Array.from(this.attributes).forEach((attr) => script.setAttribute(attr.name, attr.value));
|
||||
this.parentNode.replaceChild(script, this);
|
||||
});
|
||||
}
|
||||
|
||||
this.contentHtml = contentHtml;
|
||||
}
|
||||
|
||||
oncreate(vnode) {
|
||||
super.oncreate(vnode);
|
||||
|
||||
this.refreshContent();
|
||||
}
|
||||
|
||||
onupdate(vnode) {
|
||||
super.onupdate(vnode);
|
||||
|
||||
this.refreshContent();
|
||||
}
|
||||
|
||||
isEditing() {
|
||||
return app.composer.bodyMatches(EditPostComposer, { post: this.attrs.post });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user