@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 CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2013-2021 Ghost Foundation
3
+ Copyright (c) 2013-2022 Ghost Foundation
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -36,4 +36,4 @@ Follow the instructions for the top-level repo.
36
36
 
37
37
  # Copyright & License
38
38
 
39
- Copyright (c) 2013-2021 Ghost Foundation - Released under the [MIT license](LICENSE).
39
+ Copyright (c) 2013-2022 Ghost Foundation - Released under the [MIT license](LICENSE).
@@ -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
- const rendererOptions = Object.assign({}, this.options, {cardOptions});
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({ghostVersion});
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.1.1",
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.1"
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
- "gitHead": "cfd026c7d40d10e9b1707063a7f5a11ffa90aa42"
29
+ "devDependencies": {
30
+ "c8": "7.11.0"
31
+ },
32
+ "gitHead": "d775807eb5039489e68197b9a2c31ae999499beb"
30
33
  }