@docusaurus/mdx-loader 3.8.1 → 3.9.0-canary-6406
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/processor.d.ts.map +1 -1
- package/lib/processor.js +7 -2
- package/lib/processor.js.map +1 -1
- package/lib/remark/resolveMarkdownLinks/index.d.ts +2 -0
- package/lib/remark/resolveMarkdownLinks/index.d.ts.map +1 -1
- package/lib/remark/resolveMarkdownLinks/index.js +35 -3
- package/lib/remark/resolveMarkdownLinks/index.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts +3 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +61 -23
- package/lib/remark/transformImage/index.js.map +1 -1
- package/lib/remark/transformLinks/index.d.ts +3 -1
- package/lib/remark/transformLinks/index.d.ts.map +1 -1
- package/lib/remark/transformLinks/index.js +56 -19
- package/lib/remark/transformLinks/index.js.map +1 -1
- package/lib/remark/unusedDirectives/index.d.ts.map +1 -1
- package/lib/remark/unusedDirectives/index.js +1 -7
- package/lib/remark/unusedDirectives/index.js.map +1 -1
- package/lib/remark/utils/index.d.ts +1 -0
- package/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +14 -0
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +7 -7
- package/src/processor.ts +15 -4
- package/src/remark/resolveMarkdownLinks/index.ts +50 -3
- package/src/remark/transformImage/index.ts +96 -40
- package/src/remark/transformLinks/index.ts +84 -32
- package/src/remark/unusedDirectives/index.ts +2 -10
- package/src/remark/utils/index.ts +14 -0
package/lib/processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAeH,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM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0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AAiKF,wBAAsB,uBAAuB,CAAC,UAAU,EAAE;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,CAG3B;AAGD,MAAM,MAAM,gBAAgB,GAAG;IAC7B,WAAW,EAAE,eAAe,CAAC;IAC7B,YAAY,EAAE,eAAe,CAAC;CAC/B,CAAC;AAMF,wBAAsB,gBAAgB,CAAC,EACrC,OAAO,GACR,EAAE;IACD,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAY5B;AAgBD,wBAAsB,YAAY,CAAC,EACjC,QAAQ,EACR,cAAc,EACd,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,OAAO,CAAC;CAClB,GAAG,OAAO,CAAC,eAAe,CAAC,CAW3B"}
|
package/lib/processor.js
CHANGED
|
@@ -49,7 +49,7 @@ async function createProcessorFactory() {
|
|
|
49
49
|
headings_1.default,
|
|
50
50
|
{ anchorsMaintainCase: options.markdownConfig.anchors.maintainCase },
|
|
51
51
|
],
|
|
52
|
-
emoji,
|
|
52
|
+
...(options.markdownConfig.emoji ? [emoji] : []),
|
|
53
53
|
toc_1.default,
|
|
54
54
|
];
|
|
55
55
|
}
|
|
@@ -71,13 +71,17 @@ async function createProcessorFactory() {
|
|
|
71
71
|
{
|
|
72
72
|
staticDirs: options.staticDirs,
|
|
73
73
|
siteDir: options.siteDir,
|
|
74
|
+
onBrokenMarkdownImages: options.markdownConfig.hooks.onBrokenMarkdownImages,
|
|
74
75
|
},
|
|
75
76
|
],
|
|
76
77
|
// TODO merge this with transformLinks?
|
|
77
78
|
options.resolveMarkdownLink
|
|
78
79
|
? [
|
|
79
80
|
resolveMarkdownLinks_1.default,
|
|
80
|
-
{
|
|
81
|
+
{
|
|
82
|
+
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
83
|
+
onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
84
|
+
},
|
|
81
85
|
]
|
|
82
86
|
: undefined,
|
|
83
87
|
[
|
|
@@ -85,6 +89,7 @@ async function createProcessorFactory() {
|
|
|
85
89
|
{
|
|
86
90
|
staticDirs: options.staticDirs,
|
|
87
91
|
siteDir: options.siteDir,
|
|
92
|
+
onBrokenMarkdownLinks: options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
88
93
|
},
|
|
89
94
|
],
|
|
90
95
|
gfm,
|
package/lib/processor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA2NH,0DAMC;AAYD,4CAgBC;AAgBD,oCAmBC;;AA9RD,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,iGAAiE;AACjE,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,yFAAgE;AAChE,oGAAoE;AACpE,qCAAmC;AA8CnC,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE,CAAC;QACtB,MAAM,MAAM,GACV,iBAAiB,KAAK,IAAI;YACxB,CAAC,CAAC,qBAAoB;YACtB,CAAC,CAAC,CAAC,qBAAoB,EAAE,iBAAiB,CAAC,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC;IAClB,CAAC;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,iDAAiD;AACjD,KAAK,UAAU,sBAAsB;IACnC,MAAM,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tE,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;QACxC,oBAAoB,EAAE,OAAO,CAAC,cAAc,CAAC,MAAM;KACpD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC;AAC5E,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Plugin } from 'unified';
|
|
8
8
|
import type { Root } from 'mdast';
|
|
9
|
+
import type { MarkdownConfig } from '@docusaurus/types';
|
|
9
10
|
type ResolveMarkdownLinkParams = {
|
|
10
11
|
/**
|
|
11
12
|
* Absolute path to the source file containing this Markdown link.
|
|
@@ -20,6 +21,7 @@ type ResolveMarkdownLinkParams = {
|
|
|
20
21
|
export type ResolveMarkdownLink = (params: ResolveMarkdownLinkParams) => string | null;
|
|
21
22
|
export interface PluginOptions {
|
|
22
23
|
resolveMarkdownLink: ResolveMarkdownLink;
|
|
24
|
+
onBrokenMarkdownLinks: MarkdownConfig['hooks']['onBrokenMarkdownLinks'];
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* A remark plugin to extract the h1 heading found in Markdown files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAmB,IAAI,EAAC,MAAM,OAAO,CAAC;AAClD,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,KAAK,yBAAyB,GAAG;IAC/B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,CAChC,MAAM,EAAE,yBAAyB,KAC9B,MAAM,GAAG,IAAI,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC5B,mBAAmB,EAAE,mBAAmB,CAAC;IACzC,qBAAqB,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,uBAAuB,CAAC,CAAC;CACzE;AA8CD;;;;GAIG;AAGH,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CAwCzC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -6,7 +6,28 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
9
10
|
const utils_1 = require("@docusaurus/utils");
|
|
11
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
12
|
+
const utils_2 = require("../utils");
|
|
13
|
+
function asFunction(onBrokenMarkdownLinks) {
|
|
14
|
+
if (typeof onBrokenMarkdownLinks === 'string') {
|
|
15
|
+
const extraHelp = onBrokenMarkdownLinks === 'throw'
|
|
16
|
+
? logger_1.default.interpolate `\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} option, or apply the code=${'pathname://'} protocol to the broken link URLs.`
|
|
17
|
+
: '';
|
|
18
|
+
return ({ sourceFilePath, url: linkUrl, node }) => {
|
|
19
|
+
const relativePath = (0, utils_1.toMessageRelativeFilePath)(sourceFilePath);
|
|
20
|
+
logger_1.default.report(onBrokenMarkdownLinks) `Markdown link with URL code=${linkUrl} in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)} couldn't be resolved.
|
|
21
|
+
Make sure it references a local Markdown file that exists within the current plugin.${extraHelp}`;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
return (params) => onBrokenMarkdownLinks({
|
|
26
|
+
...params,
|
|
27
|
+
sourceFilePath: (0, utils_1.toMessageRelativeFilePath)(params.sourceFilePath),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
10
31
|
const HAS_MARKDOWN_EXTENSION = /\.mdx?$/i;
|
|
11
32
|
function parseMarkdownLinkURLPath(link) {
|
|
12
33
|
const urlPath = (0, utils_1.parseLocalURLPath)(link);
|
|
@@ -26,8 +47,11 @@ function parseMarkdownLinkURLPath(link) {
|
|
|
26
47
|
* This is exposed as "data.contentTitle" to the processed vfile
|
|
27
48
|
* Also gives the ability to strip that content title (used for the blog plugin)
|
|
28
49
|
*/
|
|
50
|
+
// TODO merge this plugin with "transformLinks"
|
|
51
|
+
// in general we'd want to avoid traversing multiple times the same AST
|
|
29
52
|
const plugin = function plugin(options) {
|
|
30
53
|
const { resolveMarkdownLink } = options;
|
|
54
|
+
const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
|
|
31
55
|
return async (root, file) => {
|
|
32
56
|
const { visit } = await import('unist-util-visit');
|
|
33
57
|
visit(root, ['link', 'definition'], (node) => {
|
|
@@ -36,17 +60,25 @@ const plugin = function plugin(options) {
|
|
|
36
60
|
if (!linkURLPath) {
|
|
37
61
|
return;
|
|
38
62
|
}
|
|
63
|
+
const sourceFilePath = file.path;
|
|
39
64
|
const permalink = resolveMarkdownLink({
|
|
40
|
-
sourceFilePath
|
|
65
|
+
sourceFilePath,
|
|
41
66
|
linkPathname: linkURLPath.pathname,
|
|
42
67
|
});
|
|
43
68
|
if (permalink) {
|
|
44
69
|
// This reapplies the link ?qs#hash part to the resolved pathname
|
|
45
|
-
|
|
70
|
+
link.url = (0, utils_1.serializeURLPath)({
|
|
46
71
|
...linkURLPath,
|
|
47
72
|
pathname: permalink,
|
|
48
73
|
});
|
|
49
|
-
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
link.url =
|
|
77
|
+
onBrokenMarkdownLinks({
|
|
78
|
+
url: link.url,
|
|
79
|
+
sourceFilePath,
|
|
80
|
+
node: link,
|
|
81
|
+
}) ?? link.url;
|
|
50
82
|
}
|
|
51
83
|
});
|
|
52
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/resolveMarkdownLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6CAK2B;AAC3B,wEAAwC;AAExC,oCAAwD;AA6BxD,SAAS,UAAU,CACjB,qBAA6D;IAE7D,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,SAAS,GACb,qBAAqB,KAAK,OAAO;YAC/B,CAAC,CAAC,gBAAM,CAAC,WAAW,CAAA,wCAAwC,iDAAiD,8BAA8B,aAAa,oCAAoC;YAC5L,CAAC,CAAC,EAAE,CAAC;QACT,OAAO,CAAC,EAAC,cAAc,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAC,EAAE,EAAE;YAC9C,MAAM,YAAY,GAAG,IAAA,iCAAyB,EAAC,cAAc,CAAC,CAAC;YAC/D,gBAAM,CAAC,MAAM,CACX,qBAAqB,CACtB,CAAA,+BAA+B,OAAO,wBAAwB,YAAY,GAAG,IAAA,sCAA8B,EAC1G,IAAI,CACL;sFAC+E,SAAS,EAAE,CAAC;QAC9F,CAAC,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,EAAE,EAAE,CAChB,qBAAqB,CAAC;YACpB,GAAG,MAAM;YACT,cAAc,EAAE,IAAA,iCAAyB,EAAC,MAAM,CAAC,cAAc,CAAC;SACjE,CAAC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gBACjE,IAAI,CAAC,GAAG,GAAG,IAAA,wBAAgB,EAAC;oBAC1B,GAAG,WAAW;oBACd,QAAQ,EAAE,SAAS;iBACpB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,GAAG;oBACN,qBAAqB,CAAC;wBACpB,GAAG,EAAE,IAAI,CAAC,GAAG;wBACb,cAAc;wBACd,IAAI,EAAE,IAAI;qBACX,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;YACnB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Plugin } from 'unified';
|
|
8
8
|
import type { Root } from 'mdast';
|
|
9
|
-
type
|
|
9
|
+
import type { MarkdownConfig } from '@docusaurus/types';
|
|
10
|
+
export type PluginOptions = {
|
|
10
11
|
staticDirs: string[];
|
|
11
12
|
siteDir: string;
|
|
13
|
+
onBrokenMarkdownImages: MarkdownConfig['hooks']['onBrokenMarkdownImages'];
|
|
12
14
|
};
|
|
13
15
|
declare const plugin: Plugin<PluginOptions[], Root>;
|
|
14
16
|
export default plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqBH,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AAEjD,OAAO,KAAK,EAAQ,IAAI,EAAC,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,wBAAwB,CAAC,CAAC;CAC3E,CAAC;AA2MF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CA4BzC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -15,13 +15,35 @@ const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
|
15
15
|
const fromFile_1 = require("image-size/fromFile");
|
|
16
16
|
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
17
17
|
const utils_2 = require("../utils");
|
|
18
|
+
function asFunction(onBrokenMarkdownImages) {
|
|
19
|
+
if (typeof onBrokenMarkdownImages === 'string') {
|
|
20
|
+
const extraHelp = onBrokenMarkdownImages === 'throw'
|
|
21
|
+
? logger_1.default.interpolate `\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownImages'} option, or apply the code=${'pathname://'} protocol to the broken image URLs.`
|
|
22
|
+
: '';
|
|
23
|
+
return ({ sourceFilePath, url: imageUrl, node }) => {
|
|
24
|
+
const relativePath = (0, utils_1.toMessageRelativeFilePath)(sourceFilePath);
|
|
25
|
+
if (imageUrl) {
|
|
26
|
+
logger_1.default.report(onBrokenMarkdownImages) `Markdown image with URL code=${imageUrl} in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)} couldn't be resolved to an existing local image file.${extraHelp}`;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
logger_1.default.report(onBrokenMarkdownImages) `Markdown image with empty URL found in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)}.${extraHelp}`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return (params) => onBrokenMarkdownImages({
|
|
35
|
+
...params,
|
|
36
|
+
sourceFilePath: (0, utils_1.toMessageRelativeFilePath)(params.sourceFilePath),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
18
40
|
async function toImageRequireNode([node], imagePath, context) {
|
|
19
41
|
// MdxJsxTextElement => see https://github.com/facebook/docusaurus/pull/8288#discussion_r1125871405
|
|
20
42
|
const jsxNode = node;
|
|
21
43
|
const attributes = [];
|
|
22
44
|
let relativeImagePath = (0, utils_1.posixPath)(path_1.default.relative(path_1.default.dirname(context.filePath), imagePath));
|
|
23
45
|
relativeImagePath = `./${relativeImagePath}`;
|
|
24
|
-
const parsedUrl = (0, utils_1.parseURLOrPath)(node.url
|
|
46
|
+
const parsedUrl = (0, utils_1.parseURLOrPath)(node.url);
|
|
25
47
|
const hash = parsedUrl.hash ?? '';
|
|
26
48
|
const search = parsedUrl.search ?? '';
|
|
27
49
|
const requireString = `${context.inlineMarkdownImageFileLoader}${(0, utils_1.escapePath)(relativeImagePath) + search}`;
|
|
@@ -77,38 +99,42 @@ ${err.message}`;
|
|
|
77
99
|
children: [],
|
|
78
100
|
});
|
|
79
101
|
}
|
|
80
|
-
async function
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
async function getImageAbsolutePath(imagePath, { siteDir, filePath, staticDirs }) {
|
|
87
|
-
if (imagePath.startsWith('@site/')) {
|
|
88
|
-
const imageFilePath = path_1.default.join(siteDir, imagePath.replace('@site/', ''));
|
|
89
|
-
await ensureImageFileExist(imageFilePath, filePath);
|
|
102
|
+
async function getLocalImageAbsolutePath(originalImagePath, { siteDir, filePath, staticDirs }) {
|
|
103
|
+
if (originalImagePath.startsWith('@site/')) {
|
|
104
|
+
const imageFilePath = path_1.default.join(siteDir, originalImagePath.replace('@site/', ''));
|
|
105
|
+
if (!(await fs_extra_1.default.pathExists(imageFilePath))) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
90
108
|
return imageFilePath;
|
|
91
109
|
}
|
|
92
|
-
else if (path_1.default.isAbsolute(
|
|
110
|
+
else if (path_1.default.isAbsolute(originalImagePath)) {
|
|
93
111
|
// Absolute paths are expected to exist in the static folder.
|
|
94
|
-
const possiblePaths = staticDirs.map((dir) => path_1.default.join(dir,
|
|
112
|
+
const possiblePaths = staticDirs.map((dir) => path_1.default.join(dir, originalImagePath));
|
|
95
113
|
const imageFilePath = await (0, utils_1.findAsyncSequential)(possiblePaths, fs_extra_1.default.pathExists);
|
|
96
114
|
if (!imageFilePath) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
return imageFilePath;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// relative paths are resolved against the source file's folder
|
|
121
|
+
const imageFilePath = path_1.default.join(path_1.default.dirname(filePath), originalImagePath);
|
|
122
|
+
if (!(await fs_extra_1.default.pathExists(imageFilePath))) {
|
|
123
|
+
return null;
|
|
100
124
|
}
|
|
101
125
|
return imageFilePath;
|
|
102
126
|
}
|
|
103
|
-
// relative paths are resolved against the source file's folder
|
|
104
|
-
const imageFilePath = path_1.default.join(path_1.default.dirname(filePath), imagePath);
|
|
105
|
-
await ensureImageFileExist(imageFilePath, filePath);
|
|
106
|
-
return imageFilePath;
|
|
107
127
|
}
|
|
108
128
|
async function processImageNode(target, context) {
|
|
109
129
|
const [node] = target;
|
|
110
130
|
if (!node.url) {
|
|
111
|
-
|
|
131
|
+
node.url =
|
|
132
|
+
context.onBrokenMarkdownImages({
|
|
133
|
+
url: node.url,
|
|
134
|
+
sourceFilePath: context.filePath,
|
|
135
|
+
node,
|
|
136
|
+
}) ?? node.url;
|
|
137
|
+
return;
|
|
112
138
|
}
|
|
113
139
|
const parsedUrl = url_1.default.parse(node.url);
|
|
114
140
|
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
|
@@ -125,10 +151,21 @@ async function processImageNode(target, context) {
|
|
|
125
151
|
const decodedPathname = decodeURIComponent(parsedUrl.pathname);
|
|
126
152
|
// We try to convert image urls without protocol to images with require calls
|
|
127
153
|
// going through webpack ensures that image assets exist at build time
|
|
128
|
-
const
|
|
129
|
-
|
|
154
|
+
const localImagePath = await getLocalImageAbsolutePath(decodedPathname, context);
|
|
155
|
+
if (localImagePath === null) {
|
|
156
|
+
node.url =
|
|
157
|
+
context.onBrokenMarkdownImages({
|
|
158
|
+
url: node.url,
|
|
159
|
+
sourceFilePath: context.filePath,
|
|
160
|
+
node,
|
|
161
|
+
}) ?? node.url;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
await toImageRequireNode(target, localImagePath, context);
|
|
165
|
+
}
|
|
130
166
|
}
|
|
131
167
|
const plugin = function plugin(options) {
|
|
168
|
+
const onBrokenMarkdownImages = asFunction(options.onBrokenMarkdownImages);
|
|
132
169
|
return async (root, vfile) => {
|
|
133
170
|
const { visit } = await import('unist-util-visit');
|
|
134
171
|
const fileLoaderUtils = (0, utils_1.getFileLoaderUtils)(vfile.data.compilerName === 'server');
|
|
@@ -136,6 +173,7 @@ const plugin = function plugin(options) {
|
|
|
136
173
|
...options,
|
|
137
174
|
filePath: vfile.path,
|
|
138
175
|
inlineMarkdownImageFileLoader: fileLoaderUtils.loaders.inlineMarkdownImageFileLoader,
|
|
176
|
+
onBrokenMarkdownImages,
|
|
139
177
|
};
|
|
140
178
|
const promises = [];
|
|
141
179
|
visit(root, 'image', (node, index, parent) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAO2B;AAC3B,sEAAqC;AACrC,kDAAsD;AACtD,wEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformImage/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAO2B;AAC3B,sEAAqC;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QAAQ,GAAoB,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,MAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACnC,OAAO;YACT,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,MAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -6,9 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import type { Plugin } from 'unified';
|
|
8
8
|
import type { Root } from 'mdast';
|
|
9
|
-
type
|
|
9
|
+
import type { MarkdownConfig } from '@docusaurus/types';
|
|
10
|
+
export type PluginOptions = {
|
|
10
11
|
staticDirs: string[];
|
|
11
12
|
siteDir: string;
|
|
13
|
+
onBrokenMarkdownLinks: MarkdownConfig['hooks']['onBrokenMarkdownLinks'];
|
|
12
14
|
};
|
|
13
15
|
declare const plugin: Plugin<PluginOptions[], Root>;
|
|
14
16
|
export default plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH,OAAO,KAAK,EAAC,MAAM,EAAc,MAAM,SAAS,CAAC;AAGjD,OAAO,KAAK,EAAO,IAAI,EAAC,MAAM,OAAO,CAAC;AACtC,OAAO,KAAK,EACV,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAE3B,MAAM,MAAM,aAAa,GAAG;IAC1B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,qBAAqB,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC,uBAAuB,CAAC,CAAC;CACzE,CAAC;AAkNF,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,IAAI,CA6BzC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -12,7 +12,31 @@ const url_1 = tslib_1.__importDefault(require("url"));
|
|
|
12
12
|
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
|
|
13
13
|
const utils_1 = require("@docusaurus/utils");
|
|
14
14
|
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
15
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
15
16
|
const utils_2 = require("../utils");
|
|
17
|
+
function asFunction(onBrokenMarkdownLinks) {
|
|
18
|
+
if (typeof onBrokenMarkdownLinks === 'string') {
|
|
19
|
+
const extraHelp = onBrokenMarkdownLinks === 'throw'
|
|
20
|
+
? logger_1.default.interpolate `\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} option, or apply the code=${'pathname://'} protocol to the broken link URLs.`
|
|
21
|
+
: '';
|
|
22
|
+
return ({ sourceFilePath, url: linkUrl, node }) => {
|
|
23
|
+
const relativePath = (0, utils_1.toMessageRelativeFilePath)(sourceFilePath);
|
|
24
|
+
if (linkUrl) {
|
|
25
|
+
logger_1.default.report(onBrokenMarkdownLinks) `Markdown link with URL code=${linkUrl} in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)} couldn't be resolved.
|
|
26
|
+
Make sure it references a local Markdown file that exists within the current plugin.${extraHelp}`;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
logger_1.default.report(onBrokenMarkdownLinks) `Markdown link with empty URL found in source file path=${relativePath}${(0, utils_2.formatNodePositionExtraMessage)(node)}.${extraHelp}`;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return (params) => onBrokenMarkdownLinks({
|
|
35
|
+
...params,
|
|
36
|
+
sourceFilePath: (0, utils_1.toMessageRelativeFilePath)(params.sourceFilePath),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
16
40
|
/**
|
|
17
41
|
* Transforms the link node to a JSX `<a>` element with a `require()` call.
|
|
18
42
|
*/
|
|
@@ -82,19 +106,12 @@ async function toAssetRequireNode([node], assetPath, context) {
|
|
|
82
106
|
children,
|
|
83
107
|
});
|
|
84
108
|
}
|
|
85
|
-
async function
|
|
86
|
-
const assetExists = await fs_extra_1.default.pathExists(assetPath);
|
|
87
|
-
if (!assetExists) {
|
|
88
|
-
throw new Error(`Asset ${(0, utils_1.toMessageRelativeFilePath)(assetPath)} used in ${(0, utils_1.toMessageRelativeFilePath)(sourceFilePath)} not found.`);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
async function getAssetAbsolutePath(assetPath, { siteDir, filePath, staticDirs }) {
|
|
109
|
+
async function getLocalFileAbsolutePath(assetPath, { siteDir, filePath, staticDirs }) {
|
|
92
110
|
if (assetPath.startsWith('@site/')) {
|
|
93
111
|
const assetFilePath = path_1.default.join(siteDir, assetPath.replace('@site/', ''));
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return assetFilePath;
|
|
112
|
+
if (await fs_extra_1.default.pathExists(assetFilePath)) {
|
|
113
|
+
return assetFilePath;
|
|
114
|
+
}
|
|
98
115
|
}
|
|
99
116
|
else if (path_1.default.isAbsolute(assetPath)) {
|
|
100
117
|
const assetFilePath = await (0, utils_1.findAsyncSequential)(staticDirs.map((dir) => path_1.default.join(dir, assetPath)), fs_extra_1.default.pathExists);
|
|
@@ -113,11 +130,13 @@ async function getAssetAbsolutePath(assetPath, { siteDir, filePath, staticDirs }
|
|
|
113
130
|
async function processLinkNode(target, context) {
|
|
114
131
|
const [node] = target;
|
|
115
132
|
if (!node.url) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
133
|
+
node.url =
|
|
134
|
+
context.onBrokenMarkdownLinks({
|
|
135
|
+
url: node.url,
|
|
136
|
+
sourceFilePath: context.filePath,
|
|
137
|
+
node,
|
|
138
|
+
}) ?? node.url;
|
|
139
|
+
return;
|
|
121
140
|
}
|
|
122
141
|
const parsedUrl = url_1.default.parse(node.url);
|
|
123
142
|
if (parsedUrl.protocol || !parsedUrl.pathname) {
|
|
@@ -130,12 +149,29 @@ async function processLinkNode(target, context) {
|
|
|
130
149
|
if (!hasSiteAlias && !hasAssetLikeExtension) {
|
|
131
150
|
return;
|
|
132
151
|
}
|
|
133
|
-
const
|
|
134
|
-
if (
|
|
135
|
-
await toAssetRequireNode(target,
|
|
152
|
+
const localFilePath = await getLocalFileAbsolutePath(decodeURIComponent(parsedUrl.pathname), context);
|
|
153
|
+
if (localFilePath) {
|
|
154
|
+
await toAssetRequireNode(target, localFilePath, context);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
// The @site alias is the only way to believe that the user wants an asset.
|
|
158
|
+
if (hasSiteAlias) {
|
|
159
|
+
node.url =
|
|
160
|
+
context.onBrokenMarkdownLinks({
|
|
161
|
+
url: node.url,
|
|
162
|
+
sourceFilePath: context.filePath,
|
|
163
|
+
node,
|
|
164
|
+
}) ?? node.url;
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
// Even if the url has a dot, and it looks like a file extension
|
|
168
|
+
// it can be risky to throw and fail fast by default
|
|
169
|
+
// It's perfectly valid for a route path segment to look like a filename
|
|
170
|
+
}
|
|
136
171
|
}
|
|
137
172
|
}
|
|
138
173
|
const plugin = function plugin(options) {
|
|
174
|
+
const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
|
|
139
175
|
return async (root, vfile) => {
|
|
140
176
|
const { visit } = await import('unist-util-visit');
|
|
141
177
|
const fileLoaderUtils = (0, utils_1.getFileLoaderUtils)(vfile.data.compilerName === 'server');
|
|
@@ -143,6 +179,7 @@ const plugin = function plugin(options) {
|
|
|
143
179
|
...options,
|
|
144
180
|
filePath: vfile.path,
|
|
145
181
|
inlineMarkdownLinkFileLoader: fileLoaderUtils.loaders.inlineMarkdownLinkFileLoader,
|
|
182
|
+
onBrokenMarkdownLinks,
|
|
146
183
|
};
|
|
147
184
|
const promises = [];
|
|
148
185
|
visit(root, 'link', (node, index, parent) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAO2B;AAC3B,sEAAqC;AACrC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAO2B;AAC3B,sEAAqC;AACrC,wEAAwC;AACxC,oCAIkB;AA0BlB,SAAS,UAAU,CACjB,qBAA6D;IAE7D,IAAI,OAAO,qBAAqB,KAAK,QAAQ,EAAE,CAAC;QAC9C,MAAM,SAAS,GACb,qBAAqB,KAAK,OAAO;YAC/B,CAAC,CAAC,gBAAM,CAAC,WAAW,CAAA,wCAAwC,iDAAiD,8BAA8B,aAAa,oCAAoC;YAC5L,CAAC,CAAC,EAAE,CAAC;QAET,OAAO,CAAC,EAAC,cAAc,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAC,EAAE,EAAE;YAC9C,MAAM,YAAY,GAAG,IAAA,iCAAyB,EAAC,cAAc,CAAC,CAAC;YAC/D,IAAI,OAAO,EAAE,CAAC;gBACZ,gBAAM,CAAC,MAAM,CACX,qBAAqB,CACtB,CAAA,+BAA+B,OAA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IAEP,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAExE,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,MAAM,eAAe,GAAG,IAAA,0BAAkB,EACxC,KAAK,CAAC,IAAI,CAAC,YAAY,KAAK,QAAQ,CACrC,CAAC;QAEF,MAAM,OAAO,GAAY;YACvB,GAAG,OAAO;YACV,QAAQ,EAAE,KAAK,CAAC,IAAK;YACrB,4BAA4B,EAC1B,eAAe,CAAC,OAAO,CAAC,4BAA4B;YACtD,qBAAqB;SACtB,CAAC;QAEF,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC1C,IAAI,CAAC,MAAM,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACnC,OAAO;YACT,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;QACjE,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAyB,MAAM,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,KAAK,EAAyB,MAAM,EAAC,MAAM,SAAS,CAAC;AAqG5D,QAAA,MAAM,MAAM,EAAE,MAAM,CAAC,OAAO,EAAE,EAAE,IAAI,CAgCnC,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -30,15 +30,9 @@ function formatDirectiveName(directive) {
|
|
|
30
30
|
// To simplify we don't display the eventual label/props of directives
|
|
31
31
|
return `${prefix}${directive.name}`;
|
|
32
32
|
}
|
|
33
|
-
function formatDirectivePosition(directive) {
|
|
34
|
-
return directive.position?.start
|
|
35
|
-
? logger_1.default.interpolate `number=${directive.position.start.line}:number=${directive.position.start.column}`
|
|
36
|
-
: undefined;
|
|
37
|
-
}
|
|
38
33
|
function formatUnusedDirectiveMessage(directive) {
|
|
39
34
|
const name = formatDirectiveName(directive);
|
|
40
|
-
|
|
41
|
-
return `- ${name} ${position ? `(${position})` : ''}`;
|
|
35
|
+
return `- ${name}${(0, utils_2.formatNodePositionExtraMessage)(directive)}`;
|
|
42
36
|
}
|
|
43
37
|
function formatUnusedDirectivesMessage({ directives, filePath, }) {
|
|
44
38
|
const supportUrl = 'https://github.com/facebook/docusaurus/pull/9394';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,wDAAwB;AACxB,8DAA8B;AAC9B,wEAAwC;AACxC,6CAA4C;AAC5C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,wDAAwB;AACxB,8DAA8B;AAC9B,wEAAwC;AACxC,6CAA4C;AAC5C,oCAAuE;AAQvE,MAAM,cAAc,GAAoB;IACtC,oBAAoB;IACpB,eAAe;IACf,eAAe;CAChB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AE,CAAC;QAE1C,kCAAkC;QAClC,KAAK,CAAqB,IAAI,EAAE,cAAc,EAAE,CAAC,SAAqB,EAAE,EAAE;YACxE,kEAAkE;YAClE,sEAAsE;YACtE,IAAI,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;gBACjC,IAAI,qBAAqB,CAAC,SAAS,CAAC,EAAE,CAAC;oBACrC,oCAAoC,CAAC,SAAS,CAAC,CAAC;gBAClD,CAAC;qBAAM,CAAC;oBACN,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QAEH,wDAAwD;QACxD,uDAAuD;QACvD,2DAA2D;QAC3D,4EAA4E;QAC5E,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;YACxC,0BAA0B,CAAC;gBACzB,UAAU,EAAE,gBAAgB;gBAC5B,QAAQ,EAAE,IAAI,CAAC,IAAI;aACpB,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -14,4 +14,5 @@ import type { MdxJsxAttributeValueExpression } from 'mdast-util-mdx';
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function transformNode<NewNode extends Node>(node: Node, newNode: NewNode): NewNode;
|
|
16
16
|
export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
|
|
17
|
+
export declare function formatNodePositionExtraMessage(node: Node): string;
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,gBAAgB,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,IAAI,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACf,OAAO,CAUT;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC;AAUD,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAGjE"}
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.transformNode = transformNode;
|
|
10
10
|
exports.assetRequireAttributeValue = assetRequireAttributeValue;
|
|
11
|
+
exports.formatNodePositionExtraMessage = formatNodePositionExtraMessage;
|
|
12
|
+
const tslib_1 = require("tslib");
|
|
13
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
11
14
|
/**
|
|
12
15
|
* Util to transform one node type to another node type
|
|
13
16
|
* The input node is mutated in place
|
|
@@ -76,4 +79,15 @@ function assetRequireAttributeValue(requireString, hash) {
|
|
|
76
79
|
},
|
|
77
80
|
};
|
|
78
81
|
}
|
|
82
|
+
function formatNodePosition(node) {
|
|
83
|
+
return node.position?.start
|
|
84
|
+
? logger_1.default.interpolate `number=${node.position.start.line}:number=${node.position.start.column}`
|
|
85
|
+
: undefined;
|
|
86
|
+
}
|
|
87
|
+
// Returns " (line:column)" when position info is available
|
|
88
|
+
// The initial space is useful to append easily to any existing message
|
|
89
|
+
function formatNodePositionExtraMessage(node) {
|
|
90
|
+
const position = formatNodePosition(node);
|
|
91
|
+
return `${position ? ` (${position})` : ''}`;
|
|
92
|
+
}
|
|
79
93
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAYH,sCAaC;AAED,gEAqDC;AAUD,wEAGC;;AA3FD,wEAAwC;AAIxC;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,IAAU,EACV,OAAgB;IAEhB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAChC,kCAAkC;QAClC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QACnC,kCAAkC;QAClC,IAAI,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC,CAAC,CAAC;IACH,OAAO,IAAe,CAAC;AACzB,CAAC;AAED,SAAgB,0BAA0B,CACxC,aAAqB,EACrB,IAAY;IAEZ,OAAO;QACL,IAAI,EAAE,gCAAgC;QACtC,KAAK,EAAE,YAAY,aAAa,aAAa,IAAI,IAAI,OAAO,IAAI,GAAG,EAAE;QACrE,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE;oBACJ;wBACE,IAAI,EAAE,qBAAqB;wBAC3B,UAAU,EAAE;4BACV,IAAI,EAAE,kBAAkB;4BACxB,IAAI,EAAE;gCACJ,IAAI,EAAE,kBAAkB;gCACxB,MAAM,EAAE;oCACN,IAAI,EAAE,gBAAgB;oCACtB,MAAM,EAAE;wCACN,IAAI,EAAE,YAAY;wCAClB,IAAI,EAAE,SAAS;qCAChB;oCACD,SAAS,EAAE;wCACT;4CACE,IAAI,EAAE,SAAS;4CACf,KAAK,EAAE,aAAa;4CACpB,GAAG,EAAE,IAAI,aAAa,GAAG;yCAC1B;qCACF;oCACD,QAAQ,EAAE,KAAK;iCAChB;gCACD,QAAQ,EAAE;oCACR,IAAI,EAAE,YAAY;oCAClB,IAAI,EAAE,SAAS;iCAChB;gCACD,QAAQ,EAAE,KAAK;gCACf,QAAQ,EAAE,KAAK;6BAChB;4BACD,QAAQ,EAAE,GAAG;4BACb,KAAK,EAAE;gCACL,IAAI,EAAE,SAAS;gCACf,KAAK,EAAE,IAAI;gCACX,GAAG,EAAE,IAAI,IAAI,GAAG;6BACjB;yBACF;qBACF;iBACF;gBACD,UAAU,EAAE,QAAQ;gBACpB,QAAQ,EAAE,EAAE;aACb;SACF;KACF,CAAC;AACJ,CAAC;AAED,SAAS,kBAAkB,CAAC,IAAU;IACpC,OAAO,IAAI,CAAC,QAAQ,EAAE,KAAK;QACzB,CAAC,CAAC,gBAAM,CAAC,WAAW,CAAA,UAAU,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,WAAW,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE;QAC7F,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,2DAA2D;AAC3D,uEAAuE;AACvE,SAAgB,8BAA8B,CAAC,IAAU;IACvD,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;IAC1C,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0-canary-6406",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "3.
|
|
22
|
-
"@docusaurus/utils": "3.
|
|
23
|
-
"@docusaurus/utils-validation": "3.
|
|
21
|
+
"@docusaurus/logger": "3.9.0-canary-6406",
|
|
22
|
+
"@docusaurus/utils": "3.9.0-canary-6406",
|
|
23
|
+
"@docusaurus/utils-validation": "3.9.0-canary-6406",
|
|
24
24
|
"@mdx-js/mdx": "^3.0.0",
|
|
25
25
|
"@slorber/remark-comment": "^1.0.0",
|
|
26
26
|
"escape-html": "^1.0.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"webpack": "^5.88.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@docusaurus/types": "3.
|
|
47
|
+
"@docusaurus/types": "3.9.0-canary-6406",
|
|
48
48
|
"@types/escape-html": "^1.0.2",
|
|
49
49
|
"@types/mdast": "^4.0.2",
|
|
50
50
|
"@types/stringify-object": "^3.3.1",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
63
63
|
},
|
|
64
64
|
"engines": {
|
|
65
|
-
"node": ">=
|
|
65
|
+
"node": ">=20.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "796441f4f831278ffc57971fabcd4c730da9e9d7"
|
|
68
68
|
}
|
package/src/processor.ts
CHANGED
|
@@ -22,6 +22,9 @@ import type {WebpackCompilerName} from '@docusaurus/utils';
|
|
|
22
22
|
import type {MDXFrontMatter} from './frontMatter';
|
|
23
23
|
import type {Options} from './options';
|
|
24
24
|
import type {AdmonitionOptions} from './remark/admonitions';
|
|
25
|
+
import type {PluginOptions as ResolveMarkdownLinksOptions} from './remark/resolveMarkdownLinks';
|
|
26
|
+
import type {PluginOptions as TransformLinksOptions} from './remark/transformLinks';
|
|
27
|
+
import type {PluginOptions as TransformImageOptions} from './remark/transformImage';
|
|
25
28
|
import type {ProcessorOptions} from '@mdx-js/mdx';
|
|
26
29
|
|
|
27
30
|
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
@@ -92,7 +95,7 @@ async function createProcessorFactory() {
|
|
|
92
95
|
headings,
|
|
93
96
|
{anchorsMaintainCase: options.markdownConfig.anchors.maintainCase},
|
|
94
97
|
],
|
|
95
|
-
emoji,
|
|
98
|
+
...(options.markdownConfig.emoji ? [emoji] : []),
|
|
96
99
|
toc,
|
|
97
100
|
];
|
|
98
101
|
}
|
|
@@ -121,13 +124,19 @@ async function createProcessorFactory() {
|
|
|
121
124
|
{
|
|
122
125
|
staticDirs: options.staticDirs,
|
|
123
126
|
siteDir: options.siteDir,
|
|
124
|
-
|
|
127
|
+
onBrokenMarkdownImages:
|
|
128
|
+
options.markdownConfig.hooks.onBrokenMarkdownImages,
|
|
129
|
+
} satisfies TransformImageOptions,
|
|
125
130
|
],
|
|
126
131
|
// TODO merge this with transformLinks?
|
|
127
132
|
options.resolveMarkdownLink
|
|
128
133
|
? [
|
|
129
134
|
resolveMarkdownLinks,
|
|
130
|
-
{
|
|
135
|
+
{
|
|
136
|
+
resolveMarkdownLink: options.resolveMarkdownLink,
|
|
137
|
+
onBrokenMarkdownLinks:
|
|
138
|
+
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
139
|
+
} satisfies ResolveMarkdownLinksOptions,
|
|
131
140
|
]
|
|
132
141
|
: undefined,
|
|
133
142
|
[
|
|
@@ -135,7 +144,9 @@ async function createProcessorFactory() {
|
|
|
135
144
|
{
|
|
136
145
|
staticDirs: options.staticDirs,
|
|
137
146
|
siteDir: options.siteDir,
|
|
138
|
-
|
|
147
|
+
onBrokenMarkdownLinks:
|
|
148
|
+
options.markdownConfig.hooks.onBrokenMarkdownLinks,
|
|
149
|
+
} satisfies TransformLinksOptions,
|
|
139
150
|
],
|
|
140
151
|
gfm,
|
|
141
152
|
options.markdownConfig.mdx1Compat.comments ? comment : null,
|
|
@@ -8,11 +8,18 @@
|
|
|
8
8
|
import {
|
|
9
9
|
parseLocalURLPath,
|
|
10
10
|
serializeURLPath,
|
|
11
|
+
toMessageRelativeFilePath,
|
|
11
12
|
type URLPath,
|
|
12
13
|
} from '@docusaurus/utils';
|
|
14
|
+
import logger from '@docusaurus/logger';
|
|
13
15
|
|
|
16
|
+
import {formatNodePositionExtraMessage} from '../utils';
|
|
14
17
|
import type {Plugin, Transformer} from 'unified';
|
|
15
18
|
import type {Definition, Link, Root} from 'mdast';
|
|
19
|
+
import type {
|
|
20
|
+
MarkdownConfig,
|
|
21
|
+
OnBrokenMarkdownLinksFunction,
|
|
22
|
+
} from '@docusaurus/types';
|
|
16
23
|
|
|
17
24
|
type ResolveMarkdownLinkParams = {
|
|
18
25
|
/**
|
|
@@ -32,6 +39,33 @@ export type ResolveMarkdownLink = (
|
|
|
32
39
|
|
|
33
40
|
export interface PluginOptions {
|
|
34
41
|
resolveMarkdownLink: ResolveMarkdownLink;
|
|
42
|
+
onBrokenMarkdownLinks: MarkdownConfig['hooks']['onBrokenMarkdownLinks'];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function asFunction(
|
|
46
|
+
onBrokenMarkdownLinks: PluginOptions['onBrokenMarkdownLinks'],
|
|
47
|
+
): OnBrokenMarkdownLinksFunction {
|
|
48
|
+
if (typeof onBrokenMarkdownLinks === 'string') {
|
|
49
|
+
const extraHelp =
|
|
50
|
+
onBrokenMarkdownLinks === 'throw'
|
|
51
|
+
? logger.interpolate`\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} option, or apply the code=${'pathname://'} protocol to the broken link URLs.`
|
|
52
|
+
: '';
|
|
53
|
+
return ({sourceFilePath, url: linkUrl, node}) => {
|
|
54
|
+
const relativePath = toMessageRelativeFilePath(sourceFilePath);
|
|
55
|
+
logger.report(
|
|
56
|
+
onBrokenMarkdownLinks,
|
|
57
|
+
)`Markdown link with URL code=${linkUrl} in source file path=${relativePath}${formatNodePositionExtraMessage(
|
|
58
|
+
node,
|
|
59
|
+
)} couldn't be resolved.
|
|
60
|
+
Make sure it references a local Markdown file that exists within the current plugin.${extraHelp}`;
|
|
61
|
+
};
|
|
62
|
+
} else {
|
|
63
|
+
return (params) =>
|
|
64
|
+
onBrokenMarkdownLinks({
|
|
65
|
+
...params,
|
|
66
|
+
sourceFilePath: toMessageRelativeFilePath(params.sourceFilePath),
|
|
67
|
+
});
|
|
68
|
+
}
|
|
35
69
|
}
|
|
36
70
|
|
|
37
71
|
const HAS_MARKDOWN_EXTENSION = /\.mdx?$/i;
|
|
@@ -57,10 +91,15 @@ function parseMarkdownLinkURLPath(link: string): URLPath | null {
|
|
|
57
91
|
* This is exposed as "data.contentTitle" to the processed vfile
|
|
58
92
|
* Also gives the ability to strip that content title (used for the blog plugin)
|
|
59
93
|
*/
|
|
94
|
+
// TODO merge this plugin with "transformLinks"
|
|
95
|
+
// in general we'd want to avoid traversing multiple times the same AST
|
|
60
96
|
const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
61
97
|
options,
|
|
62
98
|
): Transformer<Root> {
|
|
63
99
|
const {resolveMarkdownLink} = options;
|
|
100
|
+
|
|
101
|
+
const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
|
|
102
|
+
|
|
64
103
|
return async (root, file) => {
|
|
65
104
|
const {visit} = await import('unist-util-visit');
|
|
66
105
|
|
|
@@ -71,18 +110,26 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
71
110
|
return;
|
|
72
111
|
}
|
|
73
112
|
|
|
113
|
+
const sourceFilePath = file.path;
|
|
114
|
+
|
|
74
115
|
const permalink = resolveMarkdownLink({
|
|
75
|
-
sourceFilePath
|
|
116
|
+
sourceFilePath,
|
|
76
117
|
linkPathname: linkURLPath.pathname,
|
|
77
118
|
});
|
|
78
119
|
|
|
79
120
|
if (permalink) {
|
|
80
121
|
// This reapplies the link ?qs#hash part to the resolved pathname
|
|
81
|
-
|
|
122
|
+
link.url = serializeURLPath({
|
|
82
123
|
...linkURLPath,
|
|
83
124
|
pathname: permalink,
|
|
84
125
|
});
|
|
85
|
-
|
|
126
|
+
} else {
|
|
127
|
+
link.url =
|
|
128
|
+
onBrokenMarkdownLinks({
|
|
129
|
+
url: link.url,
|
|
130
|
+
sourceFilePath,
|
|
131
|
+
node: link,
|
|
132
|
+
}) ?? link.url;
|
|
86
133
|
}
|
|
87
134
|
});
|
|
88
135
|
};
|
|
@@ -19,22 +19,67 @@ import {
|
|
|
19
19
|
import escapeHtml from 'escape-html';
|
|
20
20
|
import {imageSizeFromFile} from 'image-size/fromFile';
|
|
21
21
|
import logger from '@docusaurus/logger';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
assetRequireAttributeValue,
|
|
24
|
+
formatNodePositionExtraMessage,
|
|
25
|
+
transformNode,
|
|
26
|
+
} from '../utils';
|
|
23
27
|
import type {Plugin, Transformer} from 'unified';
|
|
24
28
|
import type {MdxJsxTextElement} from 'mdast-util-mdx';
|
|
25
29
|
import type {Image, Root} from 'mdast';
|
|
26
30
|
import type {Parent} from 'unist';
|
|
31
|
+
import type {
|
|
32
|
+
MarkdownConfig,
|
|
33
|
+
OnBrokenMarkdownImagesFunction,
|
|
34
|
+
} from '@docusaurus/types';
|
|
27
35
|
|
|
28
|
-
type PluginOptions = {
|
|
36
|
+
export type PluginOptions = {
|
|
29
37
|
staticDirs: string[];
|
|
30
38
|
siteDir: string;
|
|
39
|
+
onBrokenMarkdownImages: MarkdownConfig['hooks']['onBrokenMarkdownImages'];
|
|
31
40
|
};
|
|
32
41
|
|
|
33
|
-
type Context =
|
|
42
|
+
type Context = {
|
|
43
|
+
staticDirs: PluginOptions['staticDirs'];
|
|
44
|
+
siteDir: PluginOptions['siteDir'];
|
|
45
|
+
onBrokenMarkdownImages: OnBrokenMarkdownImagesFunction;
|
|
34
46
|
filePath: string;
|
|
35
47
|
inlineMarkdownImageFileLoader: string;
|
|
36
48
|
};
|
|
37
49
|
|
|
50
|
+
function asFunction(
|
|
51
|
+
onBrokenMarkdownImages: PluginOptions['onBrokenMarkdownImages'],
|
|
52
|
+
): OnBrokenMarkdownImagesFunction {
|
|
53
|
+
if (typeof onBrokenMarkdownImages === 'string') {
|
|
54
|
+
const extraHelp =
|
|
55
|
+
onBrokenMarkdownImages === 'throw'
|
|
56
|
+
? logger.interpolate`\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownImages'} option, or apply the code=${'pathname://'} protocol to the broken image URLs.`
|
|
57
|
+
: '';
|
|
58
|
+
return ({sourceFilePath, url: imageUrl, node}) => {
|
|
59
|
+
const relativePath = toMessageRelativeFilePath(sourceFilePath);
|
|
60
|
+
if (imageUrl) {
|
|
61
|
+
logger.report(
|
|
62
|
+
onBrokenMarkdownImages,
|
|
63
|
+
)`Markdown image with URL code=${imageUrl} in source file path=${relativePath}${formatNodePositionExtraMessage(
|
|
64
|
+
node,
|
|
65
|
+
)} couldn't be resolved to an existing local image file.${extraHelp}`;
|
|
66
|
+
} else {
|
|
67
|
+
logger.report(
|
|
68
|
+
onBrokenMarkdownImages,
|
|
69
|
+
)`Markdown image with empty URL found in source file path=${relativePath}${formatNodePositionExtraMessage(
|
|
70
|
+
node,
|
|
71
|
+
)}.${extraHelp}`;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
} else {
|
|
75
|
+
return (params) =>
|
|
76
|
+
onBrokenMarkdownImages({
|
|
77
|
+
...params,
|
|
78
|
+
sourceFilePath: toMessageRelativeFilePath(params.sourceFilePath),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
38
83
|
type Target = [node: Image, index: number, parent: Parent];
|
|
39
84
|
|
|
40
85
|
async function toImageRequireNode(
|
|
@@ -51,7 +96,7 @@ async function toImageRequireNode(
|
|
|
51
96
|
);
|
|
52
97
|
relativeImagePath = `./${relativeImagePath}`;
|
|
53
98
|
|
|
54
|
-
const parsedUrl = parseURLOrPath(node.url
|
|
99
|
+
const parsedUrl = parseURLOrPath(node.url);
|
|
55
100
|
const hash = parsedUrl.hash ?? '';
|
|
56
101
|
const search = parsedUrl.search ?? '';
|
|
57
102
|
const requireString = `${context.inlineMarkdownImageFileLoader}${
|
|
@@ -113,57 +158,53 @@ ${(err as Error).message}`;
|
|
|
113
158
|
});
|
|
114
159
|
}
|
|
115
160
|
|
|
116
|
-
async function
|
|
117
|
-
|
|
118
|
-
if (!imageExists) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Image ${toMessageRelativeFilePath(
|
|
121
|
-
imagePath,
|
|
122
|
-
)} used in ${toMessageRelativeFilePath(sourceFilePath)} not found.`,
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function getImageAbsolutePath(
|
|
128
|
-
imagePath: string,
|
|
161
|
+
async function getLocalImageAbsolutePath(
|
|
162
|
+
originalImagePath: string,
|
|
129
163
|
{siteDir, filePath, staticDirs}: Context,
|
|
130
164
|
) {
|
|
131
|
-
if (
|
|
132
|
-
const imageFilePath = path.join(
|
|
133
|
-
|
|
165
|
+
if (originalImagePath.startsWith('@site/')) {
|
|
166
|
+
const imageFilePath = path.join(
|
|
167
|
+
siteDir,
|
|
168
|
+
originalImagePath.replace('@site/', ''),
|
|
169
|
+
);
|
|
170
|
+
if (!(await fs.pathExists(imageFilePath))) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
134
173
|
return imageFilePath;
|
|
135
|
-
} else if (path.isAbsolute(
|
|
174
|
+
} else if (path.isAbsolute(originalImagePath)) {
|
|
136
175
|
// Absolute paths are expected to exist in the static folder.
|
|
137
|
-
const possiblePaths = staticDirs.map((dir) =>
|
|
176
|
+
const possiblePaths = staticDirs.map((dir) =>
|
|
177
|
+
path.join(dir, originalImagePath),
|
|
178
|
+
);
|
|
138
179
|
const imageFilePath = await findAsyncSequential(
|
|
139
180
|
possiblePaths,
|
|
140
181
|
fs.pathExists,
|
|
141
182
|
);
|
|
142
183
|
if (!imageFilePath) {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
return imageFilePath;
|
|
187
|
+
} else {
|
|
188
|
+
// relative paths are resolved against the source file's folder
|
|
189
|
+
const imageFilePath = path.join(path.dirname(filePath), originalImagePath);
|
|
190
|
+
if (!(await fs.pathExists(imageFilePath))) {
|
|
191
|
+
return null;
|
|
150
192
|
}
|
|
151
193
|
return imageFilePath;
|
|
152
194
|
}
|
|
153
|
-
// relative paths are resolved against the source file's folder
|
|
154
|
-
const imageFilePath = path.join(path.dirname(filePath), imagePath);
|
|
155
|
-
await ensureImageFileExist(imageFilePath, filePath);
|
|
156
|
-
return imageFilePath;
|
|
157
195
|
}
|
|
158
196
|
|
|
159
197
|
async function processImageNode(target: Target, context: Context) {
|
|
160
198
|
const [node] = target;
|
|
199
|
+
|
|
161
200
|
if (!node.url) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
201
|
+
node.url =
|
|
202
|
+
context.onBrokenMarkdownImages({
|
|
203
|
+
url: node.url,
|
|
204
|
+
sourceFilePath: context.filePath,
|
|
205
|
+
node,
|
|
206
|
+
}) ?? node.url;
|
|
207
|
+
return;
|
|
167
208
|
}
|
|
168
209
|
|
|
169
210
|
const parsedUrl = url.parse(node.url);
|
|
@@ -183,13 +224,27 @@ async function processImageNode(target: Target, context: Context) {
|
|
|
183
224
|
|
|
184
225
|
// We try to convert image urls without protocol to images with require calls
|
|
185
226
|
// going through webpack ensures that image assets exist at build time
|
|
186
|
-
const
|
|
187
|
-
|
|
227
|
+
const localImagePath = await getLocalImageAbsolutePath(
|
|
228
|
+
decodedPathname,
|
|
229
|
+
context,
|
|
230
|
+
);
|
|
231
|
+
if (localImagePath === null) {
|
|
232
|
+
node.url =
|
|
233
|
+
context.onBrokenMarkdownImages({
|
|
234
|
+
url: node.url,
|
|
235
|
+
sourceFilePath: context.filePath,
|
|
236
|
+
node,
|
|
237
|
+
}) ?? node.url;
|
|
238
|
+
} else {
|
|
239
|
+
await toImageRequireNode(target, localImagePath, context);
|
|
240
|
+
}
|
|
188
241
|
}
|
|
189
242
|
|
|
190
243
|
const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
191
244
|
options,
|
|
192
245
|
): Transformer<Root> {
|
|
246
|
+
const onBrokenMarkdownImages = asFunction(options.onBrokenMarkdownImages);
|
|
247
|
+
|
|
193
248
|
return async (root, vfile) => {
|
|
194
249
|
const {visit} = await import('unist-util-visit');
|
|
195
250
|
|
|
@@ -201,6 +256,7 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
201
256
|
filePath: vfile.path!,
|
|
202
257
|
inlineMarkdownImageFileLoader:
|
|
203
258
|
fileLoaderUtils.loaders.inlineMarkdownImageFileLoader,
|
|
259
|
+
onBrokenMarkdownImages,
|
|
204
260
|
};
|
|
205
261
|
|
|
206
262
|
const promises: Promise<void>[] = [];
|
|
@@ -17,24 +17,72 @@ import {
|
|
|
17
17
|
parseURLOrPath,
|
|
18
18
|
} from '@docusaurus/utils';
|
|
19
19
|
import escapeHtml from 'escape-html';
|
|
20
|
-
import
|
|
20
|
+
import logger from '@docusaurus/logger';
|
|
21
|
+
import {
|
|
22
|
+
assetRequireAttributeValue,
|
|
23
|
+
formatNodePositionExtraMessage,
|
|
24
|
+
transformNode,
|
|
25
|
+
} from '../utils';
|
|
21
26
|
import type {Plugin, Transformer} from 'unified';
|
|
22
27
|
import type {MdxJsxTextElement} from 'mdast-util-mdx';
|
|
23
28
|
import type {Parent} from 'unist';
|
|
24
|
-
import type {Link,
|
|
29
|
+
import type {Link, Root} from 'mdast';
|
|
30
|
+
import type {
|
|
31
|
+
MarkdownConfig,
|
|
32
|
+
OnBrokenMarkdownLinksFunction,
|
|
33
|
+
} from '@docusaurus/types';
|
|
25
34
|
|
|
26
|
-
type PluginOptions = {
|
|
35
|
+
export type PluginOptions = {
|
|
27
36
|
staticDirs: string[];
|
|
28
37
|
siteDir: string;
|
|
38
|
+
onBrokenMarkdownLinks: MarkdownConfig['hooks']['onBrokenMarkdownLinks'];
|
|
29
39
|
};
|
|
30
40
|
|
|
31
41
|
type Context = PluginOptions & {
|
|
42
|
+
staticDirs: string[];
|
|
43
|
+
siteDir: string;
|
|
44
|
+
onBrokenMarkdownLinks: OnBrokenMarkdownLinksFunction;
|
|
32
45
|
filePath: string;
|
|
33
46
|
inlineMarkdownLinkFileLoader: string;
|
|
34
47
|
};
|
|
35
48
|
|
|
36
49
|
type Target = [node: Link, index: number, parent: Parent];
|
|
37
50
|
|
|
51
|
+
function asFunction(
|
|
52
|
+
onBrokenMarkdownLinks: PluginOptions['onBrokenMarkdownLinks'],
|
|
53
|
+
): OnBrokenMarkdownLinksFunction {
|
|
54
|
+
if (typeof onBrokenMarkdownLinks === 'string') {
|
|
55
|
+
const extraHelp =
|
|
56
|
+
onBrokenMarkdownLinks === 'throw'
|
|
57
|
+
? logger.interpolate`\nTo ignore this error, use the code=${'siteConfig.markdown.hooks.onBrokenMarkdownLinks'} option, or apply the code=${'pathname://'} protocol to the broken link URLs.`
|
|
58
|
+
: '';
|
|
59
|
+
|
|
60
|
+
return ({sourceFilePath, url: linkUrl, node}) => {
|
|
61
|
+
const relativePath = toMessageRelativeFilePath(sourceFilePath);
|
|
62
|
+
if (linkUrl) {
|
|
63
|
+
logger.report(
|
|
64
|
+
onBrokenMarkdownLinks,
|
|
65
|
+
)`Markdown link with URL code=${linkUrl} in source file path=${relativePath}${formatNodePositionExtraMessage(
|
|
66
|
+
node,
|
|
67
|
+
)} couldn't be resolved.
|
|
68
|
+
Make sure it references a local Markdown file that exists within the current plugin.${extraHelp}`;
|
|
69
|
+
} else {
|
|
70
|
+
logger.report(
|
|
71
|
+
onBrokenMarkdownLinks,
|
|
72
|
+
)`Markdown link with empty URL found in source file path=${relativePath}${formatNodePositionExtraMessage(
|
|
73
|
+
node,
|
|
74
|
+
)}.${extraHelp}`;
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
} else {
|
|
78
|
+
return (params) =>
|
|
79
|
+
onBrokenMarkdownLinks({
|
|
80
|
+
...params,
|
|
81
|
+
sourceFilePath: toMessageRelativeFilePath(params.sourceFilePath),
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
38
86
|
/**
|
|
39
87
|
* Transforms the link node to a JSX `<a>` element with a `require()` call.
|
|
40
88
|
*/
|
|
@@ -123,27 +171,15 @@ async function toAssetRequireNode(
|
|
|
123
171
|
});
|
|
124
172
|
}
|
|
125
173
|
|
|
126
|
-
async function
|
|
127
|
-
const assetExists = await fs.pathExists(assetPath);
|
|
128
|
-
if (!assetExists) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`Asset ${toMessageRelativeFilePath(
|
|
131
|
-
assetPath,
|
|
132
|
-
)} used in ${toMessageRelativeFilePath(sourceFilePath)} not found.`,
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
async function getAssetAbsolutePath(
|
|
174
|
+
async function getLocalFileAbsolutePath(
|
|
138
175
|
assetPath: string,
|
|
139
176
|
{siteDir, filePath, staticDirs}: Context,
|
|
140
177
|
) {
|
|
141
178
|
if (assetPath.startsWith('@site/')) {
|
|
142
179
|
const assetFilePath = path.join(siteDir, assetPath.replace('@site/', ''));
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return assetFilePath;
|
|
180
|
+
if (await fs.pathExists(assetFilePath)) {
|
|
181
|
+
return assetFilePath;
|
|
182
|
+
}
|
|
147
183
|
} else if (path.isAbsolute(assetPath)) {
|
|
148
184
|
const assetFilePath = await findAsyncSequential(
|
|
149
185
|
staticDirs.map((dir) => path.join(dir, assetPath)),
|
|
@@ -164,16 +200,13 @@ async function getAssetAbsolutePath(
|
|
|
164
200
|
async function processLinkNode(target: Target, context: Context) {
|
|
165
201
|
const [node] = target;
|
|
166
202
|
if (!node.url) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
context.filePath,
|
|
175
|
-
)}" file (title: ${title}, line: ${line}).`,
|
|
176
|
-
);
|
|
203
|
+
node.url =
|
|
204
|
+
context.onBrokenMarkdownLinks({
|
|
205
|
+
url: node.url,
|
|
206
|
+
sourceFilePath: context.filePath,
|
|
207
|
+
node,
|
|
208
|
+
}) ?? node.url;
|
|
209
|
+
return;
|
|
177
210
|
}
|
|
178
211
|
|
|
179
212
|
const parsedUrl = url.parse(node.url);
|
|
@@ -189,29 +222,48 @@ async function processLinkNode(target: Target, context: Context) {
|
|
|
189
222
|
return;
|
|
190
223
|
}
|
|
191
224
|
|
|
192
|
-
const
|
|
225
|
+
const localFilePath = await getLocalFileAbsolutePath(
|
|
193
226
|
decodeURIComponent(parsedUrl.pathname),
|
|
194
227
|
context,
|
|
195
228
|
);
|
|
196
|
-
|
|
197
|
-
|
|
229
|
+
|
|
230
|
+
if (localFilePath) {
|
|
231
|
+
await toAssetRequireNode(target, localFilePath, context);
|
|
232
|
+
} else {
|
|
233
|
+
// The @site alias is the only way to believe that the user wants an asset.
|
|
234
|
+
if (hasSiteAlias) {
|
|
235
|
+
node.url =
|
|
236
|
+
context.onBrokenMarkdownLinks({
|
|
237
|
+
url: node.url,
|
|
238
|
+
sourceFilePath: context.filePath,
|
|
239
|
+
node,
|
|
240
|
+
}) ?? node.url;
|
|
241
|
+
} else {
|
|
242
|
+
// Even if the url has a dot, and it looks like a file extension
|
|
243
|
+
// it can be risky to throw and fail fast by default
|
|
244
|
+
// It's perfectly valid for a route path segment to look like a filename
|
|
245
|
+
}
|
|
198
246
|
}
|
|
199
247
|
}
|
|
200
248
|
|
|
201
249
|
const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
202
250
|
options,
|
|
203
251
|
): Transformer<Root> {
|
|
252
|
+
const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
|
|
253
|
+
|
|
204
254
|
return async (root, vfile) => {
|
|
205
255
|
const {visit} = await import('unist-util-visit');
|
|
206
256
|
|
|
207
257
|
const fileLoaderUtils = getFileLoaderUtils(
|
|
208
258
|
vfile.data.compilerName === 'server',
|
|
209
259
|
);
|
|
260
|
+
|
|
210
261
|
const context: Context = {
|
|
211
262
|
...options,
|
|
212
263
|
filePath: vfile.path!,
|
|
213
264
|
inlineMarkdownLinkFileLoader:
|
|
214
265
|
fileLoaderUtils.loaders.inlineMarkdownLinkFileLoader,
|
|
266
|
+
onBrokenMarkdownLinks,
|
|
215
267
|
};
|
|
216
268
|
|
|
217
269
|
const promises: Promise<void>[] = [];
|
|
@@ -8,7 +8,7 @@ import path from 'path';
|
|
|
8
8
|
import process from 'process';
|
|
9
9
|
import logger from '@docusaurus/logger';
|
|
10
10
|
import {posixPath} from '@docusaurus/utils';
|
|
11
|
-
import {transformNode} from '../utils';
|
|
11
|
+
import {formatNodePositionExtraMessage, transformNode} from '../utils';
|
|
12
12
|
import type {Root} from 'mdast';
|
|
13
13
|
import type {Parent} from 'unist';
|
|
14
14
|
import type {Transformer, Processor, Plugin} from 'unified';
|
|
@@ -39,17 +39,9 @@ function formatDirectiveName(directive: Directives) {
|
|
|
39
39
|
return `${prefix}${directive.name}`;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
function formatDirectivePosition(directive: Directives): string | undefined {
|
|
43
|
-
return directive.position?.start
|
|
44
|
-
? logger.interpolate`number=${directive.position.start.line}:number=${directive.position.start.column}`
|
|
45
|
-
: undefined;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
42
|
function formatUnusedDirectiveMessage(directive: Directives) {
|
|
49
43
|
const name = formatDirectiveName(directive);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return `- ${name} ${position ? `(${position})` : ''}`;
|
|
44
|
+
return `- ${name}${formatNodePositionExtraMessage(directive)}`;
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
function formatUnusedDirectivesMessage({
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import logger from '@docusaurus/logger';
|
|
8
9
|
import type {Node} from 'unist';
|
|
9
10
|
import type {MdxJsxAttributeValueExpression} from 'mdast-util-mdx';
|
|
10
11
|
|
|
@@ -83,3 +84,16 @@ export function assetRequireAttributeValue(
|
|
|
83
84
|
},
|
|
84
85
|
};
|
|
85
86
|
}
|
|
87
|
+
|
|
88
|
+
function formatNodePosition(node: Node): string | undefined {
|
|
89
|
+
return node.position?.start
|
|
90
|
+
? logger.interpolate`number=${node.position.start.line}:number=${node.position.start.column}`
|
|
91
|
+
: undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Returns " (line:column)" when position info is available
|
|
95
|
+
// The initial space is useful to append easily to any existing message
|
|
96
|
+
export function formatNodePositionExtraMessage(node: Node): string {
|
|
97
|
+
const position = formatNodePosition(node);
|
|
98
|
+
return `${position ? ` (${position})` : ''}`;
|
|
99
|
+
}
|