@tryghost/kg-mobiledoc-html-renderer 5.1.1 → 5.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/mobiledoc-html-renderer.js +33 -2
- package/package.json +7 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -74,6 +74,19 @@ class DomModifier {
|
|
|
74
74
|
node.setAttribute('id', id);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
wrapBlockquoteContentInP(node) {
|
|
78
|
+
if (node.firstChild && node.firstChild.tagName === 'P') {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const p = this.options.dom.createElement('p');
|
|
83
|
+
while (node.firstChild) {
|
|
84
|
+
p.appendChild(node.firstChild);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
node.appendChild(p);
|
|
88
|
+
}
|
|
89
|
+
|
|
77
90
|
modifyChildren(node) {
|
|
78
91
|
walkDom(node, this.modify.bind(this));
|
|
79
92
|
}
|
|
@@ -83,6 +96,11 @@ class DomModifier {
|
|
|
83
96
|
if (node.nodeType === 1 && node.nodeName.match(/^h\d$/i)) {
|
|
84
97
|
this.addHeadingId(node);
|
|
85
98
|
}
|
|
99
|
+
|
|
100
|
+
// wrap blockquote content in P tag for emails
|
|
101
|
+
if (this.options.target === 'email' && node.nodeType === 1 && node.nodeName === 'BLOCKQUOTE') {
|
|
102
|
+
this.wrapBlockquoteContentInP(node);
|
|
103
|
+
}
|
|
86
104
|
}
|
|
87
105
|
}
|
|
88
106
|
|
|
@@ -98,12 +116,25 @@ class MobiledocHtmlRenderer {
|
|
|
98
116
|
|
|
99
117
|
render(mobiledoc, _cardOptions = {}) {
|
|
100
118
|
const ghostVersion = mobiledoc.ghostVersion || '4.0';
|
|
119
|
+
|
|
101
120
|
const defaultCardOptions = {
|
|
102
121
|
ghostVersion,
|
|
103
122
|
target: 'html'
|
|
104
123
|
};
|
|
105
124
|
const cardOptions = Object.assign({}, defaultCardOptions, _cardOptions);
|
|
106
|
-
|
|
125
|
+
|
|
126
|
+
const sectionElementRenderer = {
|
|
127
|
+
ASIDE: function (tagName, dom) {
|
|
128
|
+
// we use ASIDE sections in Koenig as a workaround for applying
|
|
129
|
+
// a different blockquote style because mobiledoc doesn't support
|
|
130
|
+
// storing arbitrary attributes with sections
|
|
131
|
+
const blockquote = dom.createElement('blockquote');
|
|
132
|
+
blockquote.setAttribute('class', 'kg-blockquote-alt');
|
|
133
|
+
return blockquote;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const rendererOptions = Object.assign({}, this.options, {cardOptions, sectionElementRenderer});
|
|
107
138
|
const renderer = new Renderer(rendererOptions);
|
|
108
139
|
const rendered = renderer.render(mobiledoc);
|
|
109
140
|
const serializer = new SimpleDom.HTMLSerializer(SimpleDom.voidMap);
|
|
@@ -119,7 +150,7 @@ class MobiledocHtmlRenderer {
|
|
|
119
150
|
|
|
120
151
|
// Walk the DOM output and modify nodes as needed
|
|
121
152
|
// eg. to add ID attributes to heading elements
|
|
122
|
-
const modifier = new DomModifier({
|
|
153
|
+
const modifier = new DomModifier(Object.assign({}, cardOptions, {dom: this.options.dom}));
|
|
123
154
|
modifier.modifyChildren(rendered.result);
|
|
124
155
|
|
|
125
156
|
const output = serializer.serializeChildren(rendered.result);
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/kg-mobiledoc-html-renderer",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-mobiledoc-html-renderer",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
8
8
|
"scripts": {
|
|
9
9
|
"dev": "echo \"Implement me!\"",
|
|
10
|
-
"test": "NODE_ENV=testing mocha './test/**/*.test.js'",
|
|
10
|
+
"test": "NODE_ENV=testing c8 --reporter text --reporter cobertura mocha './test/**/*.test.js'",
|
|
11
11
|
"lint": "eslint . --ext .js --cache",
|
|
12
12
|
"posttest": "yarn lint"
|
|
13
13
|
},
|
|
14
14
|
"engines": {
|
|
15
|
-
"node": "^12.22.1 || ^14.16.
|
|
15
|
+
"node": "^12.22.1 || ^14.17.0 || ^16.13.0"
|
|
16
16
|
},
|
|
17
17
|
"files": [
|
|
18
18
|
"index.js",
|
|
@@ -26,5 +26,8 @@
|
|
|
26
26
|
"semver": "^7.3.4",
|
|
27
27
|
"simple-dom": "^1.4.0"
|
|
28
28
|
},
|
|
29
|
-
"
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"c8": "7.11.0"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "d775807eb5039489e68197b9a2c31ae999499beb"
|
|
30
33
|
}
|