@docusaurus/mdx-loader 3.0.0-rc.0 → 3.0.0-rc.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/loader.d.ts.map +1 -1
- package/lib/loader.js +2 -0
- package/lib/loader.js.map +1 -1
- package/lib/processor.d.ts +3 -1
- package/lib/processor.d.ts.map +1 -1
- package/lib/processor.js +10 -11
- package/lib/processor.js.map +1 -1
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +5 -10
- package/lib/remark/admonitions/index.js.map +1 -1
- package/lib/remark/contentTitle/index.d.ts.map +1 -1
- package/lib/remark/contentTitle/index.js +5 -5
- package/lib/remark/contentTitle/index.js.map +1 -1
- package/lib/remark/details/index.d.ts.map +1 -1
- package/lib/remark/details/index.js +3 -4
- package/lib/remark/details/index.js.map +1 -1
- package/lib/remark/head/index.d.ts.map +1 -1
- package/lib/remark/head/index.js +3 -4
- package/lib/remark/head/index.js.map +1 -1
- package/lib/remark/headings/index.d.ts.map +1 -1
- package/lib/remark/headings/index.js +2 -3
- package/lib/remark/headings/index.js.map +1 -1
- package/lib/remark/mdx1Compat/codeCompatPlugin.d.ts.map +1 -1
- package/lib/remark/mdx1Compat/codeCompatPlugin.js +4 -9
- package/lib/remark/mdx1Compat/codeCompatPlugin.js.map +1 -1
- package/lib/remark/mermaid/index.d.ts.map +1 -1
- package/lib/remark/mermaid/index.js +5 -5
- package/lib/remark/mermaid/index.js.map +1 -1
- package/lib/remark/toc/index.d.ts.map +1 -1
- package/lib/remark/toc/index.js +2 -2
- package/lib/remark/toc/index.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +8 -7
- package/lib/remark/transformImage/index.js.map +1 -1
- package/lib/remark/transformLinks/index.d.ts.map +1 -1
- package/lib/remark/transformLinks/index.js +8 -7
- package/lib/remark/transformLinks/index.js.map +1 -1
- package/lib/remark/unusedDirectives/index.d.ts +4 -0
- package/lib/remark/unusedDirectives/index.d.ts.map +1 -0
- package/lib/remark/unusedDirectives/index.js +117 -0
- package/lib/remark/unusedDirectives/index.js.map +1 -0
- package/lib/remark/utils/index.d.ts +10 -3
- package/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +19 -1
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +24 -25
- package/src/loader.ts +4 -0
- package/src/processor.ts +14 -11
- package/src/remark/admonitions/index.ts +3 -1
- package/src/remark/contentTitle/index.ts +3 -1
- package/src/remark/details/index.ts +2 -2
- package/src/remark/head/index.ts +2 -2
- package/src/remark/headings/index.ts +1 -1
- package/src/remark/mdx1Compat/codeCompatPlugin.ts +6 -8
- package/src/remark/mermaid/index.ts +7 -4
- package/src/remark/toc/index.ts +10 -4
- package/src/remark/transformImage/index.ts +9 -10
- package/src/remark/transformLinks/index.ts +9 -10
- package/src/remark/unusedDirectives/index.ts +167 -0
- package/src/remark/utils/index.ts +23 -2
- package/src/types.d.mts +34 -0
|
@@ -11,7 +11,6 @@ const path_1 = tslib_1.__importDefault(require("path"));
|
|
|
11
11
|
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
|
-
const unist_util_visit_1 = tslib_1.__importDefault(require("unist-util-visit"));
|
|
15
14
|
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
16
15
|
const utils_2 = require("../utils");
|
|
17
16
|
const { loaders: { inlineMarkdownLinkFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
@@ -50,11 +49,12 @@ async function toAssetRequireNode([node], assetPath, filePath) {
|
|
|
50
49
|
});
|
|
51
50
|
}
|
|
52
51
|
const { children } = node;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
(0, utils_2.transformNode)(jsxNode, {
|
|
53
|
+
type: 'mdxJsxTextElement',
|
|
54
|
+
name: 'a',
|
|
55
|
+
attributes,
|
|
56
|
+
children,
|
|
57
|
+
});
|
|
58
58
|
}
|
|
59
59
|
async function ensureAssetFileExist(assetPath, sourceFilePath) {
|
|
60
60
|
const assetExists = await fs_extra_1.default.pathExists(assetPath);
|
|
@@ -111,8 +111,9 @@ async function processLinkNode(target, context) {
|
|
|
111
111
|
}
|
|
112
112
|
function plugin(options) {
|
|
113
113
|
return async (root, vfile) => {
|
|
114
|
+
const { visit } = await import('unist-util-visit');
|
|
114
115
|
const promises = [];
|
|
115
|
-
(
|
|
116
|
+
visit(root, 'link', (node, index, parent) => {
|
|
116
117
|
promises.push(processLinkNode([node, index, parent], {
|
|
117
118
|
...options,
|
|
118
119
|
filePath: vfile.path,
|
|
@@ -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,6CAM2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/transformLinks/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,wDAAwB;AACxB,sDAAsB;AACtB,gEAA0B;AAC1B,6CAM2B;AAC3B,sEAAqC;AACrC,oCAAmE;AAQnE,MAAM,EACJ,OAAO,EAAE,EAAC,4BAA4B,EAAC,GACxC,GAAG,IAAA,0BAAkB,GAAE,CAAC;AAazB;;GAEG;AACH,KAAK,UAAU,kBAAkB,CAC/B,CAAC,IAAI,CAAS,EACd,SAAiB,EACjB,QAAgB;IAEhB,mGAAmG;IACnG,MAAM,OAAO,GAAG,IAAoC,CAAC;IACrD,MAAM,UAAU,GAAoC,EAAE,CAAC;IAEvD,0EAA0E;IAC1E,MAAM,iBAAiB,GAAG,KAAK,IAAA,iBAAS,EACtC,cAAI,CAAC,QAAQ,CA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B;IACnD,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAEjD,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,IAAU,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChD,QAAQ,CAAC,IAAI,CACX,eAAe,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,MAAO,CAAC,EAAE;gBACtC,GAAG,OAAO;gBACV,QAAQ,EAAE,KAAK,CAAC,IAAK;aACtB,CAAC,CACH,CAAC;QACJ,CAAC,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC,CAAC;AACJ,CAAC;AAfD,yBAeC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/unusedDirectives/index.ts"],"names":[],"mappings":"AAwBA,KAAK,MAAM,GAAG,GAAG,CAAC;AA4GlB,QAAA,MAAM,MAAM,EAAE,MAgCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
11
|
+
const process_1 = tslib_1.__importDefault(require("process"));
|
|
12
|
+
const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
|
|
13
|
+
const utils_1 = require("@docusaurus/utils");
|
|
14
|
+
const utils_2 = require("../utils");
|
|
15
|
+
const directiveTypes = [
|
|
16
|
+
'containerDirective',
|
|
17
|
+
'leafDirective',
|
|
18
|
+
'textDirective',
|
|
19
|
+
];
|
|
20
|
+
const directivePrefixMap = {
|
|
21
|
+
textDirective: ':',
|
|
22
|
+
leafDirective: '::',
|
|
23
|
+
containerDirective: ':::',
|
|
24
|
+
};
|
|
25
|
+
function formatDirectiveName(directive) {
|
|
26
|
+
const prefix = directivePrefixMap[directive.type];
|
|
27
|
+
if (!prefix) {
|
|
28
|
+
throw new Error(`unexpected, no prefix found for directive of type ${directive.type}`);
|
|
29
|
+
}
|
|
30
|
+
// To simplify we don't display the eventual label/props of directives
|
|
31
|
+
return `${prefix}${directive.name}`;
|
|
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
|
+
function formatUnusedDirectiveMessage(directive) {
|
|
39
|
+
const name = formatDirectiveName(directive);
|
|
40
|
+
const position = formatDirectivePosition(directive);
|
|
41
|
+
return `- ${name} ${position ? `(${position})` : ''}`;
|
|
42
|
+
}
|
|
43
|
+
function formatUnusedDirectivesMessage({ directives, filePath, }) {
|
|
44
|
+
const supportUrl = 'https://github.com/facebook/docusaurus/pull/9394';
|
|
45
|
+
const customPath = (0, utils_1.posixPath)(path_1.default.relative(process_1.default.cwd(), filePath));
|
|
46
|
+
const warningTitle = logger_1.default.interpolate `Docusaurus found ${directives.length} unused Markdown directives in file path=${customPath}`;
|
|
47
|
+
const customSupportUrl = logger_1.default.interpolate `url=${supportUrl}`;
|
|
48
|
+
const warningMessages = directives
|
|
49
|
+
.map(formatUnusedDirectiveMessage)
|
|
50
|
+
.join('\n');
|
|
51
|
+
return `${warningTitle}
|
|
52
|
+
${warningMessages}
|
|
53
|
+
Your content might render in an unexpected way. Visit ${customSupportUrl} to find out why and how to fix it.`;
|
|
54
|
+
}
|
|
55
|
+
function logUnusedDirectivesWarning({ directives, filePath, }) {
|
|
56
|
+
if (directives.length > 0) {
|
|
57
|
+
const message = formatUnusedDirectivesMessage({
|
|
58
|
+
directives,
|
|
59
|
+
filePath,
|
|
60
|
+
});
|
|
61
|
+
logger_1.default.warn(message);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function isTextDirective(directive) {
|
|
65
|
+
return directive.type === 'textDirective';
|
|
66
|
+
}
|
|
67
|
+
// A simple text directive is one without any label/props
|
|
68
|
+
function isSimpleTextDirective(directive) {
|
|
69
|
+
if (isTextDirective(directive)) {
|
|
70
|
+
// Attributes in MDAST = Directive props
|
|
71
|
+
const hasAttributes = directive.attributes && Object.keys(directive.attributes).length > 0;
|
|
72
|
+
// Children in MDAST = Directive label
|
|
73
|
+
const hasChildren = directive.children.length > 0;
|
|
74
|
+
return !hasAttributes && !hasChildren;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
function transformSimpleTextDirectiveToString(textDirective) {
|
|
79
|
+
(0, utils_2.transformNode)(textDirective, {
|
|
80
|
+
type: 'text',
|
|
81
|
+
value: `:${textDirective.name}`, // We ignore label/props on purpose here
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function isUnusedDirective(directive) {
|
|
85
|
+
// If directive data is set (notably hName/hProperties set by admonitions)
|
|
86
|
+
// this usually means the directive has been handled by another plugin
|
|
87
|
+
return !directive.data;
|
|
88
|
+
}
|
|
89
|
+
const plugin = function plugin() {
|
|
90
|
+
return async (tree, file) => {
|
|
91
|
+
const { visit } = await import('unist-util-visit');
|
|
92
|
+
const unusedDirectives = [];
|
|
93
|
+
visit(tree, directiveTypes, (directive) => {
|
|
94
|
+
// If directive data is set (hName/hProperties set by admonitions)
|
|
95
|
+
// this usually means the directive has been handled by another plugin
|
|
96
|
+
if (isUnusedDirective(directive)) {
|
|
97
|
+
if (isSimpleTextDirective(directive)) {
|
|
98
|
+
transformSimpleTextDirectiveToString(directive);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
unusedDirectives.push(directive);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
// We only enable these warnings for the client compiler
|
|
106
|
+
// This avoids emitting duplicate warnings in prod mode
|
|
107
|
+
// Note: the client compiler is used in both dev/prod modes
|
|
108
|
+
if (file.data.compilerName === 'client') {
|
|
109
|
+
logUnusedDirectivesWarning({
|
|
110
|
+
directives: unusedDirectives,
|
|
111
|
+
filePath: file.path,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
exports.default = plugin;
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,oCAAuC;AAkBvC,MAAM,cAAc,GAAoB;IACtC,oBAAoB;IACpB,eAAe;IACf,eAAe;CAChB,CAAC;AAEF,MAAM,kBAAkB,GAAqC;IAC3D,aAAa,EAAE,GAAG;IAClB,aAAa,EAAE,IAAI;IACnB,kBAAkB,EAAE,KAAK;CAC1B,CAAC;AAEF,SAAS,mBAAmB,CAAC,SAAqB;IAChD,MAAM,MAAM,GAAG,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAClD,IAAI,CAAC,MAAM,EAAE;QACX,MAAM,IAAI,KAAK,CACb,qDAAqD,SAAS,CAAC,IAAI,EAAE,CACtE,CAAC;KACH;IACD,sEAAsE;IACtE,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;AACtC,CAAC;AAED,SAAS,uBAAuB,CAAC,SAAqB;IACpD,OAAO,SAAS,CAAC,QAAQ,EAAE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qB,CAAC,SAAS,CAAC,EAAE;oBACpC,oCAAoC,CAAC,SAAS,CAAC,CAAC;iBACjD;qBAAM;oBACL,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBAClC;aACF;QACH,CAAC,CACF,CAAC;QAEF,wDAAwD;QACxD,uDAAuD;QACvD,2DAA2D;QAC3D,IAAI,IAAI,CAAC,IAAI,CAAC,YAAY,KAAK,QAAQ,EAAE;YACvC,0BAA0B,CAAC;gBACzB,UAAU,EAAE,gBAAgB;gBAC5B,QAAQ,EAAE,IAAI,CAAC,IAAI;aACpB,CAAC,CAAC;SACJ;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
|
@@ -4,10 +4,17 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import type { Parent } from 'unist';
|
|
7
|
+
import type { Parent, Node } from 'unist';
|
|
8
8
|
import type { PhrasingContent, Heading } from 'mdast';
|
|
9
|
-
import type { MdxJsxAttributeValueExpression } from 'mdast-util-mdx';
|
|
9
|
+
import type { MdxJsxAttributeValueExpression, MdxJsxTextElement } from 'mdast-util-mdx';
|
|
10
|
+
/**
|
|
11
|
+
* Util to transform one node type to another node type
|
|
12
|
+
* The input node is mutated in place
|
|
13
|
+
* @param node the node to mutate
|
|
14
|
+
* @param newNode what the original node should become become
|
|
15
|
+
*/
|
|
16
|
+
export declare function transformNode<NewNode extends Node>(node: Node, newNode: NewNode): NewNode;
|
|
10
17
|
export declare function stringifyContent(node: Parent, toString: (param: unknown) => string): string;
|
|
11
|
-
export declare function toValue(node: PhrasingContent | Heading, toString: (param: unknown) => string): string;
|
|
18
|
+
export declare function toValue(node: PhrasingContent | Heading | MdxJsxTextElement, toString: (param: unknown) => string): string;
|
|
12
19
|
export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
|
|
13
20
|
//# 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;AAGH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,MAAM,EAAE,IAAI,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAEV,8BAA8B,EAC9B,iBAAiB,EAElB,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,IAAI,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACf,OAAO,CAUT;AAED,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAIR;AA8BD,wBAAgB,OAAO,CACrB,IAAI,EAAE,eAAe,GAAG,OAAO,GAAG,iBAAiB,EACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAsBR;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC"}
|
|
@@ -6,9 +6,27 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.assetRequireAttributeValue = exports.toValue = exports.stringifyContent = void 0;
|
|
9
|
+
exports.assetRequireAttributeValue = exports.toValue = exports.stringifyContent = exports.transformNode = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
12
|
+
/**
|
|
13
|
+
* Util to transform one node type to another node type
|
|
14
|
+
* The input node is mutated in place
|
|
15
|
+
* @param node the node to mutate
|
|
16
|
+
* @param newNode what the original node should become become
|
|
17
|
+
*/
|
|
18
|
+
function transformNode(node, newNode) {
|
|
19
|
+
Object.keys(node).forEach((key) => {
|
|
20
|
+
// @ts-expect-error: unsafe but ok
|
|
21
|
+
delete node[key];
|
|
22
|
+
});
|
|
23
|
+
Object.keys(newNode).forEach((key) => {
|
|
24
|
+
// @ts-expect-error: unsafe but ok
|
|
25
|
+
node[key] = newNode[key];
|
|
26
|
+
});
|
|
27
|
+
return node;
|
|
28
|
+
}
|
|
29
|
+
exports.transformNode = transformNode;
|
|
12
30
|
function stringifyContent(node, toString) {
|
|
13
31
|
return node.children
|
|
14
32
|
.map((item) => toValue(item, toString))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,sEAAqC;AAUrC,SAAgB,gBAAgB,CAC9B,IAAY,EACZ,QAAoC;IAEpC,OAAQ,IAAI,CAAC,QAA8B;SACxC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;SACtC,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AAPD,4CAOC;AAED,2DAA2D;AAC3D,qEAAqE;AACrE,8EAA8E;AAC9E,SAAS,uBAAuB,CAC9B,OAA0B,EAC1B,QAAoC;IAEpC,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAEzB,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,MAAM,CAC1C,CAAC,KAAK,EAA4B,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,iBAAiB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AI,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;AArDD,gEAqDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "3.0.0-rc.
|
|
3
|
+
"version": "3.0.0-rc.1",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -20,45 +20,44 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/parser": "^7.22.7",
|
|
22
22
|
"@babel/traverse": "^7.22.8",
|
|
23
|
-
"@docusaurus/logger": "3.0.0-rc.
|
|
24
|
-
"@docusaurus/utils": "3.0.0-rc.
|
|
25
|
-
"@docusaurus/utils-validation": "3.0.0-rc.
|
|
26
|
-
"@mdx-js/mdx": "^
|
|
23
|
+
"@docusaurus/logger": "3.0.0-rc.1",
|
|
24
|
+
"@docusaurus/utils": "3.0.0-rc.1",
|
|
25
|
+
"@docusaurus/utils-validation": "3.0.0-rc.1",
|
|
26
|
+
"@mdx-js/mdx": "^3.0.0",
|
|
27
27
|
"@slorber/remark-comment": "^1.0.0",
|
|
28
28
|
"escape-html": "^1.0.3",
|
|
29
|
-
"estree-util-value-to-estree": "^
|
|
29
|
+
"estree-util-value-to-estree": "^3.0.1",
|
|
30
30
|
"file-loader": "^6.2.0",
|
|
31
31
|
"fs-extra": "^11.1.1",
|
|
32
|
-
"hastscript": "^7.1.0",
|
|
33
32
|
"image-size": "^1.0.2",
|
|
34
|
-
"mdast-util-mdx": "^
|
|
35
|
-
"mdast-util-to-string": "^
|
|
36
|
-
"rehype-raw": "^
|
|
37
|
-
"remark-directive": "^
|
|
38
|
-
"remark-emoji": "^
|
|
33
|
+
"mdast-util-mdx": "^3.0.0",
|
|
34
|
+
"mdast-util-to-string": "^4.0.0",
|
|
35
|
+
"rehype-raw": "^7.0.0",
|
|
36
|
+
"remark-directive": "^3.0.0",
|
|
37
|
+
"remark-emoji": "^4.0.0",
|
|
39
38
|
"remark-frontmatter": "^5.0.0",
|
|
40
|
-
"remark-gfm": "^
|
|
39
|
+
"remark-gfm": "^4.0.0",
|
|
41
40
|
"stringify-object": "^3.3.0",
|
|
42
41
|
"tslib": "^2.6.0",
|
|
43
|
-
"unified": "^
|
|
44
|
-
"unist-util-visit": "^
|
|
42
|
+
"unified": "^11.0.3",
|
|
43
|
+
"unist-util-visit": "^5.0.0",
|
|
45
44
|
"url-loader": "^4.1.1",
|
|
46
|
-
"vfile": "^
|
|
45
|
+
"vfile": "^6.0.1",
|
|
47
46
|
"webpack": "^5.88.1"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
|
-
"@docusaurus/types": "3.0.0-rc.
|
|
49
|
+
"@docusaurus/types": "3.0.0-rc.1",
|
|
51
50
|
"@types/escape-html": "^1.0.2",
|
|
52
|
-
"@types/mdast": "^
|
|
51
|
+
"@types/mdast": "^4.0.2",
|
|
53
52
|
"@types/stringify-object": "^3.3.1",
|
|
54
|
-
"@types/unist": "^
|
|
55
|
-
"rehype-stringify": "^
|
|
56
|
-
"remark": "^
|
|
57
|
-
"remark-mdx": "^
|
|
58
|
-
"remark-rehype": "^
|
|
53
|
+
"@types/unist": "^3.0.1",
|
|
54
|
+
"rehype-stringify": "^10.0.0",
|
|
55
|
+
"remark": "^15.0.1",
|
|
56
|
+
"remark-mdx": "^3.0.0",
|
|
57
|
+
"remark-rehype": "^11.0.0",
|
|
59
58
|
"to-vfile": "^6.1.0",
|
|
60
59
|
"unist-builder": "^2.0.3",
|
|
61
|
-
"unist-util-remove-position": "^
|
|
60
|
+
"unist-util-remove-position": "^5.0.0"
|
|
62
61
|
},
|
|
63
62
|
"peerDependencies": {
|
|
64
63
|
"react": "^18.0.0",
|
|
@@ -67,5 +66,5 @@
|
|
|
67
66
|
"engines": {
|
|
68
67
|
"node": ">=18.0"
|
|
69
68
|
},
|
|
70
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "a51cc6fd7660d47ea08349f723cec9c017af0b4e"
|
|
71
70
|
}
|
package/src/loader.ts
CHANGED
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
parseFrontMatter,
|
|
12
12
|
escapePath,
|
|
13
13
|
getFileLoaderUtils,
|
|
14
|
+
getWebpackLoaderCompilerName,
|
|
14
15
|
} from '@docusaurus/utils';
|
|
15
16
|
import stringifyObject from 'stringify-object';
|
|
16
17
|
import preprocessor from './preprocessor';
|
|
@@ -134,10 +135,12 @@ export async function mdxLoader(
|
|
|
134
135
|
this: LoaderContext<Options>,
|
|
135
136
|
fileString: string,
|
|
136
137
|
): Promise<void> {
|
|
138
|
+
const compilerName = getWebpackLoaderCompilerName(this);
|
|
137
139
|
const callback = this.async();
|
|
138
140
|
const filePath = this.resourcePath;
|
|
139
141
|
const reqOptions: Options = this.getOptions();
|
|
140
142
|
const {query} = this;
|
|
143
|
+
|
|
141
144
|
ensureMarkdownConfig(reqOptions);
|
|
142
145
|
|
|
143
146
|
const {frontMatter} = parseFrontMatter(fileString);
|
|
@@ -165,6 +168,7 @@ export async function mdxLoader(
|
|
|
165
168
|
content: preprocessedContent,
|
|
166
169
|
filePath,
|
|
167
170
|
frontMatter,
|
|
171
|
+
compilerName,
|
|
168
172
|
});
|
|
169
173
|
} catch (errorUnknown) {
|
|
170
174
|
const error = errorUnknown as Error;
|
package/src/processor.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import emoji from 'remark-emoji';
|
|
9
8
|
import headings from './remark/headings';
|
|
10
9
|
import contentTitle from './remark/contentTitle';
|
|
11
10
|
import toc from './remark/toc';
|
|
@@ -15,8 +14,10 @@ import details from './remark/details';
|
|
|
15
14
|
import head from './remark/head';
|
|
16
15
|
import mermaid from './remark/mermaid';
|
|
17
16
|
import transformAdmonitions from './remark/admonitions';
|
|
17
|
+
import unusedDirectivesWarning from './remark/unusedDirectives';
|
|
18
18
|
import codeCompatPlugin from './remark/mdx1Compat/codeCompatPlugin';
|
|
19
19
|
import {getFormat} from './format';
|
|
20
|
+
import type {WebpackCompilerName} from '@docusaurus/utils';
|
|
20
21
|
import type {MDXFrontMatter} from './frontMatter';
|
|
21
22
|
import type {Options} from './loader';
|
|
22
23
|
import type {AdmonitionOptions} from './remark/admonitions';
|
|
@@ -37,20 +38,19 @@ type SimpleProcessor = {
|
|
|
37
38
|
content,
|
|
38
39
|
filePath,
|
|
39
40
|
frontMatter,
|
|
41
|
+
compilerName,
|
|
40
42
|
}: {
|
|
41
43
|
content: string;
|
|
42
44
|
filePath: string;
|
|
43
45
|
frontMatter: {[key: string]: unknown};
|
|
46
|
+
compilerName: WebpackCompilerName;
|
|
44
47
|
}) => Promise<SimpleProcessorResult>;
|
|
45
48
|
};
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
beforeDefaultRemarkPlugins: [],
|
|
52
|
-
beforeDefaultRehypePlugins: [],
|
|
53
|
-
};
|
|
50
|
+
async function getDefaultRemarkPlugins(): Promise<MDXPlugin[]> {
|
|
51
|
+
const {default: emoji} = await import('remark-emoji');
|
|
52
|
+
return [headings, emoji, toc];
|
|
53
|
+
}
|
|
54
54
|
|
|
55
55
|
export type MDXPlugin = Pluggable;
|
|
56
56
|
|
|
@@ -87,6 +87,8 @@ async function createProcessorFactory() {
|
|
|
87
87
|
const {default: directive} = await import('remark-directive');
|
|
88
88
|
const {VFile} = await import('vfile');
|
|
89
89
|
|
|
90
|
+
const defaultRemarkPlugins = await getDefaultRemarkPlugins();
|
|
91
|
+
|
|
90
92
|
// /!\ this method is synchronous on purpose
|
|
91
93
|
// Using async code here can create cache entry race conditions!
|
|
92
94
|
function createProcessorSync({
|
|
@@ -102,7 +104,7 @@ async function createProcessorFactory() {
|
|
|
102
104
|
directive,
|
|
103
105
|
[contentTitle, {removeContentTitle: options.removeContentTitle}],
|
|
104
106
|
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
105
|
-
...
|
|
107
|
+
...defaultRemarkPlugins,
|
|
106
108
|
details,
|
|
107
109
|
head,
|
|
108
110
|
...(options.markdownConfig.mermaid ? [mermaid] : []),
|
|
@@ -123,6 +125,7 @@ async function createProcessorFactory() {
|
|
|
123
125
|
gfm,
|
|
124
126
|
options.markdownConfig.mdx1Compat.comments ? comment : null,
|
|
125
127
|
...(options.remarkPlugins ?? []),
|
|
128
|
+
unusedDirectivesWarning,
|
|
126
129
|
].filter((plugin): plugin is MDXPlugin => Boolean(plugin));
|
|
127
130
|
|
|
128
131
|
// codeCompatPlugin needs to be applied last after user-provided plugins
|
|
@@ -131,7 +134,6 @@ async function createProcessorFactory() {
|
|
|
131
134
|
|
|
132
135
|
const rehypePlugins: MDXPlugin[] = [
|
|
133
136
|
...(options.beforeDefaultRehypePlugins ?? []),
|
|
134
|
-
...DEFAULT_OPTIONS.rehypePlugins,
|
|
135
137
|
...(options.rehypePlugins ?? []),
|
|
136
138
|
];
|
|
137
139
|
|
|
@@ -167,12 +169,13 @@ async function createProcessorFactory() {
|
|
|
167
169
|
});
|
|
168
170
|
|
|
169
171
|
return {
|
|
170
|
-
process: async ({content, filePath, frontMatter}) => {
|
|
172
|
+
process: async ({content, filePath, frontMatter, compilerName}) => {
|
|
171
173
|
const vfile = new VFile({
|
|
172
174
|
value: content,
|
|
173
175
|
path: filePath,
|
|
174
176
|
data: {
|
|
175
177
|
frontMatter,
|
|
178
|
+
compilerName,
|
|
176
179
|
},
|
|
177
180
|
});
|
|
178
181
|
return mdxProcessor.process(vfile).then((result) => ({
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import visit from 'unist-util-visit';
|
|
8
7
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
9
8
|
import type {Transformer, Processor} from 'unified';
|
|
10
9
|
|
|
@@ -67,6 +66,7 @@ function parseDirective(directive: ContainerDirective): {
|
|
|
67
66
|
contentNodes: DirectiveContent;
|
|
68
67
|
} {
|
|
69
68
|
const hasDirectiveLabel =
|
|
69
|
+
// @ts-expect-error: fine
|
|
70
70
|
directive.children?.[0]?.data?.directiveLabel === true;
|
|
71
71
|
if (hasDirectiveLabel) {
|
|
72
72
|
const [directiveLabel, ...contentNodes] = directive.children;
|
|
@@ -92,6 +92,8 @@ const plugin: Plugin = function plugin(
|
|
|
92
92
|
const {keywords} = normalizeAdmonitionOptions(optionsInput);
|
|
93
93
|
|
|
94
94
|
return async (root) => {
|
|
95
|
+
const {visit} = await import('unist-util-visit');
|
|
96
|
+
|
|
95
97
|
visit(root, (node) => {
|
|
96
98
|
if (node.type === 'containerDirective') {
|
|
97
99
|
const directive = node as ContainerDirective;
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import visit, {EXIT} from 'unist-util-visit';
|
|
9
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
9
|
import type {Transformer} from 'unified';
|
|
11
10
|
import type {Heading} from 'mdast';
|
|
@@ -33,10 +32,13 @@ const plugin: Plugin = function plugin(
|
|
|
33
32
|
|
|
34
33
|
return async (root, vfile) => {
|
|
35
34
|
const {toString} = await import('mdast-util-to-string');
|
|
35
|
+
const {visit, EXIT} = await import('unist-util-visit');
|
|
36
|
+
|
|
36
37
|
visit(root, 'heading', (headingNode: Heading, index, parent) => {
|
|
37
38
|
if (headingNode.depth === 1) {
|
|
38
39
|
vfile.data.contentTitle = toString(headingNode);
|
|
39
40
|
if (removeContentTitle) {
|
|
41
|
+
// @ts-expect-error: TODO how to fix?
|
|
40
42
|
parent!.children.splice(index, 1);
|
|
41
43
|
}
|
|
42
44
|
return EXIT; // We only handle the very first heading
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import visit from 'unist-util-visit';
|
|
9
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
9
|
import type {Transformer} from 'unified';
|
|
11
10
|
|
|
@@ -15,7 +14,8 @@ import type {MdxJsxFlowElement} from 'mdast-util-mdx';
|
|
|
15
14
|
// Transform <details> to <Details>
|
|
16
15
|
// MDX 2 doesn't allow to substitute html elements with the provider anymore
|
|
17
16
|
export default function plugin(): Transformer {
|
|
18
|
-
return (root) => {
|
|
17
|
+
return async (root) => {
|
|
18
|
+
const {visit} = await import('unist-util-visit');
|
|
19
19
|
visit(root, 'mdxJsxFlowElement', (node: MdxJsxFlowElement) => {
|
|
20
20
|
if (node.name === 'details') {
|
|
21
21
|
node.name = 'Details';
|
package/src/remark/head/index.ts
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import visit from 'unist-util-visit';
|
|
9
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
9
|
import type {Transformer} from 'unified';
|
|
11
10
|
|
|
@@ -15,7 +14,8 @@ import type {MdxJsxFlowElement} from 'mdast-util-mdx';
|
|
|
15
14
|
// Transform <head> to <Head>
|
|
16
15
|
// MDX 2 doesn't allow to substitute html elements with the provider anymore
|
|
17
16
|
export default function plugin(): Transformer {
|
|
18
|
-
return (root) => {
|
|
17
|
+
return async (root) => {
|
|
18
|
+
const {visit} = await import('unist-util-visit');
|
|
19
19
|
visit(root, 'mdxJsxFlowElement', (node: MdxJsxFlowElement) => {
|
|
20
20
|
if (node.name === 'head') {
|
|
21
21
|
node.name = 'Head';
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
/* Based on remark-slug (https://github.com/remarkjs/remark-slug) and gatsby-remark-autolink-headers (https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-remark-autolink-headers) */
|
|
9
9
|
|
|
10
10
|
import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
|
|
11
|
-
import visit from 'unist-util-visit';
|
|
12
11
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
13
12
|
import type {Transformer} from 'unified';
|
|
14
13
|
import type {Heading, Text} from 'mdast';
|
|
@@ -16,6 +15,7 @@ import type {Heading, Text} from 'mdast';
|
|
|
16
15
|
export default function plugin(): Transformer {
|
|
17
16
|
return async (root) => {
|
|
18
17
|
const {toString} = await import('mdast-util-to-string');
|
|
18
|
+
const {visit} = await import('unist-util-visit');
|
|
19
19
|
|
|
20
20
|
const slugs = createSlugger();
|
|
21
21
|
visit(root, 'heading', (headingNode: Heading) => {
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import visit from 'unist-util-visit';
|
|
9
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
9
|
import type {Transformer, Processor} from 'unified';
|
|
11
10
|
import type {Code} from 'mdast';
|
|
@@ -18,19 +17,18 @@ import type {Code} from 'mdast';
|
|
|
18
17
|
// To make theme-classic/src/theme/MDXComponents/Pre work
|
|
19
18
|
// we need to fill two properties that mdx v2 doesn't provide anymore
|
|
20
19
|
export default function codeCompatPlugin(this: Processor): Transformer {
|
|
21
|
-
return (root) => {
|
|
20
|
+
return async (root) => {
|
|
21
|
+
const {visit} = await import('unist-util-visit');
|
|
22
|
+
|
|
22
23
|
visit(root, 'code', (node: Code) => {
|
|
23
24
|
node.data = node.data || {};
|
|
25
|
+
|
|
24
26
|
node.data.hProperties = node.data.hProperties || {};
|
|
25
|
-
|
|
26
|
-
(node.data.hProperties as any).metastring = node.meta;
|
|
27
|
+
node.data.hProperties.metastring = node.meta;
|
|
27
28
|
|
|
28
29
|
// Retrocompatible support for live codeblock metastring
|
|
29
30
|
// Not really the appropriate place to handle that :s
|
|
30
|
-
|
|
31
|
-
(node.data.hProperties as any).live = node.meta
|
|
32
|
-
?.split(' ')
|
|
33
|
-
.includes('live');
|
|
31
|
+
node.data.hProperties.live = node.meta?.split(' ').includes('live');
|
|
34
32
|
});
|
|
35
33
|
};
|
|
36
34
|
}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
8
|
+
import {transformNode} from '../utils';
|
|
9
|
+
|
|
9
10
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
11
|
import type {Transformer} from 'unified';
|
|
11
12
|
import type {Code} from 'mdast';
|
|
@@ -15,11 +16,13 @@ import type {Code} from 'mdast';
|
|
|
15
16
|
// https://github.com/facebook/docusaurus/issues/6370), this should be provided
|
|
16
17
|
// by theme-mermaid itself
|
|
17
18
|
export default function plugin(): Transformer {
|
|
18
|
-
return (root) => {
|
|
19
|
-
visit(
|
|
19
|
+
return async (root) => {
|
|
20
|
+
const {visit} = await import('unist-util-visit');
|
|
21
|
+
|
|
22
|
+
visit(root, 'code', (node: Code) => {
|
|
20
23
|
if (node.lang === 'mermaid') {
|
|
21
24
|
// TODO migrate to mdxJsxFlowElement? cf admonitions
|
|
22
|
-
|
|
25
|
+
transformNode(node, {
|
|
23
26
|
type: 'mermaidCodeBlock',
|
|
24
27
|
data: {
|
|
25
28
|
hName: 'mermaid',
|