forked from TryGhost/Koenig
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs TryGhost/Ghost#9505 - updates mobiledoc converter's `render` method to accept a `version` argument - `1` === Ghost 1.0's markdown-only renderer output - `2` === Koenig's full mobiledoc renderer output - switch between mobiledoc renderer versions in Post model's `onSaving` hook - version 1 by default - version 2 if Koenig is enabled (currently behind dev experiments config + labs flag) - version 2 if the post's mobiledoc is not compatible with the markdown-only renderer - "version 2" full-Koenig mobiledoc renderer output - wraps content in a `.kg-post` div - removes wrapper around markdown and html card output - adds classes to image card output including selected image size/style - standardises es6 usage across mobiledoc related files
- Loading branch information
1 parent
5716c7d
commit f6effeb
Showing
9 changed files
with
175 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: 'hr', | ||
type: 'dom', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
var hr = require('./hr'), | ||
html = require('./html'), | ||
image = require('./image'), | ||
markdown = require('./markdown'), | ||
cardMarkdown = require('./card-markdown'); | ||
'use strict'; | ||
|
||
const hr = require('./hr'); | ||
const html = require('./html'); | ||
const image = require('./image'); | ||
const markdown = require('./markdown'); | ||
const cardMarkdown = require('./card-markdown'); | ||
|
||
module.exports = [hr, html, image, markdown, cardMarkdown]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
name: 'markdown', | ||
type: 'dom', | ||
render: function (opts) { | ||
var converters = require('../converters'), | ||
html, element; | ||
|
||
let converters = require('../converters'); | ||
let payload = opts.payload; | ||
let version = opts.options.version; | ||
// convert markdown to HTML ready for insertion into dom | ||
html = '<div class="kg-card-markdown">' | ||
+ converters.markdownConverter.render(opts.payload.markdown || '') | ||
+ '</div>'; | ||
let html = converters.markdownConverter.render(payload.markdown || ''); | ||
|
||
// Ghost 1.0's markdown-only renderer wrapped cards | ||
if (version === 1) { | ||
html = `<div class="kg-card-markdown">${html}</div>`; | ||
} | ||
|
||
// use the SimpleDOM document to create a raw HTML section. | ||
// avoids parsing/rendering of potentially broken or unsupported HTML | ||
element = opts.env.dom.createRawHTMLSection(html); | ||
|
||
return element; | ||
return opts.env.dom.createRawHTMLSection(html); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
var should = require('should'), // jshint ignore:line | ||
card = require('../../../../../server/lib/mobiledoc/cards/hr'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
'use strict'; | ||
|
||
const should = require('should'); // jshint ignore:line | ||
const card = require('../../../../../server/lib/mobiledoc/cards/hr'); | ||
const SimpleDom = require('simple-dom'); | ||
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap); | ||
|
||
describe('HR card', function () { | ||
it('generates a horizontal rule', function () { | ||
opts = { | ||
let opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<hr></hr>'); | ||
serializer.serialize(card.render(opts)).should.match('<hr>'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,76 @@ | ||
var should = require('should'), // jshint ignore:line | ||
card = require('../../../../../server/lib/mobiledoc/cards/markdown'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
'use strict'; | ||
|
||
const should = require('should'); // jshint ignore:line | ||
const card = require('../../../../../server/lib/mobiledoc/cards/markdown'); | ||
const SimpleDom = require('simple-dom'); | ||
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap); | ||
|
||
describe('Markdown card', function () { | ||
it('Markdown Card renders', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n- list\r\n- items' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n</div>'); | ||
describe('version 1', function () { | ||
it('Markdown Card renders', function () { | ||
let opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n- list\r\n- items' | ||
}, | ||
options: { | ||
version: 1 | ||
} | ||
}; | ||
|
||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n</div>'); | ||
}); | ||
|
||
it('Accepts invalid HTML in markdown', function () { | ||
let opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n<h2>Heading 2>' | ||
}, | ||
options: { | ||
version: 1 | ||
} | ||
}; | ||
|
||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<h2>Heading 2></div>'); | ||
}); | ||
}); | ||
|
||
it('Accepts invalid HTML in markdown', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n<h2>Heading 2>' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<div class="kg-card-markdown"><h1 id="heading">HEADING</h1>\n<h2>Heading 2></div>'); | ||
describe('version 2', function () { | ||
it('Markdown Card renders', function () { | ||
let opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n- list\r\n- items' | ||
}, | ||
options: { | ||
version: 2 | ||
} | ||
}; | ||
|
||
serializer.serialize(card.render(opts)).should.match('<h1 id="heading">HEADING</h1>\n<ul>\n<li>list</li>\n<li>items</li>\n</ul>\n'); | ||
}); | ||
|
||
it('Accepts invalid HTML in markdown', function () { | ||
let opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
markdown: '#HEADING\r\n<h2>Heading 2>' | ||
}, | ||
options: { | ||
version: 2 | ||
} | ||
}; | ||
|
||
serializer.serialize(card.render(opts)).should.match('<h1 id="heading">HEADING</h1>\n<h2>Heading 2>'); | ||
}); | ||
}); | ||
}); |