@tryghost/url-utils 5.0.0-rc.1 → 5.1.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/lib/UrlUtils.d.ts +147 -0
- package/lib/UrlUtils.js +270 -220
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -0
- package/lib/utils/absolute-to-relative.d.ts +19 -0
- package/lib/utils/absolute-to-relative.js +16 -19
- package/lib/utils/absolute-to-transform-ready.d.ts +13 -0
- package/lib/utils/absolute-to-transform-ready.js +39 -94
- package/lib/utils/build-early-exit-match.d.ts +24 -0
- package/lib/utils/build-early-exit-match.js +39 -0
- package/lib/utils/deduplicate-double-slashes.d.ts +2 -0
- package/lib/utils/deduplicate-double-slashes.js +7 -3
- package/lib/utils/deduplicate-subdirectory.d.ts +9 -0
- package/lib/utils/deduplicate-subdirectory.js +5 -9
- package/lib/utils/html-absolute-to-relative.d.ts +3 -0
- package/lib/utils/html-absolute-to-relative.js +12 -12
- package/lib/utils/html-absolute-to-transform-ready.d.ts +3 -0
- package/lib/utils/html-absolute-to-transform-ready.js +18 -38
- package/lib/utils/html-relative-to-absolute.d.ts +3 -0
- package/lib/utils/html-relative-to-absolute.js +11 -10
- package/lib/utils/html-relative-to-transform-ready.d.ts +3 -0
- package/lib/utils/html-relative-to-transform-ready.js +18 -13
- package/lib/utils/html-to-transform-ready.d.ts +3 -0
- package/lib/utils/html-to-transform-ready.js +18 -10
- package/lib/utils/html-transform.d.ts +3 -0
- package/lib/utils/html-transform.js +26 -47
- package/lib/utils/index.d.ts +76 -0
- package/lib/utils/index.js +116 -37
- package/lib/utils/is-ssl.d.ts +2 -0
- package/lib/utils/is-ssl.js +5 -5
- package/lib/utils/lexical-absolute-to-relative.d.ts +3 -0
- package/lib/utils/lexical-absolute-to-relative.js +12 -11
- package/lib/utils/lexical-absolute-to-transform-ready.d.ts +3 -0
- package/lib/utils/lexical-absolute-to-transform-ready.js +13 -12
- package/lib/utils/lexical-relative-to-absolute.d.ts +3 -0
- package/lib/utils/lexical-relative-to-absolute.js +11 -9
- package/lib/utils/lexical-relative-to-transform-ready.d.ts +3 -0
- package/lib/utils/lexical-relative-to-transform-ready.js +11 -9
- package/lib/utils/lexical-to-transform-ready.d.ts +3 -0
- package/lib/utils/lexical-to-transform-ready.js +18 -10
- package/lib/utils/lexical-transform.d.ts +3 -0
- package/lib/utils/lexical-transform.js +25 -36
- package/lib/utils/markdown-absolute-to-relative.d.ts +3 -0
- package/lib/utils/markdown-absolute-to-relative.js +13 -13
- package/lib/utils/markdown-absolute-to-transform-ready.d.ts +3 -0
- package/lib/utils/markdown-absolute-to-transform-ready.js +19 -15
- package/lib/utils/markdown-relative-to-absolute.d.ts +3 -0
- package/lib/utils/markdown-relative-to-absolute.js +13 -13
- package/lib/utils/markdown-relative-to-transform-ready.d.ts +3 -0
- package/lib/utils/markdown-relative-to-transform-ready.js +13 -13
- package/lib/utils/markdown-to-transform-ready.d.ts +3 -0
- package/lib/utils/markdown-to-transform-ready.js +18 -10
- package/lib/utils/markdown-transform.d.ts +3 -0
- package/lib/utils/markdown-transform.js +15 -30
- package/lib/utils/mobiledoc-absolute-to-relative.d.ts +3 -0
- package/lib/utils/mobiledoc-absolute-to-relative.js +12 -11
- package/lib/utils/mobiledoc-absolute-to-transform-ready.d.ts +3 -0
- package/lib/utils/mobiledoc-absolute-to-transform-ready.js +13 -12
- package/lib/utils/mobiledoc-relative-to-absolute.d.ts +3 -0
- package/lib/utils/mobiledoc-relative-to-absolute.js +11 -9
- package/lib/utils/mobiledoc-relative-to-transform-ready.d.ts +3 -0
- package/lib/utils/mobiledoc-relative-to-transform-ready.js +11 -9
- package/lib/utils/mobiledoc-to-transform-ready.d.ts +3 -0
- package/lib/utils/mobiledoc-to-transform-ready.js +18 -10
- package/lib/utils/mobiledoc-transform.d.ts +3 -0
- package/lib/utils/mobiledoc-transform.js +8 -13
- package/lib/utils/plaintext-absolute-to-transform-ready.d.ts +5 -0
- package/lib/utils/plaintext-absolute-to-transform-ready.js +29 -16
- package/lib/utils/plaintext-relative-to-transform-ready.d.ts +3 -0
- package/lib/utils/plaintext-relative-to-transform-ready.js +16 -9
- package/lib/utils/plaintext-to-transform-ready.d.ts +5 -0
- package/lib/utils/plaintext-to-transform-ready.js +18 -10
- package/lib/utils/relative-to-absolute.d.ts +15 -0
- package/lib/utils/relative-to-absolute.js +28 -33
- package/lib/utils/relative-to-transform-ready.d.ts +8 -0
- package/lib/utils/relative-to-transform-ready.js +23 -18
- package/lib/utils/replace-permalink.d.ts +16 -0
- package/lib/utils/replace-permalink.js +45 -10
- package/lib/utils/strip-subdirectory-from-path.d.ts +9 -0
- package/lib/utils/strip-subdirectory-from-path.js +7 -11
- package/lib/utils/to-transform-ready.d.ts +5 -0
- package/lib/utils/to-transform-ready.js +18 -10
- package/lib/utils/transform-ready-to-absolute.d.ts +9 -0
- package/lib/utils/transform-ready-to-absolute.js +10 -28
- package/lib/utils/transform-ready-to-relative.d.ts +3 -0
- package/lib/utils/transform-ready-to-relative.js +5 -8
- package/lib/utils/types.d.ts +92 -0
- package/lib/utils/types.js +2 -0
- package/lib/utils/url-join.d.ts +12 -0
- package/lib/utils/url-join.js +12 -12
- package/package.json +20 -12
- package/index.js +0 -1
|
@@ -1,77 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
const _ = require('lodash');
|
|
2
|
-
|
|
3
|
-
// options.transformMap = {
|
|
4
|
-
// relativeToAbsolute: {
|
|
5
|
-
// url: (url, siteUrl, itemPath, options) => 'transformedUrl',
|
|
6
|
-
// html: (html, siteUrl, itemPath, options) => 'transformedHtml',
|
|
7
|
-
// }
|
|
8
|
-
// }
|
|
9
|
-
// options.transformType = 'relativeToAbsolute'
|
|
10
|
-
|
|
11
4
|
function lexicalTransform(serializedLexical, siteUrl, transformFunction, itemPath, _options = {}) {
|
|
12
|
-
const defaultOptions = {assetsOnly: false, secure: false, nodes: [], transformMap: {}};
|
|
13
|
-
const options = Object.assign({}, defaultOptions, _options, {siteUrl, itemPath});
|
|
14
|
-
|
|
5
|
+
const defaultOptions = { assetsOnly: false, secure: false, nodes: [], transformMap: {} };
|
|
6
|
+
const options = Object.assign({}, defaultOptions, _options, { siteUrl, itemPath });
|
|
15
7
|
if (!serializedLexical) {
|
|
16
8
|
return serializedLexical;
|
|
17
9
|
}
|
|
18
|
-
|
|
19
10
|
// function only accepts serialized lexical so there's no chance of accidentally
|
|
20
11
|
// modifying pass-by-reference objects
|
|
21
12
|
const lexical = JSON.parse(serializedLexical);
|
|
22
|
-
|
|
23
13
|
if (!lexical?.root?.children) {
|
|
24
14
|
return serializedLexical;
|
|
25
15
|
}
|
|
26
|
-
|
|
27
16
|
// create a map of node types to urlTransformMap objects
|
|
28
17
|
// e.g. {'image': {src: 'url', caption: 'html'}
|
|
29
18
|
const nodeMap = new Map();
|
|
30
19
|
options.nodes.forEach(node => node.urlTransformMap && nodeMap.set(node.getType(), node.urlTransformMap));
|
|
31
|
-
|
|
32
20
|
const transformProperty = function (obj, propertyPath, transform) {
|
|
33
21
|
const propertyValue = _.get(obj, propertyPath);
|
|
34
|
-
|
|
35
22
|
if (Array.isArray(propertyValue)) {
|
|
36
23
|
propertyValue.forEach((item) => {
|
|
37
24
|
// arrays of objects need to be defined as a nested object in the urlTransformMap
|
|
38
25
|
// so the `transform` value is that nested object
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
26
|
+
if (typeof transform === 'object') {
|
|
27
|
+
Object.entries(transform).forEach(([itemPropertyPath, itemTransform]) => {
|
|
28
|
+
transformProperty(item, itemPropertyPath, itemTransform);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
42
31
|
});
|
|
43
|
-
|
|
44
32
|
return;
|
|
45
33
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
if (propertyValue && typeof transform === 'string') {
|
|
35
|
+
const transformType = options.transformType;
|
|
36
|
+
const transformRegistry = options.transformMap[transformType];
|
|
37
|
+
if (transformRegistry && transformRegistry[transform]) {
|
|
38
|
+
_.set(obj, propertyPath, transformRegistry[transform](propertyValue));
|
|
39
|
+
}
|
|
49
40
|
}
|
|
50
41
|
};
|
|
51
|
-
|
|
52
42
|
// recursively walk the Lexical node tree transforming any card data properties and links
|
|
53
43
|
const transformChildren = function (children) {
|
|
54
44
|
for (const child of children) {
|
|
55
45
|
const isCard = child.type && nodeMap.has(child.type);
|
|
56
46
|
const isLink = !!child.url;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
if (isCard && child.type) {
|
|
48
|
+
const urlTransformMap = nodeMap.get(child.type);
|
|
49
|
+
if (urlTransformMap) {
|
|
50
|
+
Object.entries(urlTransformMap).forEach(([propertyPath, transform]) => {
|
|
51
|
+
transformProperty(child, propertyPath, transform);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else if (isLink && child.url) {
|
|
63
56
|
child.url = transformFunction(child.url, siteUrl, itemPath, options);
|
|
64
57
|
}
|
|
65
|
-
|
|
66
58
|
if (child.children) {
|
|
67
59
|
transformChildren(child.children);
|
|
68
60
|
}
|
|
69
61
|
}
|
|
70
62
|
};
|
|
71
|
-
|
|
72
63
|
transformChildren(lexical.root.children);
|
|
73
|
-
|
|
74
64
|
return JSON.stringify(lexical);
|
|
75
65
|
}
|
|
76
|
-
|
|
77
|
-
module.exports = lexicalTransform;
|
|
66
|
+
exports.default = lexicalTransform;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const markdown_transform_1 = __importDefault(require("./markdown-transform"));
|
|
7
|
+
const absolute_to_relative_1 = __importDefault(require("./absolute-to-relative"));
|
|
8
|
+
const html_absolute_to_relative_1 = __importDefault(require("./html-absolute-to-relative"));
|
|
5
9
|
function markdownAbsoluteToRelative(markdown = '', siteUrl, _options = {}) {
|
|
6
|
-
const defaultOptions = {assetsOnly: false, ignoreProtocol: true};
|
|
10
|
+
const defaultOptions = { assetsOnly: false, ignoreProtocol: true };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
8
|
-
|
|
9
12
|
options.earlyExitMatchStr = options.ignoreProtocol ? siteUrl.replace(/http:|https:/, '') : siteUrl;
|
|
10
13
|
options.earlyExitMatchStr = options.earlyExitMatchStr.replace(/\/$/, '');
|
|
11
|
-
|
|
12
14
|
// need to ignore itemPath because absoluteToRelative functions doen't take that option
|
|
13
15
|
const transformFunctions = {
|
|
14
16
|
html(_url, _siteUrl, _itemPath, __options) {
|
|
15
|
-
return
|
|
17
|
+
return (0, html_absolute_to_relative_1.default)(_url, _siteUrl, __options);
|
|
16
18
|
},
|
|
17
19
|
url(_url, _siteUrl, _itemPath, __options) {
|
|
18
|
-
return
|
|
20
|
+
return (0, absolute_to_relative_1.default)(_url, _siteUrl, __options);
|
|
19
21
|
}
|
|
20
22
|
};
|
|
21
|
-
|
|
22
|
-
return markdownTransform(markdown, siteUrl, transformFunctions, '', options);
|
|
23
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, '', options);
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
module.exports = markdownAbsoluteToRelative;
|
|
25
|
+
exports.default = markdownAbsoluteToRelative;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { AbsoluteToTransformReadyOptionsInput } from './types';
|
|
2
|
+
declare function markdownAbsoluteToTransformReady(markdown: string | undefined, siteUrl: string, _options?: AbsoluteToTransformReadyOptionsInput): string;
|
|
3
|
+
export default markdownAbsoluteToTransformReady;
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const markdown_transform_1 = __importDefault(require("./markdown-transform"));
|
|
7
|
+
const absolute_to_transform_ready_1 = __importDefault(require("./absolute-to-transform-ready"));
|
|
8
|
+
const html_absolute_to_transform_ready_1 = __importDefault(require("./html-absolute-to-transform-ready"));
|
|
9
|
+
const build_early_exit_match_1 = __importDefault(require("./build-early-exit-match"));
|
|
10
|
+
const { buildEarlyExitMatch } = build_early_exit_match_1.default;
|
|
5
11
|
function markdownAbsoluteToTransformReady(markdown = '', siteUrl, _options = {}) {
|
|
6
|
-
const defaultOptions = {assetsOnly: false, ignoreProtocol: true};
|
|
12
|
+
const defaultOptions = { assetsOnly: false, ignoreProtocol: true };
|
|
7
13
|
const options = Object.assign({}, defaultOptions, _options);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
const earlyExitMatch = buildEarlyExitMatch(siteUrl, options);
|
|
15
|
+
if (earlyExitMatch) {
|
|
16
|
+
options.earlyExitMatchStr = earlyExitMatch;
|
|
17
|
+
}
|
|
12
18
|
// need to ignore itemPath because absoluteToTransformReady functions doen't take that option
|
|
13
19
|
const transformFunctions = {
|
|
14
20
|
html(_url, _siteUrl, _itemPath, __options) {
|
|
15
|
-
return
|
|
21
|
+
return (0, html_absolute_to_transform_ready_1.default)(_url, _siteUrl, __options);
|
|
16
22
|
},
|
|
17
23
|
url(_url, _siteUrl, _itemPath, __options) {
|
|
18
|
-
return
|
|
24
|
+
return (0, absolute_to_transform_ready_1.default)(_url, _siteUrl, __options);
|
|
19
25
|
}
|
|
20
26
|
};
|
|
21
|
-
|
|
22
|
-
return markdownTransform(markdown, siteUrl, transformFunctions, '', options);
|
|
27
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, '', options);
|
|
23
28
|
}
|
|
24
|
-
|
|
25
|
-
module.exports = markdownAbsoluteToTransformReady;
|
|
29
|
+
exports.default = markdownAbsoluteToTransformReady;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const markdown_transform_1 = __importDefault(require("./markdown-transform"));
|
|
7
|
+
const html_relative_to_absolute_1 = __importDefault(require("./html-relative-to-absolute"));
|
|
8
|
+
const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
|
|
5
9
|
function markdownRelativeToAbsolute(markdown = '', siteUrl, itemPath, _options = {}) {
|
|
6
|
-
const defaultOptions = {assetsOnly: false};
|
|
10
|
+
const defaultOptions = { assetsOnly: false };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
8
|
-
|
|
9
12
|
options.earlyExitMatchStr = '\\]\\([^\\s\\)]|href=|src=|srcset=';
|
|
10
13
|
if (options.assetsOnly) {
|
|
11
14
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
16
|
const transformFunctions = {
|
|
15
|
-
html:
|
|
16
|
-
url:
|
|
17
|
+
html: html_relative_to_absolute_1.default,
|
|
18
|
+
url: relative_to_absolute_1.default
|
|
17
19
|
};
|
|
18
|
-
|
|
19
|
-
return markdownTransform(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
20
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
module.exports = markdownRelativeToAbsolute;
|
|
22
|
+
exports.default = markdownRelativeToAbsolute;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const markdown_transform_1 = __importDefault(require("./markdown-transform"));
|
|
7
|
+
const html_relative_to_transform_ready_1 = __importDefault(require("./html-relative-to-transform-ready"));
|
|
8
|
+
const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
|
|
5
9
|
function markdownRelativeToTransformReady(markdown = '', siteUrl, itemPath, _options = {}) {
|
|
6
|
-
const defaultOptions = {assetsOnly: false};
|
|
10
|
+
const defaultOptions = { assetsOnly: false };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
8
|
-
|
|
9
12
|
options.earlyExitMatchStr = '\\]\\([^\\s\\)]|href=|src=|srcset=';
|
|
10
13
|
if (options.assetsOnly) {
|
|
11
14
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
12
15
|
}
|
|
13
|
-
|
|
14
16
|
const transformFunctions = {
|
|
15
|
-
html:
|
|
16
|
-
url:
|
|
17
|
+
html: html_relative_to_transform_ready_1.default,
|
|
18
|
+
url: relative_to_transform_ready_1.default
|
|
17
19
|
};
|
|
18
|
-
|
|
19
|
-
return markdownTransform(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
20
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
module.exports = markdownRelativeToTransformReady;
|
|
22
|
+
exports.default = markdownRelativeToTransformReady;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MarkdownTransformOptionsInput } from './types';
|
|
2
|
+
declare function markdownToTransformReady(markdown: string, siteUrl: string, itemPath: string | null | MarkdownTransformOptionsInput, options?: MarkdownTransformOptionsInput): string;
|
|
3
|
+
export default markdownToTransformReady;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const markdown_relative_to_absolute_1 = __importDefault(require("./markdown-relative-to-absolute"));
|
|
7
|
+
const markdown_absolute_to_transform_ready_1 = __importDefault(require("./markdown-absolute-to-transform-ready"));
|
|
4
8
|
function markdownToTransformReady(markdown, siteUrl, itemPath, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
else if (typeof itemPath === 'string') {
|
|
16
|
+
finalItemPath = itemPath;
|
|
17
|
+
}
|
|
18
|
+
const absolute = (0, markdown_relative_to_absolute_1.default)(markdown, siteUrl, finalItemPath, finalOptions);
|
|
19
|
+
return (0, markdown_absolute_to_transform_ready_1.default)(absolute, siteUrl, finalOptions);
|
|
11
20
|
}
|
|
12
|
-
|
|
13
|
-
module.exports = markdownToTransformReady;
|
|
21
|
+
exports.default = markdownToTransformReady;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MarkdownTransformOptionsInput, MarkdownTransformFunctions } from './types';
|
|
2
|
+
declare function markdownTransform(markdown: string | undefined, siteUrl: string, transformFunctions: MarkdownTransformFunctions, itemPath: string | null, _options?: MarkdownTransformOptionsInput): string;
|
|
3
|
+
export default markdownTransform;
|
|
@@ -1,44 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
3
|
let remark;
|
|
2
4
|
const footnotes = require('remark-footnotes');
|
|
3
5
|
const visit = require('unist-util-visit');
|
|
4
|
-
|
|
5
6
|
function replaceLast(find, replace, str) {
|
|
6
7
|
const lastIndex = str.lastIndexOf(find);
|
|
7
|
-
|
|
8
8
|
if (lastIndex === -1) {
|
|
9
9
|
return str;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
11
|
const begin = str.substring(0, lastIndex);
|
|
13
12
|
const end = str.substring(lastIndex + find.length);
|
|
14
|
-
|
|
15
13
|
return begin + replace + end;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath, _options = {}) {
|
|
19
|
-
const defaultOptions = {assetsOnly: false, ignoreProtocol: true};
|
|
16
|
+
const defaultOptions = { assetsOnly: false, ignoreProtocol: true };
|
|
20
17
|
const options = Object.assign({}, defaultOptions, _options);
|
|
21
|
-
|
|
22
18
|
if (!markdown || (options.earlyExitMatchStr && !markdown.match(new RegExp(options.earlyExitMatchStr)))) {
|
|
23
19
|
return markdown;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
const replacements = [];
|
|
27
|
-
|
|
28
22
|
if (!remark) {
|
|
29
23
|
remark = require('remark');
|
|
30
24
|
}
|
|
31
|
-
|
|
25
|
+
if (!remark) {
|
|
26
|
+
return markdown;
|
|
27
|
+
}
|
|
32
28
|
const tree = remark()
|
|
33
|
-
.use({settings: {commonmark: true}})
|
|
34
|
-
.use(footnotes, {inlineNotes: true})
|
|
29
|
+
.use({ settings: { commonmark: true } })
|
|
30
|
+
.use(footnotes, { inlineNotes: true })
|
|
35
31
|
.parse(markdown);
|
|
36
|
-
|
|
37
32
|
visit(tree, ['link', 'image', 'html'], (node) => {
|
|
38
|
-
if (node.type === 'html' && node.value.match(/src|srcset|href/)) {
|
|
33
|
+
if (node.type === 'html' && node.value && node.value.match(/src|srcset|href/) && node.position) {
|
|
39
34
|
const oldValue = node.value;
|
|
40
|
-
const newValue = transformFunctions.html(
|
|
41
|
-
|
|
35
|
+
const newValue = transformFunctions.html(oldValue, siteUrl, itemPath, options);
|
|
42
36
|
if (newValue !== oldValue) {
|
|
43
37
|
replacements.push({
|
|
44
38
|
old: oldValue,
|
|
@@ -48,11 +42,9 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
48
42
|
});
|
|
49
43
|
}
|
|
50
44
|
}
|
|
51
|
-
|
|
52
|
-
if (node.type === 'link' || node.type === 'image') {
|
|
45
|
+
if ((node.type === 'link' || node.type === 'image') && node.url && node.position) {
|
|
53
46
|
const oldValue = node.url;
|
|
54
|
-
const newValue = transformFunctions.url(
|
|
55
|
-
|
|
47
|
+
const newValue = transformFunctions.url(oldValue, siteUrl, itemPath, options);
|
|
56
48
|
if (newValue !== oldValue) {
|
|
57
49
|
replacements.push({
|
|
58
50
|
old: oldValue,
|
|
@@ -63,36 +55,29 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
63
55
|
}
|
|
64
56
|
}
|
|
65
57
|
});
|
|
66
|
-
|
|
67
58
|
let result = markdown;
|
|
68
59
|
let offsetAdjustment = 0;
|
|
69
60
|
let nestedAdjustment = 0;
|
|
70
|
-
|
|
71
61
|
replacements.forEach((replacement, i) => {
|
|
72
62
|
const original = markdown.slice(replacement.start, replacement.end);
|
|
73
63
|
// only transform last occurrence of the old string because markdown links and images
|
|
74
64
|
// have urls at the end and we see replacements for outermost nested nodes first
|
|
75
65
|
const transformed = replaceLast(replacement.old, replacement.new, original);
|
|
76
|
-
|
|
77
66
|
let before = result.slice(0, replacement.start + offsetAdjustment);
|
|
78
67
|
let after = result.slice(replacement.end + offsetAdjustment, result.length);
|
|
79
|
-
|
|
80
68
|
result = before + transformed + after;
|
|
81
|
-
|
|
82
69
|
// adjust offset according to new lengths
|
|
83
70
|
const nextReplacement = replacements[i + 1];
|
|
84
71
|
const adjustment = transformed.length - original.length;
|
|
85
|
-
|
|
86
72
|
if (nextReplacement && nextReplacement.start < replacement.end) {
|
|
87
73
|
// next replacement is nested, do not apply any offset adjustments until we're out of nesting
|
|
88
74
|
nestedAdjustment = nestedAdjustment + adjustment;
|
|
89
|
-
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
90
77
|
offsetAdjustment = offsetAdjustment + adjustment + nestedAdjustment;
|
|
91
78
|
nestedAdjustment = 0;
|
|
92
79
|
}
|
|
93
80
|
});
|
|
94
|
-
|
|
95
81
|
return result;
|
|
96
82
|
}
|
|
97
|
-
|
|
98
|
-
module.exports = markdownTransform;
|
|
83
|
+
exports.default = markdownTransform;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const absolute_to_relative_1 = __importDefault(require("./absolute-to-relative"));
|
|
7
|
+
const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
|
|
4
8
|
function mobiledocAbsoluteToRelative(serializedMobiledoc, siteUrl, _options = {}) {
|
|
5
|
-
const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
|
|
6
|
-
const overrideOptions = {siteUrl, transformType: 'absoluteToRelative'};
|
|
9
|
+
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
10
|
+
const overrideOptions = { siteUrl, transformType: 'absoluteToRelative' };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
8
|
-
|
|
9
12
|
const transformFunction = function (_url, _siteUrl, _itemPath, __options) {
|
|
10
|
-
return
|
|
13
|
+
return (0, absolute_to_relative_1.default)(_url, _siteUrl, __options);
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
return mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
15
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
module.exports = mobiledocAbsoluteToRelative;
|
|
17
|
+
exports.default = mobiledocAbsoluteToRelative;
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const absolute_to_transform_ready_1 = __importDefault(require("./absolute-to-transform-ready"));
|
|
7
|
+
const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
|
|
8
|
+
function mobiledocAbsoluteToTransformReady(serializedMobiledoc, siteUrl, _options = {}) {
|
|
9
|
+
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
10
|
+
const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
8
|
-
|
|
9
12
|
const transformFunction = function (_url, _siteUrl, _itemPath, __options) {
|
|
10
|
-
return
|
|
13
|
+
return (0, absolute_to_transform_ready_1.default)(_url, _siteUrl, __options);
|
|
11
14
|
};
|
|
12
|
-
|
|
13
|
-
return mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
15
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
14
16
|
}
|
|
15
|
-
|
|
16
|
-
module.exports = mobiledocAbsoluteToRelative;
|
|
17
|
+
exports.default = mobiledocAbsoluteToTransformReady;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MobiledocTransformOptionsInput } from './types';
|
|
2
|
+
declare function mobiledocRelativeToAbsolute(serializedMobiledoc: string, siteUrl: string, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocRelativeToAbsolute;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const relative_to_absolute_1 = __importDefault(require("./relative-to-absolute"));
|
|
7
|
+
const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
|
|
4
8
|
function mobiledocRelativeToAbsolute(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
|
|
5
|
-
const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
|
|
6
|
-
const overrideOptions = {siteUrl, itemPath, transformType: 'relativeToAbsolute'};
|
|
9
|
+
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
10
|
+
const overrideOptions = { siteUrl, itemPath, transformType: 'relativeToAbsolute' };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
8
|
-
|
|
9
|
-
return mobiledocTransform(serializedMobiledoc, siteUrl, relativeToAbsolute, itemPath, options);
|
|
12
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_absolute_1.default, itemPath, options);
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = mobiledocRelativeToAbsolute;
|
|
14
|
+
exports.default = mobiledocRelativeToAbsolute;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MobiledocTransformOptionsInput } from './types';
|
|
2
|
+
declare function mobiledocRelativeToTransformReady(serializedMobiledoc: string, siteUrl: string, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocRelativeToTransformReady;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const relative_to_transform_ready_1 = __importDefault(require("./relative-to-transform-ready"));
|
|
7
|
+
const mobiledoc_transform_1 = __importDefault(require("./mobiledoc-transform"));
|
|
4
8
|
function mobiledocRelativeToTransformReady(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
|
|
5
|
-
const defaultOptions = {assetsOnly: false, secure: false, cardTransformers: []};
|
|
6
|
-
const overrideOptions = {siteUrl, transformType: 'toTransformReady'};
|
|
9
|
+
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
10
|
+
const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
|
|
7
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
8
|
-
|
|
9
|
-
return mobiledocTransform(serializedMobiledoc, siteUrl, relativeToTransformReady, itemPath, options);
|
|
12
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_transform_ready_1.default, itemPath, options);
|
|
10
13
|
}
|
|
11
|
-
|
|
12
|
-
module.exports = mobiledocRelativeToTransformReady;
|
|
14
|
+
exports.default = mobiledocRelativeToTransformReady;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MobiledocTransformOptionsInput } from './types';
|
|
2
|
+
declare function mobiledocToTransformReady(mobiledoc: string, siteUrl: string, itemPath: string | null | MobiledocTransformOptionsInput, options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocToTransformReady;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const mobiledoc_relative_to_absolute_1 = __importDefault(require("./mobiledoc-relative-to-absolute"));
|
|
7
|
+
const mobiledoc_absolute_to_transform_ready_1 = __importDefault(require("./mobiledoc-absolute-to-transform-ready"));
|
|
4
8
|
function mobiledocToTransformReady(mobiledoc, siteUrl, itemPath, options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
8
14
|
}
|
|
9
|
-
|
|
10
|
-
|
|
15
|
+
else if (typeof itemPath === 'string') {
|
|
16
|
+
finalItemPath = itemPath;
|
|
17
|
+
}
|
|
18
|
+
const absolute = (0, mobiledoc_relative_to_absolute_1.default)(mobiledoc, siteUrl, finalItemPath, finalOptions);
|
|
19
|
+
return (0, mobiledoc_absolute_to_transform_ready_1.default)(absolute, siteUrl, finalOptions);
|
|
11
20
|
}
|
|
12
|
-
|
|
13
|
-
module.exports = mobiledocToTransformReady;
|
|
21
|
+
exports.default = mobiledocToTransformReady;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { MobiledocTransformOptionsInput, UrlTransformFunction } from './types';
|
|
2
|
+
declare function mobiledocTransform(serializedMobiledoc: string, siteUrl: string, transformFunction: UrlTransformFunction, itemPath: string | null, _options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocTransform;
|