Skip to content

Commit

Permalink
[WIP] Mobile-Doc based renderer (#7437)
Browse files Browse the repository at this point in the history
Refs #7429

Added mobile-doc renderer

------------

- Added generic mobiledoc-renderer
- Kept the existing showdown editor for legacy mode.
  • Loading branch information
disordinary authored and kirrg001 committed Sep 26, 2016
1 parent 6c24084 commit 7edc518
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
38 changes: 23 additions & 15 deletions core/server/models/post.js
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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');
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 7edc518

Please sign in to comment.