@adobe/helix-importer 2.4.0 → 2.5.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,17 @@
1
+ # [2.5.0](https://github.com/adobe/helix-importer/compare/v2.4.1...v2.5.0) (2023-01-09)
2
+
3
+
4
+ ### Features
5
+
6
+ * allow no element to be provided in transform returned object ([44e4167](https://github.com/adobe/helix-importer/commit/44e4167abd00e796a2b4f68a0384a9cdd8618c31))
7
+
8
+ ## [2.4.1](https://github.com/adobe/helix-importer/compare/v2.4.0...v2.4.1) (2023-01-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **deps:** update adobe fixes ([#61](https://github.com/adobe/helix-importer/issues/61)) ([82138df](https://github.com/adobe/helix-importer/commit/82138df79d256befb7602d8181366cf7ee454aeb))
14
+
1
15
  # [2.4.0](https://github.com/adobe/helix-importer/compare/v2.3.6...v2.4.0) (2023-01-05)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-importer",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Helix Importer tool: create md / docx from html",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -27,7 +27,7 @@
27
27
  "devDependencies": {
28
28
  "@adobe/eslint-config-helix": "1.3.2",
29
29
  "@adobe/helix-docx2md": "1.3.7",
30
- "@adobe/helix-mediahandler": "1.2.24",
30
+ "@adobe/helix-mediahandler": "1.2.25",
31
31
  "@semantic-release/changelog": "6.0.2",
32
32
  "@semantic-release/exec": "6.0.3",
33
33
  "@semantic-release/git": "10.0.1",
@@ -37,7 +37,7 @@
37
37
  "eslint-import-resolver-exports": "1.0.0-beta.3",
38
38
  "eslint-plugin-header": "3.1.1",
39
39
  "eslint-plugin-import": "2.26.0",
40
- "husky": "8.0.2",
40
+ "husky": "8.0.3",
41
41
  "lint-staged": "13.1.0",
42
42
  "mocha": "10.2.0",
43
43
  "mocha-multi-reporters": "1.5.1",
@@ -47,7 +47,7 @@
47
47
  "license": "Apache-2.0",
48
48
  "dependencies": {
49
49
  "@adobe/helix-markdown-support": "6.0.0",
50
- "@adobe/helix-md2docx": "2.0.27",
50
+ "@adobe/helix-md2docx": "2.0.28",
51
51
  "@adobe/mdast-util-gridtables": "1.0.3",
52
52
  "@adobe/remark-gridtables": "1.0.0",
53
53
  "form-data": "4.0.0",
@@ -116,9 +116,11 @@ 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
- const extra = {
120
- html: result.element.outerHTML,
121
- };
119
+ const extra = {};
120
+
121
+ if (result.element) {
122
+ extra.html = result.element.outerHTML;
123
+ }
122
124
 
123
125
  if (result.report) {
124
126
  extra.report = result.report;
@@ -182,9 +184,11 @@ async function html2x(
182
184
  const pirs = await importer.import(url);
183
185
 
184
186
  const getResponseObjectFromPIR = async (pir) => {
185
- const res = {
186
- html: pir.extra.html,
187
- };
187
+ const res = {};
188
+
189
+ if (pir.extra && pir.extra.html) {
190
+ res.html = pir.extra.html;
191
+ }
188
192
 
189
193
  if (pir.extra.report) {
190
194
  res.report = pir.extra.report;
@@ -192,11 +196,11 @@ async function html2x(
192
196
 
193
197
  res.path = path.resolve(pir.directory, pir.name);
194
198
 
195
- if (config.toMd) {
199
+ if (config.toMd && pir.md) {
196
200
  const md = await storageHandler.get(pir.md);
197
201
  res.md = md;
198
202
  }
199
- if (config.toDocx) {
203
+ if (config.toDocx && pir.docx) {
200
204
  const docx = await storageHandler.get(pir.docx);
201
205
  res.docx = docx;
202
206
  }
@@ -314,28 +314,30 @@ export default class PageImporter {
314
314
 
315
315
  if (entries) {
316
316
  await Utils.asyncForEach(entries, async (entry) => {
317
- const res = await this.createMarkdown(entry, url);
318
- // eslint-disable-next-line no-param-reassign
319
- entry.source = url;
320
- // eslint-disable-next-line no-param-reassign
321
- entry.path = res.path;
322
- // eslint-disable-next-line no-param-reassign
323
- entry.markdown = res.content;
324
-
325
- if (!this.params.skipMDFileCreation) {
326
- const mdPath = `${res.path}.md`;
327
- await this.params.storageHandler.put(mdPath, res.content);
328
- this.logger.log(`MD file created: ${mdPath}`);
329
-
317
+ if (entry.document) {
318
+ const res = await this.createMarkdown(entry, url);
330
319
  // eslint-disable-next-line no-param-reassign
331
- entry.md = mdPath;
332
- }
333
-
334
- if (!this.params.skipDocxConversion) {
335
- const docxPath = `${res.path}.docx`;
336
- await this.convertToDocx(docxPath, res.content);
320
+ entry.source = url;
337
321
  // eslint-disable-next-line no-param-reassign
338
- entry.docx = docxPath;
322
+ entry.path = res.path;
323
+ // eslint-disable-next-line no-param-reassign
324
+ entry.markdown = res.content;
325
+
326
+ if (!this.params.skipMDFileCreation) {
327
+ const mdPath = `${res.path}.md`;
328
+ await this.params.storageHandler.put(mdPath, res.content);
329
+ this.logger.log(`MD file created: ${mdPath}`);
330
+
331
+ // eslint-disable-next-line no-param-reassign
332
+ entry.md = mdPath;
333
+ }
334
+
335
+ if (!this.params.skipDocxConversion) {
336
+ const docxPath = `${res.path}.docx`;
337
+ await this.convertToDocx(docxPath, res.content);
338
+ // eslint-disable-next-line no-param-reassign
339
+ entry.docx = docxPath;
340
+ }
339
341
  }
340
342
 
341
343
  results.push(entry);
@@ -230,6 +230,35 @@ describe('html2md tests', () => {
230
230
  strictEqual(out2.report.somethingElse, 'something else');
231
231
  });
232
232
 
233
+ it('html2md allows no element to be provided when using transform', async () => {
234
+ const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
235
+ transform: () => [{
236
+ path: '/my-custom-path-p1',
237
+ report: {
238
+ custom: 'A custom property',
239
+ customArray: ['a', 'b', 'c'],
240
+ customObject: {
241
+ a: 1,
242
+ b: true,
243
+ c: {
244
+ d: 'e',
245
+ },
246
+ },
247
+ },
248
+ }],
249
+ });
250
+
251
+ // if no element provided, no creation of html, md or docx
252
+ strictEqual(out.html, undefined);
253
+ strictEqual(out.md, undefined);
254
+ strictEqual(out.docx, undefined);
255
+ strictEqual(out.path, '/my-custom-path-p1');
256
+ ok(out.report);
257
+ strictEqual(out.report.custom, 'A custom property');
258
+ deepStrictEqual(out.report.customArray, ['a', 'b', 'c']);
259
+ deepStrictEqual(out.report.customObject, { a: 1, b: true, c: { d: 'e' } });
260
+ });
261
+
233
262
  it('html2md does not crash if transform returns null', async () => {
234
263
  const out = await html2md('https://www.sample.com/page.html', '<html><body><h1>Hello World</h1></body></html>', {
235
264
  transform: () => null,