-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removed ghost editor dependency (#8137)
refs #7429 - ☢️ 👷🏻♀️ This PR removes the dependency on Ghost-Editor and replaces it with the Mobiledoc DOM renderer. It includes new DOM based default cards and atoms.
- Loading branch information
1 parent
8382be1
commit f61aa66
Showing
20 changed files
with
295 additions
and
726 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var softReturn = require('./soft-return'); | ||
|
||
module.exports = [softReturn]; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
name: 'soft-return', | ||
type: 'dom', | ||
render(opts) { | ||
return opts.env.dom.createElement('br'); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
name: 'hr-card', | ||
type: 'dom', | ||
render(opts) { | ||
return opts.env.dom.createElement('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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
var SimpleDom = require('simple-dom'), | ||
tokenizer = require('simple-html-tokenizer').tokenize, | ||
parser; | ||
|
||
module.exports = { | ||
name: 'html-card', | ||
type: 'dom', | ||
render(opts) { | ||
parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap); | ||
return parser.parse('<div>' + opts.payload.html + '</div>'); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module.exports = { | ||
name: 'image-card', | ||
type: 'dom', | ||
render(opts) { | ||
var img = opts.env.dom.createElement('img'); | ||
img.setAttribute('src', opts.payload.img); | ||
return img; | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var hr = require('./hr'), | ||
html = require('./html'), | ||
image = require('./image'), | ||
markdown = require('./markdown'); | ||
|
||
module.exports = [hr, html, image, markdown]; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
var SimpleDom = require('simple-dom'), | ||
tokenizer = require('simple-html-tokenizer').tokenize, | ||
Showdown = require('showdown-ghost'), | ||
converter = new Showdown.converter({extensions: ['ghostgfm', 'footnotes', 'highlight']}), | ||
parser; | ||
|
||
module.exports = { | ||
name: 'markdown-card', | ||
type: 'dom', | ||
render(opts) { | ||
parser = new SimpleDom.HTMLParser(tokenizer, opts.env.dom, SimpleDom.voidMap); | ||
return parser.parse('<div>' + converter.makeHtml(opts.payload.markdown || '') + '</div>'); | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
var cards = require('./cards'), | ||
atoms = require('./atoms'); | ||
module.exports = { | ||
cards: cards, | ||
atoms: atoms, | ||
activate: function () { | ||
// needed by ghost | ||
} | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var should = require('should'), | ||
card = require('../cards/hr'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
|
||
should = should; | ||
describe('HR card', function () { | ||
it('generates a horizontal rule', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<hr></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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var should = require('should'), | ||
card = require('../cards/html'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
|
||
should = should; | ||
describe('HTML card', function () { | ||
it('HTML Card renders', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
html: '<h1>HEADING</h1><p>PARAGRAPH</p>' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<div><h1>HEADING</h1><p>PARAGRAPH</p></div>'); | ||
}); | ||
it('Plain content renders', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
html: 'CONTENT' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<div>CONTENT</div>'); | ||
}); | ||
it.skip('Invalid HTML returns', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
html: '<h1>HEADING<' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<div><h1>HEADING<</div>'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var should = require('should'), | ||
card = require('../cards/image'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
|
||
should = should; | ||
describe('Image card', function () { | ||
it('generates an image', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
}, | ||
payload: { | ||
img: 'https://www.ghost.org/image.png' | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<img src="https://www.ghost.org/image.png"></img>'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
var should = require('should'), | ||
card = require('../cards/markdown'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
|
||
should = should; | ||
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><h1 id="heading">HEADING</h1>\n\n<ul>\n<li>list</li>\n<li>items</li>\n</ul></div>'); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
var should = require('should'), | ||
card = require('../atoms/soft-return'), | ||
SimpleDom = require('simple-dom'), | ||
opts; | ||
|
||
should = should; | ||
describe('Soft return card', function () { | ||
it('generates a `br` tag', function () { | ||
opts = { | ||
env: { | ||
dom: new SimpleDom.Document() | ||
} | ||
}; | ||
|
||
var serializer = new SimpleDom.HTMLSerializer([]); | ||
serializer.serialize(card.render(opts)).should.match('<br></br>'); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var SimpleDom = require('simple-dom'), | ||
Renderer = require('mobiledoc-dom-renderer').default, | ||
config = require('../config'), | ||
defaults = require(config.get('paths').internalAppPath + 'default-cards'), | ||
options = { | ||
dom: new SimpleDom.Document(), | ||
cards: defaults.cards, | ||
atoms: defaults.atoms | ||
}; | ||
|
||
// function getCards() { | ||
// return config.get('internalApps').reduce( | ||
// function (cards, appName) { | ||
// var app = require(path.join(config.get('paths').internalAppPath, appName)); | ||
// if (app.hasOwnProperty('cards')) { | ||
// cards = cards.concat(app.cards); | ||
// } | ||
// return cards; | ||
// }, [ ]); | ||
// } | ||
// function getAtoms() { | ||
// return config.get('internalApps').reduce( | ||
// function (atoms, appName) { | ||
// var app = require(path.join(config.get('paths').internalAppPath, appName)); | ||
// if (app.hasOwnProperty('atoms')) { | ||
// atoms = atoms.concat(app.atoms); | ||
// } | ||
// return atoms; | ||
// }, [ ]); | ||
// } | ||
|
||
module.exports = { | ||
render: function (mobiledoc) { | ||
var renderer = new Renderer(options), | ||
rendered = renderer.render(mobiledoc), | ||
serializer = new SimpleDom.HTMLSerializer([]), | ||
html = serializer.serializeChildren(rendered.result); | ||
return 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var converter = require('../../../server/utils/mobiledoc-converter'); | ||
|
||
describe('Convert mobiledoc to HTML ', function () { | ||
var mobiledoc = { | ||
version: '0.3.1', | ||
atoms: [], | ||
cards: [ | ||
['markdown-card', | ||
{ | ||
pos: 'top', | ||
card_name: 'markdown-card', | ||
markdown: '#heading\n\n- list one\n- list two\n- list three' | ||
} | ||
], | ||
['markdown-card', { | ||
pos: 'top' | ||
}] | ||
], | ||
markups: [], | ||
sections: [ | ||
[1, 'p', [ | ||
[0, [], 0, 'test'] | ||
]], | ||
[10, 0], | ||
[10, 1] | ||
] | ||
}; | ||
it('Converts a mobiledoc to HTML', function () { | ||
converter.render(mobiledoc).should.match('<p>test</p><div><h1 id="heading">heading</h1>\n\n<ul>\n<li>list one</li>\n<li>list two</li>\n<li>list three</li>\n</ul></div><div></div>'); | ||
}); | ||
}); |
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
Oops, something went wrong.