@adobe/helix-importer 3.2.3 → 3.3.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 +21 -0
- package/package.json +10 -10
- package/src/importer/PageImporter.js +7 -2
- package/src/utils/DOMUtils.js +18 -0
- package/test/importers/PageImporter.spec.js +13 -2
- package/test/importers/fixtures/img.spec.html +11 -0
- package/test/importers/fixtures/img.spec.md +15 -0
- package/test/utils/DOMUtils.spec.js +19 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
# [3.3.0](https://github.com/adobe/helix-importer/compare/v3.2.4...v3.3.0) (2024-03-15)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* add image type in blob used in getDataUrlFromB64Img ([4fa0937](https://github.com/adobe/helix-importer/commit/4fa093723dba506b5abfde6a3eddc34aa14c6d36))
|
|
7
|
+
* do not use node.js buffer package for blob to get code working in browser ([d6da86d](https://github.com/adobe/helix-importer/commit/d6da86d6c4715346035a2dff549d4291adc4e150))
|
|
8
|
+
* fix tests after online merge resolution ([cbc326d](https://github.com/adobe/helix-importer/commit/cbc326dfe43b96f7d09e895867fff398f044c74d))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* add support for base64 images ([966c807](https://github.com/adobe/helix-importer/commit/966c807a5ebc404ee9729286d2864c968a612120))
|
|
14
|
+
|
|
15
|
+
## [3.2.4](https://github.com/adobe/helix-importer/compare/v3.2.3...v3.2.4) (2024-02-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** update dependency @adobe/mdast-util-gridtables to v4.0.1 ([#316](https://github.com/adobe/helix-importer/issues/316)) ([9b7aff5](https://github.com/adobe/helix-importer/commit/9b7aff5d83498aa7f63bf7e1f87cfeae8bf8435d))
|
|
21
|
+
|
|
1
22
|
## [3.2.3](https://github.com/adobe/helix-importer/compare/v3.2.2...v3.2.3) (2024-02-14)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-importer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Helix Importer tool: create md / docx from html",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -27,20 +27,20 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@adobe/eslint-config-helix": "2.0.6",
|
|
30
|
-
"@adobe/helix-docx2md": "1.5.
|
|
31
|
-
"@adobe/helix-mediahandler": "2.4.
|
|
30
|
+
"@adobe/helix-docx2md": "1.5.6",
|
|
31
|
+
"@adobe/helix-mediahandler": "2.4.14",
|
|
32
32
|
"@esm-bundle/chai": "4.3.4-fix.0",
|
|
33
33
|
"@semantic-release/changelog": "6.0.3",
|
|
34
34
|
"@semantic-release/exec": "6.0.3",
|
|
35
35
|
"@semantic-release/git": "10.0.1",
|
|
36
|
-
"@web/test-runner": "0.18.
|
|
36
|
+
"@web/test-runner": "0.18.1",
|
|
37
37
|
"@web/test-runner-commands": "0.9.0",
|
|
38
38
|
"@web/test-runner-mocha": "0.9.0",
|
|
39
39
|
"c8": "9.1.0",
|
|
40
|
-
"chai": "5.0
|
|
40
|
+
"chai": "5.1.0",
|
|
41
41
|
"dirname-filename-esm": "1.1.1",
|
|
42
|
-
"eslint": "8.
|
|
43
|
-
"husky": "9.0.
|
|
42
|
+
"eslint": "8.57.0",
|
|
43
|
+
"husky": "9.0.11",
|
|
44
44
|
"jsdom": "24.0.0",
|
|
45
45
|
"lint-staged": "15.2.2",
|
|
46
46
|
"mocha": "10.3.0",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"license": "Apache-2.0",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@adobe/helix-markdown-support": "7.1.0",
|
|
56
|
-
"@adobe/helix-md2docx": "2.1.
|
|
57
|
-
"@adobe/mdast-util-gridtables": "4.0.
|
|
58
|
-
"@adobe/remark-gridtables": "3.0.
|
|
56
|
+
"@adobe/helix-md2docx": "2.1.45",
|
|
57
|
+
"@adobe/mdast-util-gridtables": "4.0.1",
|
|
58
|
+
"@adobe/remark-gridtables": "3.0.1",
|
|
59
59
|
"form-data": "4.0.0",
|
|
60
60
|
"fs-extra": "11.2.0",
|
|
61
61
|
"hast-util-to-mdast": "10.1.0",
|
|
@@ -249,9 +249,14 @@ export default class PageImporter {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
src = img.getAttribute('src');
|
|
252
|
+
// try to handle b64 img
|
|
252
253
|
if (!src || src.indexOf('data:') === 0) {
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
const dataUrl = DOMUtils.getDataUrlFromB64Img(img.src);
|
|
255
|
+
if (dataUrl) {
|
|
256
|
+
img.setAttribute('src', dataUrl);
|
|
257
|
+
} else {
|
|
258
|
+
img.remove();
|
|
259
|
+
}
|
|
255
260
|
}
|
|
256
261
|
|
|
257
262
|
const alt = img.getAttribute('alt');
|
package/src/utils/DOMUtils.js
CHANGED
|
@@ -293,4 +293,22 @@ export default class DOMUtils {
|
|
|
293
293
|
}, interval);
|
|
294
294
|
});
|
|
295
295
|
}
|
|
296
|
+
|
|
297
|
+
static getDataUrlFromB64Img(src) {
|
|
298
|
+
try {
|
|
299
|
+
const arr = src.split(',');
|
|
300
|
+
const type = arr[0].split(':')[1];
|
|
301
|
+
const b64Str = atob(arr[1]);
|
|
302
|
+
const bytesArray = new Uint8Array(b64Str.length);
|
|
303
|
+
for (let i = 0; i < b64Str.length; i += 1) {
|
|
304
|
+
bytesArray[i] = b64Str.charCodeAt(i);
|
|
305
|
+
}
|
|
306
|
+
const blob = new Blob([bytesArray], { type });
|
|
307
|
+
return URL.createObjectURL(blob);
|
|
308
|
+
} catch (e) {
|
|
309
|
+
// eslint-disable-next-line no-console
|
|
310
|
+
console.error(`get data url from a base64 image (${src}):`, e);
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
296
314
|
}
|
|
@@ -156,7 +156,10 @@ describe('PageImporter tests - various options', () => {
|
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
describe('PageImporter tests - fixtures', () => {
|
|
159
|
-
const featureTest = async (feature) => {
|
|
159
|
+
const featureTest = async (feature, assertFn) => {
|
|
160
|
+
// eslint-disable-next-line no-param-reassign
|
|
161
|
+
assertFn = assertFn || ((got, want) => strictEqual(got, want, 'imported md is expected one'));
|
|
162
|
+
|
|
160
163
|
class Test extends PageImporter {
|
|
161
164
|
async fetch() {
|
|
162
165
|
const html = await fs.readFile(path.resolve(__dirname, 'fixtures', `${feature}.spec.html`), 'utf-8');
|
|
@@ -183,7 +186,7 @@ describe('PageImporter tests - fixtures', () => {
|
|
|
183
186
|
|
|
184
187
|
const md = await storageHandler.get(results[0].md);
|
|
185
188
|
const expectedMD = await fs.readFile(path.resolve(__dirname, 'fixtures', `${feature}.spec.md`), 'utf-8');
|
|
186
|
-
|
|
189
|
+
assertFn(md.trim(), expectedMD.trim(), 'imported md is expected one');
|
|
187
190
|
|
|
188
191
|
// parse md to verify mdast
|
|
189
192
|
const mdast = unified()
|
|
@@ -238,6 +241,14 @@ describe('PageImporter tests - fixtures', () => {
|
|
|
238
241
|
await featureTest('subsup');
|
|
239
242
|
});
|
|
240
243
|
|
|
244
|
+
it('import - images', async () => {
|
|
245
|
+
await featureTest('img', (got, want) => {
|
|
246
|
+
if (got.indexOf(want) !== 0) {
|
|
247
|
+
throw new Error('imported md is not expected one');
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
|
|
241
252
|
it('import - video', async () => {
|
|
242
253
|
await featureTest('video');
|
|
243
254
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<html>
|
|
2
|
+
<body>
|
|
3
|
+
<h1>Images sample</h1>
|
|
4
|
+
<h3>Standard Image - should be imported as is</h3>
|
|
5
|
+
<img src="https://www.server.com/image.jpg" alt="empty alt" />
|
|
6
|
+
<h3>Image with wrong Base64 data - should be removed</h3>
|
|
7
|
+
<img src="data:image/png;base64,--dummy--" alt="empty alt" />
|
|
8
|
+
<h3>Image with correct Base64 data - should be transformed into Object Url data</h3>
|
|
9
|
+
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="empty alt" />
|
|
10
|
+
</body>
|
|
11
|
+
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Images sample
|
|
2
|
+
|
|
3
|
+
### Standard Image - should be imported as is
|
|
4
|
+
|
|
5
|
+
![empty alt][image0]
|
|
6
|
+
|
|
7
|
+
### Image with wrong Base64 data - should be removed
|
|
8
|
+
|
|
9
|
+
### Image with correct Base64 data - should be transformed into Object Url data
|
|
10
|
+
|
|
11
|
+
![empty alt][image1]
|
|
12
|
+
|
|
13
|
+
[image0]: https://www.server.com/image.jpg
|
|
14
|
+
|
|
15
|
+
[image1]: blob:nodedata:
|
|
@@ -432,3 +432,22 @@ describe('DOMUtils#getImgFromBackground', () => {
|
|
|
432
432
|
test(createElement('p', {}, { 'background-image': 'url( /image.jpg )' }, 'Some content'), '<img src="/image.jpg">');
|
|
433
433
|
});
|
|
434
434
|
});
|
|
435
|
+
|
|
436
|
+
describe('DOMUtils#getDataUrlFromB64Img', () => {
|
|
437
|
+
const test = (img, expected) => {
|
|
438
|
+
const dataUrl = DOMUtils.getDataUrlFromB64Img(img.src);
|
|
439
|
+
return expected(dataUrl) === true;
|
|
440
|
+
};
|
|
441
|
+
|
|
442
|
+
it('no data url in original image', () => {
|
|
443
|
+
test(createElement('img', { src: 'https://www.server.com/image.jpg' }, {}, ''), (res) => res === null);
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it('malformed base64 data url in original image', () => {
|
|
447
|
+
test(createElement('img', { src: 'data:image/png;base64,--dummy--' }, {}, ''), (res) => res === null);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it('base64 data url in original image', () => {
|
|
451
|
+
test(createElement('img', { src: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' }, {}, ''), (res) => res.indexOf('blob:nodedata:') === 0);
|
|
452
|
+
});
|
|
453
|
+
});
|