From 7edc518d5ab46d9e4345396d90c5f0c0bb5c029a Mon Sep 17 00:00:00 2001 From: Ryan McCarvill Date: Tue, 27 Sep 2016 02:23:49 +1300 Subject: [PATCH] [WIP] Mobile-Doc based renderer (#7437) Refs #7429 Added mobile-doc renderer ------------ - Added generic mobiledoc-renderer - Kept the existing showdown editor for legacy mode. --- core/server/models/post.js | 38 +++++++++++++++++++++++--------------- package.json | 1 + 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/core/server/models/post.js b/core/server/models/post.js index fb7cf8772d..23bf113d24 100644 --- a/core/server/models/post.js +++ b/core/server/models/post.js @@ -1,18 +1,20 @@ // # Post Model -var _ = require('lodash'), - uuid = require('node-uuid'), - moment = require('moment'), - Promise = require('bluebird'), - sequence = require('../utils/sequence'), - errors = require('../errors'), - Showdown = require('showdown-ghost'), - converter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}), - ghostBookshelf = require('./base'), - events = require('../events'), - config = require('../config'), - utils = require('../utils'), - baseUtils = require('./base/utils'), - i18n = require('../i18n'), +var _ = require('lodash'), + uuid = require('node-uuid'), + moment = require('moment'), + Promise = require('bluebird'), + sequence = require('../utils/sequence'), + errors = require('../errors'), + Showdown = require('showdown-ghost'), + legacyConverter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}), + Mobiledoc = require('mobiledoc-html-renderer').default, + converter = new Mobiledoc(), + ghostBookshelf = require('./base'), + events = require('../events'), + config = require('../config'), + utils = require('../utils'), + baseUtils = require('./base/utils'), + i18n = require('../i18n'), Post, Posts; @@ -156,6 +158,7 @@ Post = ghostBookshelf.Model.extend({ tagsToCheck = this.get('tags'), publishedAt = this.get('published_at'), publishedAtHasChanged = this.hasDateChanged('published_at'), + mobiledoc = this.get('mobiledoc'), tags = []; // CASE: disallow published -> scheduled @@ -205,7 +208,12 @@ Post = ghostBookshelf.Model.extend({ ghostBookshelf.Model.prototype.saving.call(this, model, attr, options); - this.set('html', converter.makeHtml(_.toString(this.get('markdown')))); + if (mobiledoc) { + this.set('html', converter.render(JSON.parse(mobiledoc)).result); + } else { + // legacy showdown mode + this.set('html', legacyConverter.makeHtml(_.toString(this.get('markdown')))); + } // disabling sanitization until we can implement a better version title = this.get('title') || i18n.t('errors.models.post.untitled'); diff --git a/package.json b/package.json index ab3b29d8e4..5f0399386f 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "knex": "0.12.1", "lodash": "4.16.0", "moment": "2.15.1", + "mobiledoc-html-renderer": "0.3.0", "moment-timezone": "0.5.5", "morgan": "1.7.0", "multer": "1.2.0",