0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

[WIP] Mobile-Doc based renderer (#7437)

Refs #7429

Added mobile-doc renderer

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

- Added generic mobiledoc-renderer
- Kept the existing showdown editor for legacy mode.
This commit is contained in:
Ryan McCarvill 2016-09-27 02:23:49 +13:00 committed by Katharina Irrgang
parent 6c24084e68
commit 7edc518d5a
2 changed files with 24 additions and 15 deletions

View file

@ -1,18 +1,20 @@
// # Post Model // # Post Model
var _ = require('lodash'), var _ = require('lodash'),
uuid = require('node-uuid'), uuid = require('node-uuid'),
moment = require('moment'), moment = require('moment'),
Promise = require('bluebird'), Promise = require('bluebird'),
sequence = require('../utils/sequence'), sequence = require('../utils/sequence'),
errors = require('../errors'), errors = require('../errors'),
Showdown = require('showdown-ghost'), Showdown = require('showdown-ghost'),
converter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}), legacyConverter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}),
ghostBookshelf = require('./base'), Mobiledoc = require('mobiledoc-html-renderer').default,
events = require('../events'), converter = new Mobiledoc(),
config = require('../config'), ghostBookshelf = require('./base'),
utils = require('../utils'), events = require('../events'),
baseUtils = require('./base/utils'), config = require('../config'),
i18n = require('../i18n'), utils = require('../utils'),
baseUtils = require('./base/utils'),
i18n = require('../i18n'),
Post, Post,
Posts; Posts;
@ -156,6 +158,7 @@ Post = ghostBookshelf.Model.extend({
tagsToCheck = this.get('tags'), tagsToCheck = this.get('tags'),
publishedAt = this.get('published_at'), publishedAt = this.get('published_at'),
publishedAtHasChanged = this.hasDateChanged('published_at'), publishedAtHasChanged = this.hasDateChanged('published_at'),
mobiledoc = this.get('mobiledoc'),
tags = []; tags = [];
// CASE: disallow published -> scheduled // CASE: disallow published -> scheduled
@ -205,7 +208,12 @@ Post = ghostBookshelf.Model.extend({
ghostBookshelf.Model.prototype.saving.call(this, model, attr, options); 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 // disabling sanitization until we can implement a better version
title = this.get('title') || i18n.t('errors.models.post.untitled'); title = this.get('title') || i18n.t('errors.models.post.untitled');

View file

@ -54,6 +54,7 @@
"knex": "0.12.1", "knex": "0.12.1",
"lodash": "4.16.0", "lodash": "4.16.0",
"moment": "2.15.1", "moment": "2.15.1",
"mobiledoc-html-renderer": "0.3.0",
"moment-timezone": "0.5.5", "moment-timezone": "0.5.5",
"morgan": "1.7.0", "morgan": "1.7.0",
"multer": "1.2.0", "multer": "1.2.0",