@docusaurus/utils 3.3.0 → 3.4.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/hashUtils.d.ts +4 -1
- package/lib/hashUtils.d.ts.map +1 -1
- package/lib/hashUtils.js +9 -3
- package/lib/hashUtils.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -4
- package/lib/index.js.map +1 -1
- package/lib/markdownLinks.d.ts +7 -34
- package/lib/markdownLinks.d.ts.map +1 -1
- package/lib/markdownLinks.js +22 -104
- package/lib/markdownLinks.js.map +1 -1
- package/lib/tags.d.ts +35 -18
- package/lib/tags.d.ts.map +1 -1
- package/lib/tags.js +57 -28
- package/lib/tags.js.map +1 -1
- package/lib/urlUtils.d.ts +14 -0
- package/lib/urlUtils.d.ts.map +1 -1
- package/lib/urlUtils.js +66 -19
- package/lib/urlUtils.js.map +1 -1
- package/package.json +6 -5
- package/src/hashUtils.ts +20 -3
- package/src/index.ts +11 -3
- package/src/markdownLinks.ts +32 -151
- package/src/tags.ts +121 -36
- package/src/urlUtils.ts +76 -22
package/lib/urlUtils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.d.ts","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAoFtD;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CACxB,gBAAgB,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,MAAM,GACf,MAAM,GAAG,SAAS,CAKpB;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ/C;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM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AiB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAwCjE;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAIzD;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAIjE;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CACzB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAC3B,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,MAAM,EAClB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,MAAM,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAKR;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAU7D"}
|
package/lib/urlUtils.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = exports.resolvePathname = exports.serializeURLPath = exports.parseURLPath = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
9
|
+
exports.hasSSHProtocol = exports.buildHttpsUrl = exports.buildSshUrl = exports.resolvePathname = exports.serializeURLPath = exports.parseLocalURLPath = exports.parseURLPath = exports.toURLPath = exports.parseURLOrPath = exports.isValidPathname = exports.encodePath = exports.fileToPath = exports.getEditUrl = exports.normalizeUrl = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const resolve_pathname_1 = tslib_1.__importDefault(require("resolve-pathname"));
|
|
12
12
|
/**
|
|
@@ -77,7 +77,7 @@ function normalizeUrl(rawUrls) {
|
|
|
77
77
|
// Each input component is now separated by a single slash except the possible
|
|
78
78
|
// first plain protocol part.
|
|
79
79
|
// Remove trailing slash before parameters or hash.
|
|
80
|
-
str = str.replace(/\/(?<search>\?|&|#[
|
|
80
|
+
str = str.replace(/\/(?<search>\?|&|#[^!/])/g, '$1');
|
|
81
81
|
// Replace ? in parameters with &.
|
|
82
82
|
const parts = str.split('?');
|
|
83
83
|
str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
|
|
@@ -144,21 +144,18 @@ function isValidPathname(str) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
exports.isValidPathname = isValidPathname;
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
}
|
|
156
|
-
catch (e) {
|
|
157
|
-
throw new Error(`Can't parse URL ${url}${base ? ` with base ${base}` : ''}`, { cause: e });
|
|
158
|
-
}
|
|
147
|
+
function parseURLOrPath(url, base) {
|
|
148
|
+
try {
|
|
149
|
+
// TODO when Node supports it, use URL.parse could be faster?
|
|
150
|
+
// see https://kilianvalkhof.com/2024/javascript/the-problem-with-new-url-and-how-url-parse-fixes-that/
|
|
151
|
+
return new URL(url, base ?? 'https://example.com');
|
|
152
|
+
}
|
|
153
|
+
catch (e) {
|
|
154
|
+
throw new Error(`Can't parse URL ${url}${base ? ` with base ${base}` : ''}`, { cause: e });
|
|
159
155
|
}
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
}
|
|
157
|
+
exports.parseURLOrPath = parseURLOrPath;
|
|
158
|
+
function toURLPath(url) {
|
|
162
159
|
const { pathname } = url;
|
|
163
160
|
// Fixes annoying url.search behavior
|
|
164
161
|
// "" => undefined
|
|
@@ -166,16 +163,16 @@ function parseURLPath(urlPath, fromPath) {
|
|
|
166
163
|
// "?param => "param"
|
|
167
164
|
const search = url.search
|
|
168
165
|
? url.search.slice(1)
|
|
169
|
-
:
|
|
166
|
+
: url.href.includes('?')
|
|
170
167
|
? ''
|
|
171
168
|
: undefined;
|
|
172
169
|
// Fixes annoying url.hash behavior
|
|
173
170
|
// "" => undefined
|
|
174
171
|
// "#" => ""
|
|
175
|
-
// "
|
|
172
|
+
// "#param => "param"
|
|
176
173
|
const hash = url.hash
|
|
177
174
|
? url.hash.slice(1)
|
|
178
|
-
:
|
|
175
|
+
: url.href.includes('#')
|
|
179
176
|
? ''
|
|
180
177
|
: undefined;
|
|
181
178
|
return {
|
|
@@ -184,7 +181,57 @@ function parseURLPath(urlPath, fromPath) {
|
|
|
184
181
|
hash,
|
|
185
182
|
};
|
|
186
183
|
}
|
|
184
|
+
exports.toURLPath = toURLPath;
|
|
185
|
+
/**
|
|
186
|
+
* Let's name the concept of (pathname + search + hash) as URLPath
|
|
187
|
+
* See also https://twitter.com/kettanaito/status/1741768992866308120
|
|
188
|
+
* Note: this function also resolves relative pathnames while parsing!
|
|
189
|
+
*/
|
|
190
|
+
function parseURLPath(urlPath, fromPath) {
|
|
191
|
+
const base = fromPath ? parseURLOrPath(fromPath) : undefined;
|
|
192
|
+
const url = parseURLOrPath(urlPath, base);
|
|
193
|
+
return toURLPath(url);
|
|
194
|
+
}
|
|
187
195
|
exports.parseURLPath = parseURLPath;
|
|
196
|
+
/**
|
|
197
|
+
* This returns results for strings like "foo", "../foo", "./foo.mdx?qs#hash"
|
|
198
|
+
* Unlike "parseURLPath()" above, this will not resolve the pathnames
|
|
199
|
+
* Te returned pathname of "../../foo.mdx" will be "../../foo.mdx", not "/foo"
|
|
200
|
+
* This returns null if the url is not "local" (contains domain/protocol etc)
|
|
201
|
+
*/
|
|
202
|
+
function parseLocalURLPath(urlPath) {
|
|
203
|
+
// Workaround because URL("") requires a protocol
|
|
204
|
+
const unspecifiedProtocol = 'unspecified:';
|
|
205
|
+
const url = parseURLOrPath(urlPath, `${unspecifiedProtocol}//`);
|
|
206
|
+
// Ignore links with specified protocol / host
|
|
207
|
+
// (usually fully qualified links starting with https://)
|
|
208
|
+
if (url.protocol !== unspecifiedProtocol ||
|
|
209
|
+
url.host !== '' ||
|
|
210
|
+
url.username !== '' ||
|
|
211
|
+
url.password !== '') {
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
214
|
+
// We can't use "new URL()" result because it always tries to resolve urls
|
|
215
|
+
// IE it will remove any "./" or "../" in the pathname, which we don't want
|
|
216
|
+
// We have to parse it manually...
|
|
217
|
+
let localUrlPath = urlPath;
|
|
218
|
+
// Extract and remove the #hash part
|
|
219
|
+
const hashIndex = localUrlPath.indexOf('#');
|
|
220
|
+
const hash = hashIndex !== -1 ? localUrlPath.substring(hashIndex + 1) : undefined;
|
|
221
|
+
localUrlPath =
|
|
222
|
+
hashIndex !== -1 ? localUrlPath.substring(0, hashIndex) : localUrlPath;
|
|
223
|
+
// Extract and remove ?search part
|
|
224
|
+
const searchIndex = localUrlPath.indexOf('?');
|
|
225
|
+
const search = searchIndex !== -1 ? localUrlPath.substring(searchIndex + 1) : undefined;
|
|
226
|
+
localUrlPath =
|
|
227
|
+
searchIndex !== -1 ? localUrlPath.substring(0, searchIndex) : localUrlPath;
|
|
228
|
+
return {
|
|
229
|
+
pathname: localUrlPath,
|
|
230
|
+
search,
|
|
231
|
+
hash,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
exports.parseLocalURLPath = parseLocalURLPath;
|
|
188
235
|
function serializeURLPath(urlPath) {
|
|
189
236
|
const search = urlPath.search === undefined ? '' : `?${urlPath.search}`;
|
|
190
237
|
const hash = urlPath.hash === undefined ? '' : `#${urlPath.hash}`;
|
package/lib/urlUtils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlUtils.js","sourceRoot":"","sources":["../src/urlUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gFAAqD;AAErD;;;;;;;;;;;GAWG;AACH,S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Aa,CAAC,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;YAC/C,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAAC,MAAM,CAAC;QACP,oCAAoC;QACpC,OAAO,+BAA+B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC;AAVD,wCAUC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"description": "Node utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "3.
|
|
22
|
-
"@docusaurus/utils-common": "3.
|
|
21
|
+
"@docusaurus/logger": "3.4.0",
|
|
22
|
+
"@docusaurus/utils-common": "3.4.0",
|
|
23
23
|
"@svgr/webpack": "^8.1.0",
|
|
24
24
|
"escape-string-regexp": "^4.0.0",
|
|
25
25
|
"file-loader": "^6.2.0",
|
|
@@ -36,13 +36,14 @@
|
|
|
36
36
|
"shelljs": "^0.8.5",
|
|
37
37
|
"tslib": "^2.6.0",
|
|
38
38
|
"url-loader": "^4.1.1",
|
|
39
|
+
"utility-types": "^3.10.0",
|
|
39
40
|
"webpack": "^5.88.1"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
43
|
"node": ">=18.0"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/types": "3.
|
|
46
|
+
"@docusaurus/types": "3.4.0",
|
|
46
47
|
"@types/dedent": "^0.7.0",
|
|
47
48
|
"@types/github-slugger": "^1.3.0",
|
|
48
49
|
"@types/micromatch": "^4.0.2",
|
|
@@ -58,5 +59,5 @@
|
|
|
58
59
|
"optional": true
|
|
59
60
|
}
|
|
60
61
|
},
|
|
61
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "49e9a2143274a8dd795659b417b470bc42abbd6e"
|
|
62
63
|
}
|
package/src/hashUtils.ts
CHANGED
|
@@ -25,11 +25,28 @@ export function simpleHash(str: string, length: number): string {
|
|
|
25
25
|
* collision. Also removes part of the string if its larger than the allowed
|
|
26
26
|
* filename per OS, avoiding `ERRNAMETOOLONG` error.
|
|
27
27
|
*/
|
|
28
|
-
export function docuHash(
|
|
29
|
-
|
|
28
|
+
export function docuHash(
|
|
29
|
+
strInput: string,
|
|
30
|
+
options?: {
|
|
31
|
+
// String that contributes to the hash value
|
|
32
|
+
// but does not contribute to the returned string
|
|
33
|
+
hashExtra?: string;
|
|
34
|
+
// Length of the hash to append
|
|
35
|
+
hashLength?: number;
|
|
36
|
+
},
|
|
37
|
+
): string {
|
|
38
|
+
// TODO check this historical behavior
|
|
39
|
+
// I'm not sure it makes sense to keep it...
|
|
40
|
+
if (strInput === '/' && typeof options?.hashExtra === 'undefined') {
|
|
30
41
|
return 'index';
|
|
31
42
|
}
|
|
32
|
-
const
|
|
43
|
+
const str = strInput === '/' ? 'index' : strInput;
|
|
44
|
+
|
|
45
|
+
const hashExtra = options?.hashExtra ?? '';
|
|
46
|
+
const hashLength = options?.hashLength ?? 3;
|
|
47
|
+
|
|
48
|
+
const stringToHash = str + hashExtra;
|
|
49
|
+
const shortHash = simpleHash(stringToHash, hashLength);
|
|
33
50
|
const parsedPath = `${_.kebabCase(str)}-${shortHash}`;
|
|
34
51
|
if (isNameTooLong(parsedPath)) {
|
|
35
52
|
return `${shortName(_.kebabCase(str))}-${shortHash}`;
|
package/src/index.ts
CHANGED
|
@@ -44,6 +44,9 @@ export {
|
|
|
44
44
|
isValidPathname,
|
|
45
45
|
resolvePathname,
|
|
46
46
|
parseURLPath,
|
|
47
|
+
parseLocalURLPath,
|
|
48
|
+
parseURLOrPath,
|
|
49
|
+
toURLPath,
|
|
47
50
|
serializeURLPath,
|
|
48
51
|
hasSSHProtocol,
|
|
49
52
|
buildHttpsUrl,
|
|
@@ -52,10 +55,13 @@ export {
|
|
|
52
55
|
export type {URLPath} from './urlUtils';
|
|
53
56
|
export {
|
|
54
57
|
type Tag,
|
|
58
|
+
type TagsFile,
|
|
59
|
+
type TagsFileInput,
|
|
60
|
+
type TagMetadata,
|
|
55
61
|
type TagsListItem,
|
|
56
62
|
type TagModule,
|
|
57
63
|
type FrontMatterTag,
|
|
58
|
-
|
|
64
|
+
type TagsPluginOptions,
|
|
59
65
|
groupTaggedItems,
|
|
60
66
|
getTagVisibility,
|
|
61
67
|
} from './tags';
|
|
@@ -73,8 +79,8 @@ export {
|
|
|
73
79
|
} from './markdownUtils';
|
|
74
80
|
export {
|
|
75
81
|
type ContentPaths,
|
|
76
|
-
type
|
|
77
|
-
|
|
82
|
+
type SourceToPermalink,
|
|
83
|
+
resolveMarkdownLinkPathname,
|
|
78
84
|
} from './markdownLinks';
|
|
79
85
|
export {type SluggerOptions, type Slugger, createSlugger} from './slugger';
|
|
80
86
|
export {
|
|
@@ -121,3 +127,5 @@ export {
|
|
|
121
127
|
type LastUpdateData,
|
|
122
128
|
type FrontMatterLastUpdate,
|
|
123
129
|
} from './lastUpdateUtils';
|
|
130
|
+
|
|
131
|
+
export {normalizeTags, reportInlineTags} from './tags';
|
package/src/markdownLinks.ts
CHANGED
|
@@ -40,159 +40,40 @@ export type BrokenMarkdownLink<T extends ContentPaths> = {
|
|
|
40
40
|
link: string;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
43
|
+
export type SourceToPermalink = Map<
|
|
44
|
+
string, // Aliased source path: "@site/docs/content.mdx"
|
|
45
|
+
string // Permalink: "/docs/content"
|
|
46
|
+
>;
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
// Note this is historical logic extracted during a 2024 refactor
|
|
49
|
+
// The algo has been kept exactly as before for retro compatibility
|
|
50
|
+
// See also https://github.com/facebook/docusaurus/pull/10168
|
|
51
|
+
export function resolveMarkdownLinkPathname(
|
|
52
|
+
linkPathname: string,
|
|
53
|
+
context: {
|
|
54
|
+
sourceFilePath: string;
|
|
55
|
+
sourceToPermalink: SourceToPermalink;
|
|
56
|
+
contentPaths: ContentPaths;
|
|
57
|
+
siteDir: string;
|
|
58
|
+
},
|
|
59
|
+
): string | null {
|
|
60
|
+
const {sourceFilePath, sourceToPermalink, contentPaths, siteDir} = context;
|
|
61
|
+
const sourceDirsToTry: string[] = [];
|
|
62
|
+
// ./file.md and ../file.md are always relative to the current file
|
|
63
|
+
if (!linkPathname.startsWith('./') && !linkPathname.startsWith('../')) {
|
|
64
|
+
sourceDirsToTry.push(...getContentPathList(contentPaths), siteDir);
|
|
65
|
+
}
|
|
66
|
+
// /file.md is never relative to the source file path
|
|
67
|
+
if (!linkPathname.startsWith('/')) {
|
|
68
|
+
sourceDirsToTry.push(path.dirname(sourceFilePath));
|
|
53
69
|
}
|
|
54
|
-
return {
|
|
55
|
-
type: match.groups!.fence![0]! as '`' | '~',
|
|
56
|
-
definitelyOpen: !!match.groups!.rest!,
|
|
57
|
-
count: match.groups!.fence!.length,
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Takes a Markdown file and replaces relative file references with their URL
|
|
63
|
-
* counterparts, e.g. `[link](./intro.md)` => `[link](/docs/intro)`, preserving
|
|
64
|
-
* everything else.
|
|
65
|
-
*
|
|
66
|
-
* This method uses best effort to find a matching file. The file reference can
|
|
67
|
-
* be relative to the directory of the current file (most likely) or any of the
|
|
68
|
-
* content paths (so `/tutorials/intro.md` can be resolved as
|
|
69
|
-
* `<siteDir>/docs/tutorials/intro.md`). Links that contain the `http(s):` or
|
|
70
|
-
* `@site/` prefix will always be ignored.
|
|
71
|
-
*/
|
|
72
|
-
export function replaceMarkdownLinks<T extends ContentPaths>({
|
|
73
|
-
siteDir,
|
|
74
|
-
fileString,
|
|
75
|
-
filePath,
|
|
76
|
-
contentPaths,
|
|
77
|
-
sourceToPermalink,
|
|
78
|
-
}: {
|
|
79
|
-
/** Absolute path to the site directory, used to resolve aliased paths. */
|
|
80
|
-
siteDir: string;
|
|
81
|
-
/** The Markdown file content to be processed. */
|
|
82
|
-
fileString: string;
|
|
83
|
-
/** Absolute path to the current file containing `fileString`. */
|
|
84
|
-
filePath: string;
|
|
85
|
-
/** The content paths which the file reference may live in. */
|
|
86
|
-
contentPaths: T;
|
|
87
|
-
/**
|
|
88
|
-
* A map from source paths to their URLs. Source paths are `@site` aliased.
|
|
89
|
-
*/
|
|
90
|
-
sourceToPermalink: {[aliasedPath: string]: string};
|
|
91
|
-
}): {
|
|
92
|
-
/**
|
|
93
|
-
* The content with all Markdown file references replaced with their URLs.
|
|
94
|
-
* Unresolved links are left as-is.
|
|
95
|
-
*/
|
|
96
|
-
newContent: string;
|
|
97
|
-
/** The list of broken links, */
|
|
98
|
-
brokenMarkdownLinks: BrokenMarkdownLink<T>[];
|
|
99
|
-
} {
|
|
100
|
-
const brokenMarkdownLinks: BrokenMarkdownLink<T>[] = [];
|
|
101
|
-
|
|
102
|
-
// Replace internal markdown linking (except in fenced blocks).
|
|
103
|
-
let lastOpenCodeFence: CodeFence | null = null;
|
|
104
|
-
const lines = fileString.split('\n').map((line) => {
|
|
105
|
-
const codeFence = parseCodeFence(line);
|
|
106
|
-
if (codeFence) {
|
|
107
|
-
if (!lastOpenCodeFence) {
|
|
108
|
-
lastOpenCodeFence = codeFence;
|
|
109
|
-
} else if (
|
|
110
|
-
!codeFence.definitelyOpen &&
|
|
111
|
-
lastOpenCodeFence.type === codeFence.type &&
|
|
112
|
-
lastOpenCodeFence.count <= codeFence.count
|
|
113
|
-
) {
|
|
114
|
-
// All three conditions must be met in order for this to be considered
|
|
115
|
-
// a closing fence.
|
|
116
|
-
lastOpenCodeFence = null;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (lastOpenCodeFence) {
|
|
120
|
-
return line;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
let modifiedLine = line;
|
|
124
|
-
// Replace inline-style links or reference-style links e.g:
|
|
125
|
-
// This is [Document 1](doc1.md)
|
|
126
|
-
// [doc1]: doc1.md
|
|
127
|
-
const linkTitlePattern = '(?:\\s+(?:\'.*?\'|".*?"|\\(.*?\\)))?';
|
|
128
|
-
const linkSuffixPattern = '(?:\\?[^#>\\s]+)?(?:#[^>\\s]+)?';
|
|
129
|
-
const linkCapture = (forbidden: string) =>
|
|
130
|
-
`((?!https?://|@site/)[^${forbidden}#?]+)`;
|
|
131
|
-
const linkURLPattern = `(?:(?!<)${linkCapture(
|
|
132
|
-
'()\\s',
|
|
133
|
-
)}${linkSuffixPattern}|<${linkCapture('>')}${linkSuffixPattern}>)`;
|
|
134
|
-
const linkPattern = new RegExp(
|
|
135
|
-
`\\[(?:(?!\\]\\().)*\\]\\(\\s*${linkURLPattern}${linkTitlePattern}\\s*\\)|^\\s*\\[[^[\\]]*[^[\\]\\s][^[\\]]*\\]:\\s*${linkURLPattern}${linkTitlePattern}$`,
|
|
136
|
-
'dgm',
|
|
137
|
-
);
|
|
138
|
-
let mdMatch = linkPattern.exec(modifiedLine);
|
|
139
|
-
while (mdMatch !== null) {
|
|
140
|
-
// Replace it to correct html link.
|
|
141
|
-
const mdLink = mdMatch.slice(1, 5).find(Boolean)!;
|
|
142
|
-
const mdLinkRange = mdMatch.indices!.slice(1, 5).find(Boolean)!;
|
|
143
|
-
if (!/\.mdx?$/.test(mdLink)) {
|
|
144
|
-
mdMatch = linkPattern.exec(modifiedLine);
|
|
145
|
-
continue;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const sourcesToTry: string[] = [];
|
|
149
|
-
// ./file.md and ../file.md are always relative to the current file
|
|
150
|
-
if (!mdLink.startsWith('./') && !mdLink.startsWith('../')) {
|
|
151
|
-
sourcesToTry.push(...getContentPathList(contentPaths), siteDir);
|
|
152
|
-
}
|
|
153
|
-
// /file.md is always relative to the content path
|
|
154
|
-
if (!mdLink.startsWith('/')) {
|
|
155
|
-
sourcesToTry.push(path.dirname(filePath));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const aliasedSourceMatch = sourcesToTry
|
|
159
|
-
.map((p) => path.join(p, decodeURIComponent(mdLink)))
|
|
160
|
-
.map((source) => aliasedSitePath(source, siteDir))
|
|
161
|
-
.find((source) => sourceToPermalink[source]);
|
|
162
|
-
|
|
163
|
-
const permalink: string | undefined = aliasedSourceMatch
|
|
164
|
-
? sourceToPermalink[aliasedSourceMatch]
|
|
165
|
-
: undefined;
|
|
166
|
-
|
|
167
|
-
if (permalink) {
|
|
168
|
-
// MDX won't be happy if the permalink contains a space, we need to
|
|
169
|
-
// convert it to %20
|
|
170
|
-
const encodedPermalink = permalink
|
|
171
|
-
.split('/')
|
|
172
|
-
.map((part) => part.replace(/\s/g, '%20'))
|
|
173
|
-
.join('/');
|
|
174
|
-
modifiedLine = `${modifiedLine.slice(
|
|
175
|
-
0,
|
|
176
|
-
mdLinkRange[0],
|
|
177
|
-
)}${encodedPermalink}${modifiedLine.slice(mdLinkRange[1])}`;
|
|
178
|
-
// Adjust the lastIndex to avoid passing over the next link if the
|
|
179
|
-
// newly replaced URL is shorter.
|
|
180
|
-
linkPattern.lastIndex += encodedPermalink.length - mdLink.length;
|
|
181
|
-
} else {
|
|
182
|
-
const brokenMarkdownLink: BrokenMarkdownLink<T> = {
|
|
183
|
-
contentPaths,
|
|
184
|
-
filePath,
|
|
185
|
-
link: mdLink,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
brokenMarkdownLinks.push(brokenMarkdownLink);
|
|
189
|
-
}
|
|
190
|
-
mdMatch = linkPattern.exec(modifiedLine);
|
|
191
|
-
}
|
|
192
|
-
return modifiedLine;
|
|
193
|
-
});
|
|
194
70
|
|
|
195
|
-
const
|
|
71
|
+
const aliasedSourceMatch = sourceDirsToTry
|
|
72
|
+
.map((sourceDir) => path.join(sourceDir, decodeURIComponent(linkPathname)))
|
|
73
|
+
.map((source) => aliasedSitePath(source, siteDir))
|
|
74
|
+
.find((source) => sourceToPermalink.has(source));
|
|
196
75
|
|
|
197
|
-
return
|
|
76
|
+
return aliasedSourceMatch
|
|
77
|
+
? sourceToPermalink.get(aliasedSourceMatch) ?? null
|
|
78
|
+
: null;
|
|
198
79
|
}
|