@tryghost/url-utils 5.0.0 → 5.1.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/lib/UrlUtils.d.ts +147 -3
- package/lib/UrlUtils.js +228 -112
- package/lib/index.d.ts +2 -0
- package/lib/index.js +6 -0
- package/lib/utils/absolute-to-relative.d.ts +9 -3
- package/lib/utils/absolute-to-relative.js +14 -9
- package/lib/utils/absolute-to-transform-ready.d.ts +13 -4
- package/lib/utils/absolute-to-transform-ready.js +16 -11
- package/lib/utils/build-early-exit-match.d.ts +11 -1
- package/lib/utils/build-early-exit-match.js +4 -4
- package/lib/utils/deduplicate-double-slashes.d.ts +2 -1
- package/lib/utils/deduplicate-double-slashes.js +2 -2
- package/lib/utils/deduplicate-subdirectory.d.ts +2 -2
- package/lib/utils/deduplicate-subdirectory.js +4 -4
- package/lib/utils/html-absolute-to-relative.d.ts +3 -3
- package/lib/utils/html-absolute-to-relative.js +10 -7
- package/lib/utils/html-absolute-to-transform-ready.d.ts +3 -4
- package/lib/utils/html-absolute-to-transform-ready.js +16 -9
- package/lib/utils/html-relative-to-absolute.d.ts +3 -3
- package/lib/utils/html-relative-to-absolute.js +43 -8
- package/lib/utils/html-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/html-relative-to-transform-ready.js +51 -11
- package/lib/utils/html-to-transform-ready.d.ts +3 -3
- package/lib/utils/html-to-transform-ready.js +17 -9
- package/lib/utils/html-transform.d.ts +5 -4
- package/lib/utils/html-transform.js +25 -21
- package/lib/utils/index.d.ts +76 -0
- package/lib/utils/index.js +115 -38
- package/lib/utils/is-ssl.d.ts +2 -2
- package/lib/utils/is-ssl.js +4 -4
- package/lib/utils/lexical-absolute-to-relative.d.ts +3 -2
- package/lib/utils/lexical-absolute-to-relative.js +9 -6
- package/lib/utils/lexical-absolute-to-transform-ready.d.ts +3 -2
- package/lib/utils/lexical-absolute-to-transform-ready.js +10 -7
- package/lib/utils/lexical-relative-to-absolute.d.ts +3 -3
- package/lib/utils/lexical-relative-to-absolute.js +8 -5
- package/lib/utils/lexical-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/lexical-relative-to-transform-ready.js +8 -5
- package/lib/utils/lexical-to-transform-ready.d.ts +3 -3
- package/lib/utils/lexical-to-transform-ready.js +17 -9
- package/lib/utils/lexical-transform.d.ts +3 -2
- package/lib/utils/lexical-transform.js +22 -19
- package/lib/utils/markdown-absolute-to-relative.d.ts +3 -4
- package/lib/utils/markdown-absolute-to-relative.js +11 -8
- package/lib/utils/markdown-absolute-to-transform-ready.d.ts +3 -5
- package/lib/utils/markdown-absolute-to-transform-ready.js +17 -10
- package/lib/utils/markdown-relative-to-absolute.d.ts +3 -4
- package/lib/utils/markdown-relative-to-absolute.js +11 -8
- package/lib/utils/markdown-relative-to-transform-ready.d.ts +3 -4
- package/lib/utils/markdown-relative-to-transform-ready.js +11 -8
- package/lib/utils/markdown-to-transform-ready.d.ts +3 -3
- package/lib/utils/markdown-to-transform-ready.js +17 -9
- package/lib/utils/markdown-transform.d.ts +3 -5
- package/lib/utils/markdown-transform.js +12 -6
- package/lib/utils/mobiledoc-absolute-to-relative.d.ts +3 -2
- package/lib/utils/mobiledoc-absolute-to-relative.js +9 -6
- package/lib/utils/mobiledoc-absolute-to-transform-ready.d.ts +3 -2
- package/lib/utils/mobiledoc-absolute-to-transform-ready.js +10 -7
- package/lib/utils/mobiledoc-relative-to-absolute.d.ts +3 -3
- package/lib/utils/mobiledoc-relative-to-absolute.js +8 -5
- package/lib/utils/mobiledoc-relative-to-transform-ready.d.ts +3 -3
- package/lib/utils/mobiledoc-relative-to-transform-ready.js +8 -5
- package/lib/utils/mobiledoc-to-transform-ready.d.ts +3 -3
- package/lib/utils/mobiledoc-to-transform-ready.js +17 -9
- package/lib/utils/mobiledoc-transform.d.ts +3 -1
- package/lib/utils/mobiledoc-transform.js +5 -4
- package/lib/utils/plaintext-absolute-to-transform-ready.d.ts +5 -4
- package/lib/utils/plaintext-absolute-to-transform-ready.js +16 -11
- package/lib/utils/plaintext-relative-to-transform-ready.d.ts +3 -2
- package/lib/utils/plaintext-relative-to-transform-ready.js +15 -7
- package/lib/utils/plaintext-to-transform-ready.d.ts +5 -3
- package/lib/utils/plaintext-to-transform-ready.js +17 -9
- package/lib/utils/relative-to-absolute.d.ts +5 -3
- package/lib/utils/relative-to-absolute.js +26 -19
- package/lib/utils/relative-to-transform-ready.d.ts +8 -2
- package/lib/utils/relative-to-transform-ready.js +22 -10
- package/lib/utils/replace-permalink.d.ts +13 -2
- package/lib/utils/replace-permalink.js +44 -8
- package/lib/utils/strip-subdirectory-from-path.d.ts +1 -1
- package/lib/utils/strip-subdirectory-from-path.js +5 -5
- package/lib/utils/to-transform-ready.d.ts +5 -3
- package/lib/utils/to-transform-ready.js +17 -9
- package/lib/utils/transform-ready-to-absolute.d.ts +9 -1
- package/lib/utils/transform-ready-to-absolute.js +2 -2
- package/lib/utils/transform-ready-to-relative.d.ts +3 -1
- package/lib/utils/transform-ready-to-relative.js +4 -3
- package/lib/utils/types.d.ts +92 -0
- package/lib/utils/types.js +2 -0
- package/lib/utils/url-join.d.ts +5 -2
- package/lib/utils/url-join.js +11 -5
- package/package.json +10 -11
- package/index.js +0 -2
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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"));
|
|
6
9
|
function markdownRelativeToAbsolute(markdown = '', siteUrl, itemPath, _options = {}) {
|
|
7
10
|
const defaultOptions = { assetsOnly: false };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
@@ -11,9 +14,9 @@ function markdownRelativeToAbsolute(markdown = '', siteUrl, itemPath, _options =
|
|
|
11
14
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
12
15
|
}
|
|
13
16
|
const transformFunctions = {
|
|
14
|
-
html:
|
|
15
|
-
url:
|
|
17
|
+
html: html_relative_to_absolute_1.default,
|
|
18
|
+
url: relative_to_absolute_1.default
|
|
16
19
|
};
|
|
17
|
-
return
|
|
20
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
exports.default = markdownRelativeToAbsolute;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
declare function markdownRelativeToTransformReady(markdown: string | undefined, siteUrl: any, itemPath: any, _options?: {}): any;
|
|
1
|
+
import type { SecureOptionsInput } from './types';
|
|
2
|
+
declare function markdownRelativeToTransformReady(markdown: string | undefined, siteUrl: string, itemPath: string | null, _options?: SecureOptionsInput): string;
|
|
3
|
+
export default markdownRelativeToTransformReady;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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"));
|
|
6
9
|
function markdownRelativeToTransformReady(markdown = '', siteUrl, itemPath, _options = {}) {
|
|
7
10
|
const defaultOptions = { assetsOnly: false };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options);
|
|
@@ -11,9 +14,9 @@ function markdownRelativeToTransformReady(markdown = '', siteUrl, itemPath, _opt
|
|
|
11
14
|
options.earlyExitMatchStr = options.staticImageUrlPrefix;
|
|
12
15
|
}
|
|
13
16
|
const transformFunctions = {
|
|
14
|
-
html:
|
|
15
|
-
url:
|
|
17
|
+
html: html_relative_to_transform_ready_1.default,
|
|
18
|
+
url: relative_to_transform_ready_1.default
|
|
16
19
|
};
|
|
17
|
-
return
|
|
20
|
+
return (0, markdown_transform_1.default)(markdown, siteUrl, transformFunctions, itemPath, options);
|
|
18
21
|
}
|
|
19
|
-
|
|
22
|
+
exports.default = markdownRelativeToTransformReady;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
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
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
8
|
function markdownToTransformReady(markdown, siteUrl, itemPath, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
12
20
|
}
|
|
13
|
-
|
|
21
|
+
exports.default = markdownToTransformReady;
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
3
|
-
|
|
4
|
-
declare function replaceLast(find: any, replace: any, str: any): any;
|
|
5
|
-
declare function markdownTransform(markdown: string | undefined, siteUrl: any, transformFunctions: any, itemPath: any, _options?: {}): string;
|
|
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,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-require-imports */
|
|
3
4
|
let remark;
|
|
4
5
|
const footnotes = require('remark-footnotes');
|
|
5
6
|
const visit = require('unist-util-visit');
|
|
7
|
+
/* eslint-enable @typescript-eslint/no-require-imports */
|
|
6
8
|
function replaceLast(find, replace, str) {
|
|
7
9
|
const lastIndex = str.lastIndexOf(find);
|
|
8
10
|
if (lastIndex === -1) {
|
|
@@ -20,16 +22,20 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
20
22
|
}
|
|
21
23
|
const replacements = [];
|
|
22
24
|
if (!remark) {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
23
26
|
remark = require('remark');
|
|
24
27
|
}
|
|
28
|
+
if (!remark) {
|
|
29
|
+
return markdown;
|
|
30
|
+
}
|
|
25
31
|
const tree = remark()
|
|
26
32
|
.use({ settings: { commonmark: true } })
|
|
27
33
|
.use(footnotes, { inlineNotes: true })
|
|
28
34
|
.parse(markdown);
|
|
29
35
|
visit(tree, ['link', 'image', 'html'], (node) => {
|
|
30
|
-
if (node.type === 'html' && node.value.match(/src|srcset|href/)) {
|
|
36
|
+
if (node.type === 'html' && node.value && node.value.match(/src|srcset|href/) && node.position) {
|
|
31
37
|
const oldValue = node.value;
|
|
32
|
-
const newValue = transformFunctions.html(
|
|
38
|
+
const newValue = transformFunctions.html(oldValue, siteUrl, itemPath, options);
|
|
33
39
|
if (newValue !== oldValue) {
|
|
34
40
|
replacements.push({
|
|
35
41
|
old: oldValue,
|
|
@@ -39,9 +45,9 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
39
45
|
});
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
|
-
if (node.type === 'link' || node.type === 'image') {
|
|
48
|
+
if ((node.type === 'link' || node.type === 'image') && node.url && node.position) {
|
|
43
49
|
const oldValue = node.url;
|
|
44
|
-
const newValue = transformFunctions.url(
|
|
50
|
+
const newValue = transformFunctions.url(oldValue, siteUrl, itemPath, options);
|
|
45
51
|
if (newValue !== oldValue) {
|
|
46
52
|
replacements.push({
|
|
47
53
|
old: oldValue,
|
|
@@ -77,4 +83,4 @@ function markdownTransform(markdown = '', siteUrl, transformFunctions, itemPath,
|
|
|
77
83
|
});
|
|
78
84
|
return result;
|
|
79
85
|
}
|
|
80
|
-
|
|
86
|
+
exports.default = markdownTransform;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
1
|
+
import type { MobiledocTransformOptionsInput } from './types';
|
|
2
|
+
declare function mobiledocAbsoluteToRelative(serializedMobiledoc: string, siteUrl: string, _options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocAbsoluteToRelative;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
8
|
function mobiledocAbsoluteToRelative(serializedMobiledoc, siteUrl, _options = {}) {
|
|
6
9
|
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
7
10
|
const overrideOptions = { siteUrl, transformType: 'absoluteToRelative' };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
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
|
-
return
|
|
15
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
exports.default = mobiledocAbsoluteToRelative;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
1
|
+
import type { MobiledocTransformOptionsInput } from './types';
|
|
2
|
+
declare function mobiledocAbsoluteToTransformReady(serializedMobiledoc: string, siteUrl: string, _options?: MobiledocTransformOptionsInput): string;
|
|
3
|
+
export default mobiledocAbsoluteToTransformReady;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 = {}) {
|
|
6
9
|
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
7
10
|
const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
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
|
-
return
|
|
15
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, transformFunction, '', options);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
exports.default = mobiledocAbsoluteToTransformReady;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
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,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
8
|
function mobiledocRelativeToAbsolute(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
|
|
6
9
|
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
7
10
|
const overrideOptions = { siteUrl, itemPath, transformType: 'relativeToAbsolute' };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
9
|
-
return
|
|
12
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_absolute_1.default, itemPath, options);
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
exports.default = mobiledocRelativeToAbsolute;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
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,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
8
|
function mobiledocRelativeToTransformReady(serializedMobiledoc, siteUrl, itemPath, _options = {}) {
|
|
6
9
|
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
7
10
|
const overrideOptions = { siteUrl, transformType: 'toTransformReady' };
|
|
8
11
|
const options = Object.assign({}, defaultOptions, _options, overrideOptions);
|
|
9
|
-
return
|
|
12
|
+
return (0, mobiledoc_transform_1.default)(serializedMobiledoc, siteUrl, relative_to_transform_ready_1.default, itemPath, options);
|
|
10
13
|
}
|
|
11
|
-
|
|
14
|
+
exports.default = mobiledocRelativeToTransformReady;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare
|
|
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
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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"));
|
|
5
8
|
function mobiledocToTransformReady(mobiledoc, siteUrl, itemPath, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
|
|
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);
|
|
12
20
|
}
|
|
13
|
-
|
|
21
|
+
exports.default = mobiledocToTransformReady;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, itemPath, _options = {}) {
|
|
4
4
|
const defaultOptions = { assetsOnly: false, secure: false, cardTransformers: [] };
|
|
5
5
|
const options = Object.assign({}, defaultOptions, _options, { siteUrl, itemPath });
|
|
@@ -25,7 +25,7 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
|
|
|
25
25
|
hrefIndex = index + 1;
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
if (hrefIndex !== -1) {
|
|
28
|
+
if (hrefIndex !== -1 && typeof markup[1][hrefIndex] === 'string') {
|
|
29
29
|
const transformedUrl = transformFunction(markup[1][hrefIndex], siteUrl, itemPath, options);
|
|
30
30
|
if (transformedUrl) {
|
|
31
31
|
markup[1][hrefIndex] = transformedUrl;
|
|
@@ -37,7 +37,8 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
|
|
|
37
37
|
// cards may contain so we sub out to card-specific transform functions that
|
|
38
38
|
// are passed in as options from the consuming application.
|
|
39
39
|
(mobiledoc.cards || []).forEach((card) => {
|
|
40
|
-
const
|
|
40
|
+
const name = card[0];
|
|
41
|
+
const payload = card[1];
|
|
41
42
|
if (cardTransformers[name]) {
|
|
42
43
|
// transformers take a payload and return a transformed payload
|
|
43
44
|
const transformedPayload = cardTransformers[name](payload, options);
|
|
@@ -46,4 +47,4 @@ function mobiledocTransform(serializedMobiledoc, siteUrl, transformFunction, ite
|
|
|
46
47
|
});
|
|
47
48
|
return JSON.stringify(mobiledoc);
|
|
48
49
|
}
|
|
49
|
-
|
|
50
|
+
exports.default = mobiledocTransform;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare const plaintextAbsoluteToTransformReady: (plaintext:
|
|
1
|
+
import type { AbsoluteToTransformReadyOptionsInput, BaseUrlOptionsInput } from './types';
|
|
2
|
+
type PlaintextAbsoluteToTransformReadyOptions = AbsoluteToTransformReadyOptionsInput & BaseUrlOptionsInput;
|
|
3
|
+
type PlaintextAbsoluteToTransformReadyOptionsInput = Partial<PlaintextAbsoluteToTransformReadyOptions>;
|
|
4
|
+
declare const plaintextAbsoluteToTransformReady: (plaintext: string, rootUrl: string, itemPath: string | null | PlaintextAbsoluteToTransformReadyOptionsInput, options?: PlaintextAbsoluteToTransformReadyOptionsInput) => string;
|
|
5
|
+
export default plaintextAbsoluteToTransformReady;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 build_early_exit_match_1 = __importDefault(require("./build-early-exit-match"));
|
|
8
|
+
const { escapeRegExp } = build_early_exit_match_1.default;
|
|
9
|
+
const url_1 = require("url");
|
|
5
10
|
function buildLinkRegex(rootUrl, options = {}) {
|
|
6
11
|
// Build a regex that matches links from ANY configured base URL (site + CDNs)
|
|
7
12
|
const baseUrls = [rootUrl, options.imageBaseUrl, options.filesBaseUrl, options.mediaBaseUrl]
|
|
8
|
-
.filter(Boolean);
|
|
13
|
+
.filter((value) => Boolean(value));
|
|
9
14
|
const patterns = baseUrls.map((baseUrl) => {
|
|
10
|
-
const parsed = new URL(baseUrl);
|
|
15
|
+
const parsed = new url_1.URL(baseUrl);
|
|
11
16
|
const escapedUrl = escapeRegExp(`${parsed.hostname}${parsed.pathname.replace(/\/$/, '')}`);
|
|
12
17
|
return escapedUrl;
|
|
13
18
|
});
|
|
@@ -19,16 +24,16 @@ function buildLinkRegex(rootUrl, options = {}) {
|
|
|
19
24
|
}
|
|
20
25
|
const plaintextAbsoluteToTransformReady = function plaintextAbsoluteToTransformReady(plaintext, rootUrl, itemPath, options) {
|
|
21
26
|
// itemPath is optional, if it's an object may be the options param instead
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
27
|
+
let finalOptions = options || {};
|
|
28
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
29
|
+
finalOptions = itemPath;
|
|
25
30
|
}
|
|
26
31
|
// plaintext links look like "Link title [url]"
|
|
27
32
|
// those links are all we care about so we can do a fast regex here
|
|
28
|
-
const linkRegex = buildLinkRegex(rootUrl,
|
|
33
|
+
const linkRegex = buildLinkRegex(rootUrl, finalOptions);
|
|
29
34
|
return plaintext.replace(linkRegex, function (fullMatch, url) {
|
|
30
|
-
const newUrl =
|
|
35
|
+
const newUrl = (0, absolute_to_transform_ready_1.default)(`${url}`, rootUrl, finalOptions);
|
|
31
36
|
return ` [${newUrl}]`;
|
|
32
37
|
});
|
|
33
38
|
};
|
|
34
|
-
|
|
39
|
+
exports.default = plaintextAbsoluteToTransformReady;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
declare const plaintextRelativeToTransformReady: (plaintext:
|
|
1
|
+
import type { RelativeToTransformReadyOptionsInput } from './relative-to-transform-ready';
|
|
2
|
+
declare const plaintextRelativeToTransformReady: (plaintext: string, rootUrl: string, itemPath: string | null | RelativeToTransformReadyOptionsInput, options?: RelativeToTransformReadyOptionsInput) => string;
|
|
3
|
+
export default plaintextRelativeToTransformReady;
|
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
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"));
|
|
4
7
|
const plaintextRelativeToTransformReady = function plaintextRelativeToTransformReady(plaintext, rootUrl, itemPath, options) {
|
|
5
8
|
// itemPath is optional, if it's an object may be the options param instead
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
14
|
+
}
|
|
15
|
+
else if (typeof itemPath === 'string') {
|
|
16
|
+
finalItemPath = itemPath;
|
|
9
17
|
}
|
|
10
18
|
// plaintext links look like "Link title [url]"
|
|
11
19
|
// those are all we care about so we can do a fast regex here
|
|
12
20
|
return plaintext.replace(/ \[(\/.*?)\]/g, function (fullMatch, path) {
|
|
13
|
-
const newPath =
|
|
21
|
+
const newPath = (0, relative_to_transform_ready_1.default)(`${path}`, rootUrl, finalItemPath, finalOptions);
|
|
14
22
|
return ` [${newPath}]`;
|
|
15
23
|
});
|
|
16
24
|
};
|
|
17
|
-
|
|
25
|
+
exports.default = plaintextRelativeToTransformReady;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { UnknownRecord } from './types';
|
|
2
|
+
type PlaintextTransformOptions = UnknownRecord;
|
|
3
|
+
type PlaintextTransformOptionsInput = Partial<PlaintextTransformOptions>;
|
|
4
|
+
declare function plaintextToTransformReady(plaintext: string, siteUrl: string, itemPath: string | null | PlaintextTransformOptionsInput, options?: PlaintextTransformOptionsInput): string;
|
|
5
|
+
export default plaintextToTransformReady;
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 plaintext_relative_to_transform_ready_1 = __importDefault(require("./plaintext-relative-to-transform-ready"));
|
|
7
|
+
const plaintext_absolute_to_transform_ready_1 = __importDefault(require("./plaintext-absolute-to-transform-ready"));
|
|
5
8
|
function plaintextToTransformReady(plaintext, siteUrl, itemPath, options) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
let finalItemPath = null;
|
|
10
|
+
let finalOptions = options || {};
|
|
11
|
+
if (typeof itemPath === 'object' && itemPath !== null && !options) {
|
|
12
|
+
finalOptions = itemPath;
|
|
13
|
+
finalItemPath = null;
|
|
9
14
|
}
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
else if (typeof itemPath === 'string') {
|
|
16
|
+
finalItemPath = itemPath;
|
|
17
|
+
}
|
|
18
|
+
const relativeTransformed = (0, plaintext_relative_to_transform_ready_1.default)(plaintext, siteUrl, finalItemPath, finalOptions);
|
|
19
|
+
return (0, plaintext_absolute_to_transform_ready_1.default)(relativeTransformed, siteUrl, finalOptions);
|
|
12
20
|
}
|
|
13
|
-
|
|
21
|
+
exports.default = plaintextToTransformReady;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type { SecureOptions, SecureOptionsInput } from './types';
|
|
2
|
+
export type RelativeToAbsoluteOptions = SecureOptions;
|
|
3
|
+
export type RelativeToAbsoluteOptionsInput = SecureOptionsInput;
|
|
3
4
|
/**
|
|
4
5
|
* Convert a root-relative path to an absolute URL based on the supplied root.
|
|
5
6
|
* Will _only_ convert root-relative urls (/some/path not some/path)
|
|
@@ -10,4 +11,5 @@ declare const urlJoin: any;
|
|
|
10
11
|
* @param {object} options
|
|
11
12
|
* @returns {string} The passed in url or an absolute URL using
|
|
12
13
|
*/
|
|
13
|
-
declare const relativeToAbsolute: (path:
|
|
14
|
+
declare const relativeToAbsolute: (path: string, rootUrl: string, itemPath: string | null | RelativeToAbsoluteOptionsInput, _options?: RelativeToAbsoluteOptionsInput) => string;
|
|
15
|
+
export default relativeToAbsolute;
|