@adobe/helix-importer 2.3.6 → 2.4.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [2.4.0](https://github.com/adobe/helix-importer/compare/v2.3.6...v2.4.0) (2023-01-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow to transform and report back ([#59](https://github.com/adobe/helix-importer/issues/59)) ([bfeea5d](https://github.com/adobe/helix-importer/commit/bfeea5ddf24aee30749c6952d2c3cbd83a5b4255))
7
+
1
8
  ## [2.3.6](https://github.com/adobe/helix-importer/compare/v2.3.5...v2.3.6) (2022-12-31)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-importer",
3
- "version": "2.3.6",
3
+ "version": "2.4.0",
4
4
  "description": "Helix Importer tool: create md / docx from html",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -116,10 +116,15 @@ async function html2x(
116
116
  results.forEach((result) => {
117
117
  const name = path.basename(result.path);
118
118
  const dirname = path.dirname(result.path);
119
-
120
- const pir = new PageImporterResource(name, dirname, result.element, null, {
119
+ const extra = {
121
120
  html: result.element.outerHTML,
122
- });
121
+ };
122
+
123
+ if (result.report) {
124
+ extra.report = result.report;
125
+ }
126
+
127
+ const pir = new PageImporterResource(name, dirname, result.element, null, extra);
123
128
  pirs.push(pir);
124
129
  });
125
130
  return pirs;
@@ -181,6 +186,10 @@ async function html2x(
181
186
  html: pir.extra.html,
182
187
  };
183
188
 
189
+ if (pir.extra.report) {
190
+ res.report = pir.extra.report;
191
+ }
192
+
184
193
  res.path = path.resolve(pir.directory, pir.name);
185
194
 
186
195
  if (config.toMd) {
@@ -10,7 +10,7 @@
10
10
  * governing permissions and limitations under the License.
11
11
  */
12
12
 
13
- import { ok, strictEqual } from 'assert';
13
+ import { deepStrictEqual, ok, strictEqual } from 'assert';
14
14
  import { describe, it } from 'mocha';
15
15
  import { JSDOM } from 'jsdom';
16
16
  import { docx2md } from '@adobe/helix-docx2md';
@@ -155,7 +155,7 @@ describe('html2md tests', () => {
155
155
  strictEqual(out2.path, '/folder/my-custom-path-p2');
156
156
  });
157
157
 
158
- it('html2md handles multiple transform', async () => {
158
+ it('html2md handles multiple transform (but single output)', async () => {
159
159
  const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
160
160
  transform: ({ document }) => {
161
161
  const p1 = document.createElement('p');
@@ -176,6 +176,60 @@ describe('html2md tests', () => {
176
176
  strictEqual(out.path, '/my-custom-path-p1');
177
177
  });
178
178
 
179
+ it('html2md allows to report when using transform', async () => {
180
+ const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
181
+ transform: ({ document }) => {
182
+ const p1 = document.createElement('p');
183
+ p1.innerHTML = 'My Hello to the World 1';
184
+
185
+ const p2 = document.createElement('p');
186
+ p2.innerHTML = 'My Hello to the World 2';
187
+
188
+ return [{
189
+ element: p1,
190
+ path: '/my-custom-path-p1',
191
+ report: {
192
+ custom: 'A custom property',
193
+ customArray: ['a', 'b', 'c'],
194
+ customObject: {
195
+ a: 1,
196
+ b: true,
197
+ c: {
198
+ d: 'e',
199
+ },
200
+ },
201
+ },
202
+ }, {
203
+ element: p2,
204
+ path: '/folder/my-custom-path-p2',
205
+ report: {
206
+ custom: 'Another value',
207
+ customArray: ['a', 'b', 'c'],
208
+ somethingElse: 'something else',
209
+ },
210
+ }];
211
+ },
212
+ });
213
+
214
+ const out1 = out[0];
215
+ strictEqual(out1.html.trim(), '<p>My Hello to the World 1</p>');
216
+ strictEqual(out1.md.trim(), 'My Hello to the World 1');
217
+ strictEqual(out1.path, '/my-custom-path-p1');
218
+ ok(out1.report);
219
+ strictEqual(out1.report.custom, 'A custom property');
220
+ deepStrictEqual(out1.report.customArray, ['a', 'b', 'c']);
221
+ deepStrictEqual(out1.report.customObject, { a: 1, b: true, c: { d: 'e' } });
222
+
223
+ const out2 = out[1];
224
+ strictEqual(out2.html.trim(), '<p>My Hello to the World 2</p>');
225
+ strictEqual(out2.md.trim(), 'My Hello to the World 2');
226
+ strictEqual(out2.path, '/folder/my-custom-path-p2');
227
+ ok(out2.report);
228
+ strictEqual(out2.report.custom, 'Another value');
229
+ deepStrictEqual(out2.report.customArray, ['a', 'b', 'c']);
230
+ strictEqual(out2.report.somethingElse, 'something else');
231
+ });
232
+
179
233
  it('html2md does not crash if transform returns null', async () => {
180
234
  const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
181
235
  transform: () => null,