0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-04-15 03:01:37 -05:00

🐛 fix "unbalanced tag" errors on save/import (#8759)

refs https://github.com/TryGhost/Ghost/issues/8757

- remove mobiledoc parsing, it's reliance on SimpleDom makes it too
fragile when dealing with the unconstrained user-entered HTML that is
allowed in markdown
This commit is contained in:
Kevin Ansfield 2017-07-27 12:10:15 +04:00 committed by Katharina Irrgang
parent ce3830f8a9
commit 57ffa4571c

View file

@ -178,7 +178,7 @@ Post = ghostBookshelf.Model.extend({
publishedAt = this.get('published_at'),
publishedAtHasChanged = this.hasDateChanged('published_at', {beforeWrite: true}),
mobiledoc = this.get('mobiledoc'),
tags = [], ops = [];
tags = [], ops = [], markdown, html;
// CASE: disallow published -> scheduled
// @TODO: remove when we have versioning based on updated_at
@ -233,7 +233,11 @@ Post = ghostBookshelf.Model.extend({
ghostBookshelf.Model.prototype.onSaving.call(this, model, attr, options);
if (mobiledoc) {
this.set('html', utils.mobiledocConverter.render(JSON.parse(mobiledoc)));
// NOTE: using direct markdown parsing through markdown-it for now,
// mobiledoc's use of SimpleDom is very fragile with certain HTML
markdown = JSON.parse(mobiledoc).cards[0][1].markdown;
html = utils.markdownConverter.render(markdown);
this.set('html', '<div class="kg-card-markdown">' + html + '</div>');
}
if (this.hasChanged('html') || !this.get('plaintext')) {