@adobe/helix-importer 1.4.0 → 1.4.1
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 +7 -0
- package/package.json +1 -1
- package/src/importer/PageImporter.js +2 -5
- package/src/utils/MDUtils.js +21 -0
- package/test/utils/MDUtils.spec.js +54 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.4.1](https://github.com/adobe/helix-importer/compare/v1.4.0...v1.4.1) (2022-02-24)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* some images come with wrong src in md ([#16](https://github.com/adobe/helix-importer/issues/16)) ([7f27432](https://github.com/adobe/helix-importer/commit/7f274326683313cd11c2a92bb1c01c1960de5fcd))
|
|
7
|
+
|
|
1
8
|
# [1.4.0](https://github.com/adobe/helix-importer/compare/v1.3.0...v1.4.0) (2022-02-02)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -25,6 +25,7 @@ import { md2docx } from '@adobe/helix-md2docx';
|
|
|
25
25
|
import Utils from '../utils/Utils.js';
|
|
26
26
|
import DOMUtils from '../utils/DOMUtils.js';
|
|
27
27
|
import FileUtils from '../utils/FileUtils.js';
|
|
28
|
+
import MDUtils from '../utils/MDUtils.js';
|
|
28
29
|
|
|
29
30
|
export default class PageImporter {
|
|
30
31
|
params;
|
|
@@ -143,14 +144,10 @@ export default class PageImporter {
|
|
|
143
144
|
}
|
|
144
145
|
});
|
|
145
146
|
|
|
146
|
-
const patchSrcInContent = (c, oldSrc, newSrc) => contents
|
|
147
|
-
.replace(new RegExp(`${oldSrc.replace('.', '\\.').replace('?', '\\?')}`, 'gm'), newSrc)
|
|
148
|
-
.replace(new RegExp(`${decodeURI(oldSrc).replace('.', '\\.')}`, 'gm'), newSrc);
|
|
149
|
-
|
|
150
147
|
// adjust assets url (from relative to absolute)
|
|
151
148
|
assets.forEach((asset) => {
|
|
152
149
|
const u = new URL(decodeURI(asset.url), url);
|
|
153
|
-
contents =
|
|
150
|
+
contents = MDUtils.replaceSrcInMarkdown(contents, asset.url, u.toString());
|
|
154
151
|
});
|
|
155
152
|
|
|
156
153
|
if (resource.prepend) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2022 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export default class MDUtils {
|
|
14
|
+
static replaceSrcInMarkdown = (md, oldSrc, newSrc) => {
|
|
15
|
+
if (decodeURI(oldSrc) !== oldSrc) {
|
|
16
|
+
return md.replace(new RegExp(`${decodeURI(oldSrc).replace('.', '\\.')}`, 'gm'), newSrc);
|
|
17
|
+
} else {
|
|
18
|
+
return md.replace(new RegExp(`${oldSrc.replace('.', '\\.').replace('?', '\\?')}`, 'gm'), newSrc);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
*
|
|
7
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
+
* governing permissions and limitations under the License.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { strictEqual } from 'assert';
|
|
14
|
+
import { describe, it } from 'mocha';
|
|
15
|
+
|
|
16
|
+
import MDUtils from '../../src/utils/MDUtils.js';
|
|
17
|
+
|
|
18
|
+
describe('MDUtils tests', () => {
|
|
19
|
+
it('MDUtils#replaceSrcInMarkdown do nothing', () => {
|
|
20
|
+
strictEqual(
|
|
21
|
+
MDUtils.replaceSrcInMarkdown('#A title\n', 'https://www.sample.com/replace.jpg', 'https://www.sample.com/withimage.jpg'),
|
|
22
|
+
'#A title\n',
|
|
23
|
+
'do nothing',
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('MDUtils#replaceSrcInMarkdown can replace', () => {
|
|
28
|
+
strictEqual(
|
|
29
|
+
MDUtils.replaceSrcInMarkdown('#A title\n', 'https://www.sample.com/image.jpg', 'https://www.sample.com/withimage.jpg'),
|
|
30
|
+
'#A title\n',
|
|
31
|
+
'basic replacement',
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
strictEqual(
|
|
35
|
+
MDUtils.replaceSrcInMarkdown('#A title\n', '/image.jpg', 'https://www.sample.com/image.jpg'),
|
|
36
|
+
'#A title\n',
|
|
37
|
+
'relative to absolute replacement',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
strictEqual(
|
|
41
|
+
MDUtils.replaceSrcInMarkdown('\n\n# Title for the page', '/book/resources/_prod/img/hero/image.jpg', 'https://www.sample.com/book/resources/_prod/img/hero/image.jpg'),
|
|
42
|
+
'\n\n# Title for the page',
|
|
43
|
+
'relative to absolute replacement (no double replacement)',
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('MDUtils#replaceSrcInMarkdown can replace with encoding', () => {
|
|
48
|
+
strictEqual(
|
|
49
|
+
MDUtils.replaceSrcInMarkdown('#A title\n', 'https://www.sample.com/imag%C3%A9.jpg', 'https://www.sample.com/withsomethingelse.jpg'),
|
|
50
|
+
'#A title\n',
|
|
51
|
+
'encoded to replacement',
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|