From 69d5fac61e09fb26e1c5982188ebf7381d36a48e Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 18 Jan 2018 15:43:22 +0000 Subject: [PATCH] Resurrect the old alpha Koenig editor (#9277) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit requires https://github.com/TryGhost/Ghost-Admin/pull/916 - add "enableDeveloperExperiments" config flag - allow any HTML payload through in the HTML mobiledoc card - same approach as taken in the markdown card, running the markup through SimpleDOM isn't necessary and is prone to breaking because of it's limited parsing and error handling abilities To use Koenig modify your `config.development.json` file and add the following flag to the top-level object: ``` "enableDeveloperExperiments": true ``` If you restart the dev server you will then see a new section on the Labs screen with a Koenig Editor checkbox to enable/disable the editor. ⚠️ The editor is in a _very_ broken state, it's there for developer testing and on-going development. _Do not_ try to use this on any production data! --- core/server/api/configuration.js | 3 ++- core/server/lib/mobiledoc/cards/html.js | 13 ++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/server/api/configuration.js b/core/server/api/configuration.js index 2dd9d76fc4..52f6069159 100644 --- a/core/server/api/configuration.js +++ b/core/server/api/configuration.js @@ -30,7 +30,8 @@ function getBaseConfig() { blogUrl: urlService.utils.urlFor('home', true), blogTitle: settingsCache.get('title'), routeKeywords: config.get('routeKeywords'), - clientExtensions: config.get('clientExtensions') + clientExtensions: config.get('clientExtensions'), + enableDeveloperExperiments: config.get('enableDeveloperExperiments') }; } diff --git a/core/server/lib/mobiledoc/cards/html.js b/core/server/lib/mobiledoc/cards/html.js index c78c73f264..0fff642df6 100644 --- a/core/server/lib/mobiledoc/cards/html.js +++ b/core/server/lib/mobiledoc/cards/html.js @@ -1,12 +1,15 @@ -var SimpleDom = require('simple-dom'), - tokenizer = require('simple-html-tokenizer').tokenize, - parser; +'use strict'; module.exports = { name: 'card-html', type: 'dom', render(opts) { - parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap); - return parser.parse('
' + opts.payload.html + '
'); + let html = `
${opts.payload.html}
`; + + // use the SimpleDOM document to create a raw HTML section. + // avoids parsing/rendering of potentially broken or unsupported HTML + let element = opts.env.dom.createRawHTMLSection(html); + + return element; } };