@tryghost/kg-mobiledoc-html-renderer 5.3.0 → 5.3.4
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 +21 -26
- package/package.json +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const SimpleDom = require('simple-dom');
|
|
2
|
-
const semver = require('semver');
|
|
3
2
|
const Renderer = require('mobiledoc-dom-renderer').default;
|
|
3
|
+
const {slugify} = require('@tryghost/kg-utils');
|
|
4
4
|
|
|
5
5
|
const walkDom = function (node, func) {
|
|
6
6
|
func(node);
|
|
@@ -24,29 +24,6 @@ const nodeTextContent = function (node) {
|
|
|
24
24
|
return textContent;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const slugify = function (inputString, {ghostVersion = '4.0'} = {}) {
|
|
28
|
-
const version = semver.coerce(ghostVersion);
|
|
29
|
-
|
|
30
|
-
if (semver.satisfies(version, '<4.x')) {
|
|
31
|
-
// backwards compatible slugs used in Ghost 2.x to 3.x mobiledoc
|
|
32
|
-
return inputString.replace(/[<>&"?]/g, '')
|
|
33
|
-
.trim()
|
|
34
|
-
.replace(/[^\w]/g, '-')
|
|
35
|
-
.replace(/-{2,}/g, '-')
|
|
36
|
-
.toLowerCase();
|
|
37
|
-
} else {
|
|
38
|
-
// news slugs introduced in 4.0
|
|
39
|
-
// allows all chars except symbols but will urlEncode everything
|
|
40
|
-
// produces %-encoded chars in src but browsers show real chars in status bar and url bar
|
|
41
|
-
return encodeURIComponent(inputString.trim()
|
|
42
|
-
.toLowerCase()
|
|
43
|
-
.replace(/[\][!"#$%&'()*+,./:;<=>?@\\^_{|}~]/g, '')
|
|
44
|
-
.replace(/\s+/g, '-')
|
|
45
|
-
.replace(/^-|-{2,}|-$/g, '')
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
27
|
// used to walk the rendered SimpleDOM output and modify elements before
|
|
51
28
|
// serializing to HTML. Saves having a large HTML parsing dependency such as
|
|
52
29
|
// jsdom that may break on malformed HTML in MD or HTML cards
|
|
@@ -74,6 +51,19 @@ class DomModifier {
|
|
|
74
51
|
node.setAttribute('id', id);
|
|
75
52
|
}
|
|
76
53
|
|
|
54
|
+
wrapBlockquoteContentInP(node) {
|
|
55
|
+
if (node.firstChild && node.firstChild.tagName === 'P') {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const p = this.options.dom.createElement('p');
|
|
60
|
+
while (node.firstChild) {
|
|
61
|
+
p.appendChild(node.firstChild);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
node.appendChild(p);
|
|
65
|
+
}
|
|
66
|
+
|
|
77
67
|
modifyChildren(node) {
|
|
78
68
|
walkDom(node, this.modify.bind(this));
|
|
79
69
|
}
|
|
@@ -83,6 +73,11 @@ class DomModifier {
|
|
|
83
73
|
if (node.nodeType === 1 && node.nodeName.match(/^h\d$/i)) {
|
|
84
74
|
this.addHeadingId(node);
|
|
85
75
|
}
|
|
76
|
+
|
|
77
|
+
// wrap blockquote content in P tag for emails
|
|
78
|
+
if (this.options.target === 'email' && node.nodeType === 1 && node.nodeName === 'BLOCKQUOTE') {
|
|
79
|
+
this.wrapBlockquoteContentInP(node);
|
|
80
|
+
}
|
|
86
81
|
}
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -111,7 +106,7 @@ class MobiledocHtmlRenderer {
|
|
|
111
106
|
// a different blockquote style because mobiledoc doesn't support
|
|
112
107
|
// storing arbitrary attributes with sections
|
|
113
108
|
const blockquote = dom.createElement('blockquote');
|
|
114
|
-
blockquote.setAttribute('class', 'kg-blockquote-alt
|
|
109
|
+
blockquote.setAttribute('class', 'kg-blockquote-alt');
|
|
115
110
|
return blockquote;
|
|
116
111
|
}
|
|
117
112
|
};
|
|
@@ -132,7 +127,7 @@ class MobiledocHtmlRenderer {
|
|
|
132
127
|
|
|
133
128
|
// Walk the DOM output and modify nodes as needed
|
|
134
129
|
// eg. to add ID attributes to heading elements
|
|
135
|
-
const modifier = new DomModifier({
|
|
130
|
+
const modifier = new DomModifier(Object.assign({}, cardOptions, {dom: this.options.dom}));
|
|
136
131
|
modifier.modifyChildren(rendered.result);
|
|
137
132
|
|
|
138
133
|
const output = serializer.serializeChildren(rendered.result);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tryghost/kg-mobiledoc-html-renderer",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.4",
|
|
4
4
|
"repository": "https://github.com/TryGhost/Koenig/tree/master/packages/kg-mobiledoc-html-renderer",
|
|
5
5
|
"author": "Ghost Foundation",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,12 +22,12 @@
|
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@tryghost/kg-utils": "^1.0.1",
|
|
25
26
|
"mobiledoc-dom-renderer": "^0.7.0",
|
|
26
|
-
"semver": "^7.3.4",
|
|
27
27
|
"simple-dom": "^1.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"c8": "7.
|
|
30
|
+
"c8": "7.11.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "9ef2eefcee55e3ef3a823a007f169c2e3b34d9d0"
|
|
33
33
|
}
|