0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added parsing of html cards when using ?source=html with the v2 Admin API

no issue

- when sending `html` with `?source=html` to the v2 Admin API it's now possible to include blocks of HTML that will be extracted to html cards rather than going through the normal lossy html-to-mobiledoc conversion

Example usage would be sending HTML in the following format:

```html
<p>Some standard content...</p>

<!--kg-card-begin: html-->
<div class="my-custom-html">...</div>
<!--kg-card-end: html-->

<p>Some more content...</p>
```

In this case an html card will be created in the mobiledoc with the content `<div class="my-custom-html">...</div>`.
This commit is contained in:
Kevin Ansfield 2019-05-04 11:30:59 +01:00
parent 9f9dde3107
commit 75ae3f8736
3 changed files with 37 additions and 15 deletions

View file

@ -448,6 +448,28 @@ describe('Unit: v2/utils/serializers/input/posts', function () {
postData.mobiledoc.should.not.equal(mobiledoc);
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[],"markups":[],"sections":[[1,"p",[[0,[],0,"this is great feature"]]]]}');
});
it('preserves html cards in transformed html', function () {
const apiConfig = {};
const frame = {
options: {
source: 'html'
},
data: {
posts: [
{
id: 'id1',
html: '<p>this is great feature</p>\n<!--kg-card-begin: html--><div class="custom">My Custom HTML</div><!--kg-card-end: html-->\n<p>custom html preserved!</p>',
}
]
}
};
serializers.input.posts.edit(apiConfig, frame);
let postData = frame.data.posts[0];
postData.mobiledoc.should.equal('{"version":"0.3.1","atoms":[],"cards":[["html",{"html":"<div class=\"custom\">My Custom HTML</div>"}]],"markups":[],"sections":[[1,"p",[[0,[],0,"this is great feature"]]],[10,0],[1,"p",[[0,[],0,"custom html preserved!"]]]]}');
});
});
describe('Ensure relations format', function () {

View file

@ -119,7 +119,7 @@
"xml": "1.0.1"
},
"optionalDependencies": {
"@tryghost/html-to-mobiledoc": "0.3.0",
"@tryghost/html-to-mobiledoc": "0.4.0",
"sharp": "0.21.3",
"sqlite3": "4.0.6"
},

View file

@ -111,13 +111,13 @@
dependencies:
lodash-es "^4.17.11"
"@tryghost/html-to-mobiledoc@0.3.0":
version "0.3.0"
resolved "https://registry.yarnpkg.com/@tryghost/html-to-mobiledoc/-/html-to-mobiledoc-0.3.0.tgz#6985fac775000c0ea96c3a36e3275c68a8b83f7e"
integrity sha512-X69oETTdfjSwi99t0tMkRzwNBrNBOV4elhS0kpDuvfQ/zKhuzlRgjvsGIvzX8zG0/NYm1ZlUaOpgBRz6i6P17w==
"@tryghost/html-to-mobiledoc@0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@tryghost/html-to-mobiledoc/-/html-to-mobiledoc-0.4.0.tgz#2dd7111c10213634bfd39dc00d5171abe0f2a321"
integrity sha512-YIBqjfXy2l51/zMpNuHilDkZizxF7WYRkATKqh7uKy2UJs+yeJq9gwQBojAvwDOc8Lmdwj/sJGLlg5jWs9dRCA==
dependencies:
"@tryghost/kg-parser-plugins" "^0.4.1"
"@tryghost/mobiledoc-kit" "^0.11.2-ghost.1"
"@tryghost/kg-parser-plugins" "^0.5.0"
"@tryghost/mobiledoc-kit" "^0.11.2-ghost.3"
jsdom "14.1.0"
"@tryghost/kg-clean-basic-html@^0.1.1":
@ -125,10 +125,10 @@
resolved "https://registry.yarnpkg.com/@tryghost/kg-clean-basic-html/-/kg-clean-basic-html-0.1.1.tgz#a065a5771c29af47d7e681fc6ac2db445b839daf"
integrity sha512-pHszGBQMo6r9YTg9VTDJsn0+i+rRNTs09dAMI8ZbD11AP0ten5XJxIqLQuDJJwIrchZ91J2rl+LMgnQo1yIyNw==
"@tryghost/kg-parser-plugins@^0.4.1":
version "0.4.1"
resolved "https://registry.yarnpkg.com/@tryghost/kg-parser-plugins/-/kg-parser-plugins-0.4.1.tgz#d504976e2ec9eb5fdfdca19fecf3a03a94aebf08"
integrity sha512-J1Gn91hIG2pxgwWymPnKcsWsF4BB08tR+Qdg9uqyE5JGwIGGQdNTxgbXSRaMOcHorlmNKqb0bZlnk2l2d/AAYA==
"@tryghost/kg-parser-plugins@^0.5.0":
version "0.5.0"
resolved "https://registry.yarnpkg.com/@tryghost/kg-parser-plugins/-/kg-parser-plugins-0.5.0.tgz#def06ea586e1a075105531f289d49f9c91996203"
integrity sha512-0Vq0lfSXKkn8mLYb4Wz0VlK7pNtrhoioPQnG8o+/Juu8r4CHtHiLgGqTPWzPntd4wXNnBLAS3SppPE5GRM1Wng==
dependencies:
"@tryghost/kg-clean-basic-html" "^0.1.1"
@ -184,10 +184,10 @@
ghost-ignition "^3.1.0"
lodash "^4.17.11"
"@tryghost/mobiledoc-kit@^0.11.2-ghost.1":
version "0.11.2-ghost.1"
resolved "https://registry.yarnpkg.com/@tryghost/mobiledoc-kit/-/mobiledoc-kit-0.11.2-ghost.1.tgz#7088eb9eef06b4ccdd6c221613f20d01b106f939"
integrity sha512-oc5zAQiEzq0oSUb3NpAXHvfcQ+FOjzQ+1sRNv2QwSJ+JftanpdFvgmc9BwX8dZAlHA/NOnrIeTW1Q2Ip9Nm2Ag==
"@tryghost/mobiledoc-kit@^0.11.2-ghost.3":
version "0.11.2-ghost.3"
resolved "https://registry.yarnpkg.com/@tryghost/mobiledoc-kit/-/mobiledoc-kit-0.11.2-ghost.3.tgz#15d5ad0ce0b2c4322ba5e2fc87f641dcb387e8ff"
integrity sha512-R07zG7vLViPt2SmJSQXPTdgakfsra9GcP+O2saa0SYzfdTE/+3+hMo0PgJSwcyCx898mJmQv6L1lgu7N7qjihw==
dependencies:
mobiledoc-dom-renderer "0.6.5"
mobiledoc-text-renderer "0.3.2"