@adobe/helix-importer 1.10.0 → 1.11.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
+ # [1.11.0](https://github.com/adobe/helix-importer/compare/v1.10.0...v1.11.0) (2022-04-05)
2
+
3
+
4
+ ### Features
5
+
6
+ * replace weird spaces characters ([4c9b43f](https://github.com/adobe/helix-importer/commit/4c9b43fe2693b0cacae8a7ef2210b0ab271f918d))
7
+
1
8
  # [1.10.0](https://github.com/adobe/helix-importer/compare/v1.9.0...v1.10.0) (2022-04-01)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adobe/helix-importer",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "description": "Helix Importer tool: create md / docx from html",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -231,7 +231,7 @@ export default class PageImporter {
231
231
  }
232
232
 
233
233
  postProcessMD(md) {
234
- return md.replace(/\\\\~/gm, '\\~');
234
+ return MDUtils.cleanupMarkdown(md);
235
235
  }
236
236
 
237
237
  async download(url) {
@@ -18,4 +18,20 @@ export default class MDUtils {
18
18
  return md.replace(new RegExp(`${oldSrc.replace('.', '\\.').replace('?', '\\?')}`, 'gm'), newSrc);
19
19
  }
20
20
  };
21
+
22
+ static cleanupMarkdown(md) {
23
+ let ret = md?.replace(/\\\\~/gm, '\\~');
24
+ if (ret) {
25
+ for (let i = 0; i < 20; i += 1) {
26
+ let x = `${i}`;
27
+ if (i < 10) x = `0${i}`;
28
+ const c = String.fromCodePoint(parseInt(`00${x}`, 16));
29
+ const reg = new RegExp(`\\u00${x}`, 'g');
30
+ const r = [c.length].map(() => ' ').join('');
31
+ ret = ret.replace(reg, r);
32
+ }
33
+ ret = ret.replace(/\u00A0/gm, '');
34
+ }
35
+ return ret;
36
+ }
21
37
  }
@@ -15,7 +15,7 @@ import { describe, it } from 'mocha';
15
15
 
16
16
  import MDUtils from '../../src/utils/MDUtils.js';
17
17
 
18
- describe('MDUtils tests', () => {
18
+ describe('MDUtils#replaceSrcInMarkdown tests', () => {
19
19
  it('MDUtils#replaceSrcInMarkdown do nothing', () => {
20
20
  strictEqual(
21
21
  MDUtils.replaceSrcInMarkdown('#A title\n![](https://www.sample.com/image.jpg)', 'https://www.sample.com/replace.jpg', 'https://www.sample.com/withimage.jpg'),
@@ -52,3 +52,30 @@ describe('MDUtils tests', () => {
52
52
  );
53
53
  });
54
54
  });
55
+
56
+ describe('MDUtils#cleanupMarkdown tests', () => {
57
+ it('MDUtils#cleanupMarkdown do nothing', () => {
58
+ const md = '#A title\n![](https://www.sample.com/image.jpg)\nShould be clean\n<table><tr><th colspan="2">Metadata</th></tr><tr><td>key</td><td>value</td></tr></table>';
59
+ strictEqual(
60
+ MDUtils.cleanupMarkdown(md),
61
+ md,
62
+ 'do nothing',
63
+ );
64
+ });
65
+
66
+ it('MDUtils#cleanupMarkdown unescape tildes', () => {
67
+ strictEqual(
68
+ MDUtils.cleanupMarkdown('#A title\n~~Tilde can be an pb~~\n Especially \\\\~in the content'),
69
+ '#A title\n~~Tilde can be an pb~~\n Especially \\~in the content',
70
+ 'unescape tildes',
71
+ );
72
+ });
73
+
74
+ it('MDUtils#cleanupMarkdown replace weird spaces', () => {
75
+ strictEqual(
76
+ MDUtils.cleanupMarkdown('#A title\nReplaces the weird spaces characters: "\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019"'),
77
+ '#A title\nReplaces the weird spaces characters: " "',
78
+ 'replace weird spaces',
79
+ );
80
+ });
81
+ });