@docusaurus/mdx-loader 4.0.0-canary-6813 → 4.0.0-canary-6815
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 +20 -21
- package/lib/processor.js.map +1 -1
- package/lib/remark/admonitions/index.d.ts +0 -6
- package/lib/remark/admonitions/index.d.ts.map +1 -1
- package/lib/remark/admonitions/index.js +9 -3
- package/lib/remark/admonitions/index.js.map +1 -1
- package/lib/remark/contentTitle/index.d.ts +0 -6
- package/lib/remark/contentTitle/index.d.ts.map +1 -1
- package/lib/remark/contentTitle/index.js +14 -8
- 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 -3
- 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 -3
- 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 +5 -5
- 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 +3 -3
- 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 +3 -3
- package/lib/remark/mermaid/index.js.map +1 -1
- package/lib/remark/resolveMarkdownLinks/index.d.ts.map +1 -1
- package/lib/remark/resolveMarkdownLinks/index.js +3 -3
- package/lib/remark/resolveMarkdownLinks/index.js.map +1 -1
- package/lib/remark/toc/index.d.ts.map +1 -1
- package/lib/remark/toc/index.js +11 -12
- package/lib/remark/toc/index.js.map +1 -1
- package/lib/remark/toc/utils.d.ts +2 -2
- package/lib/remark/toc/utils.d.ts.map +1 -1
- package/lib/remark/toc/utils.js +20 -20
- package/lib/remark/toc/utils.js.map +1 -1
- package/lib/remark/transformImage/index.d.ts.map +1 -1
- package/lib/remark/transformImage/index.js +2 -2
- 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 +4 -4
- 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 +3 -3
- package/lib/remark/unusedDirectives/index.js.map +1 -1
- package/package.json +13 -11
- package/src/processor.ts +13 -15
- package/src/remark/admonitions/index.ts +2 -3
- package/src/remark/contentTitle/index.ts +3 -3
- package/src/remark/details/index.ts +2 -2
- package/src/remark/head/index.ts +2 -2
- package/src/remark/headings/index.ts +3 -4
- package/src/remark/mdx1Compat/codeCompatPlugin.ts +2 -3
- package/src/remark/mermaid/index.ts +2 -3
- package/src/remark/resolveMarkdownLinks/index.ts +2 -3
- package/src/remark/toc/index.ts +12 -15
- package/src/remark/toc/utils.ts +18 -25
- package/src/remark/transformImage/index.ts +1 -2
- package/src/remark/transformLinks/index.ts +3 -4
- package/src/remark/unusedDirectives/index.ts +2 -3
package/src/remark/toc/index.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {visit} from 'unist-util-visit';
|
|
9
|
+
import {toString} from 'mdast-util-to-string';
|
|
8
10
|
import {
|
|
9
11
|
addTocSliceImportIfNeeded,
|
|
10
12
|
createTOCExportNodeAST,
|
|
@@ -41,18 +43,16 @@ function createTocSliceImportName({
|
|
|
41
43
|
return `__${tocExportName}${componentName}`;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
function collectImportsExports({
|
|
45
47
|
root,
|
|
46
48
|
tocExportName,
|
|
47
49
|
}: {
|
|
48
50
|
root: Root;
|
|
49
51
|
tocExportName: string;
|
|
50
|
-
}):
|
|
52
|
+
}): {
|
|
51
53
|
markdownImports: MarkdownImports;
|
|
52
54
|
existingTocExport: ExistingTOCExport;
|
|
53
|
-
}
|
|
54
|
-
const {visit} = await import('unist-util-visit');
|
|
55
|
-
|
|
55
|
+
} {
|
|
56
56
|
const markdownImports = new Map<string, {declaration: ImportDeclaration}>();
|
|
57
57
|
let existingTocExport: MdxjsEsm | null = null;
|
|
58
58
|
|
|
@@ -81,7 +81,7 @@ async function collectImportsExports({
|
|
|
81
81
|
return {markdownImports, existingTocExport};
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
function collectTOCItems({
|
|
85
85
|
root,
|
|
86
86
|
tocExportName,
|
|
87
87
|
markdownImports,
|
|
@@ -89,13 +89,10 @@ async function collectTOCItems({
|
|
|
89
89
|
root: Root;
|
|
90
90
|
tocExportName: string;
|
|
91
91
|
markdownImports: MarkdownImports;
|
|
92
|
-
}):
|
|
92
|
+
}): {
|
|
93
93
|
// The toc items we collected in the tree
|
|
94
94
|
tocItems: TOCItems;
|
|
95
|
-
}
|
|
96
|
-
const {toString} = await import('mdast-util-to-string');
|
|
97
|
-
const {visit} = await import('unist-util-visit');
|
|
98
|
-
|
|
95
|
+
} {
|
|
99
96
|
const tocItems: TOCItems = [];
|
|
100
97
|
|
|
101
98
|
visit(root, (child) => {
|
|
@@ -155,8 +152,8 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
155
152
|
): Transformer<Root> {
|
|
156
153
|
const tocExportName = options.name || 'toc';
|
|
157
154
|
|
|
158
|
-
return
|
|
159
|
-
const {markdownImports, existingTocExport} =
|
|
155
|
+
return (root) => {
|
|
156
|
+
const {markdownImports, existingTocExport} = collectImportsExports({
|
|
160
157
|
root,
|
|
161
158
|
tocExportName,
|
|
162
159
|
});
|
|
@@ -168,14 +165,14 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
168
165
|
return;
|
|
169
166
|
}
|
|
170
167
|
|
|
171
|
-
const {tocItems} =
|
|
168
|
+
const {tocItems} = collectTOCItems({
|
|
172
169
|
root,
|
|
173
170
|
tocExportName,
|
|
174
171
|
markdownImports,
|
|
175
172
|
});
|
|
176
173
|
|
|
177
174
|
root.children.push(
|
|
178
|
-
|
|
175
|
+
createTOCExportNodeAST({
|
|
179
176
|
tocExportName,
|
|
180
177
|
tocItems,
|
|
181
178
|
}),
|
package/src/remark/toc/utils.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import {toString} from 'mdast-util-to-string';
|
|
9
|
+
import {valueToEstree} from 'estree-util-value-to-estree';
|
|
8
10
|
import escapeHtml from 'escape-html';
|
|
9
11
|
import type {Node, Parent} from 'unist';
|
|
10
12
|
import type {
|
|
@@ -105,13 +107,13 @@ export function isNamedExport(
|
|
|
105
107
|
return id.name === exportName;
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
export
|
|
110
|
+
export function createTOCExportNodeAST({
|
|
109
111
|
tocExportName,
|
|
110
112
|
tocItems,
|
|
111
113
|
}: {
|
|
112
114
|
tocExportName: string;
|
|
113
115
|
tocItems: TOCItems;
|
|
114
|
-
}):
|
|
116
|
+
}): MdxjsEsm {
|
|
115
117
|
function createTOCSliceAST(tocSlice: TOCSlice): SpreadElement {
|
|
116
118
|
return {
|
|
117
119
|
type: 'SpreadElement',
|
|
@@ -119,18 +121,16 @@ export async function createTOCExportNodeAST({
|
|
|
119
121
|
};
|
|
120
122
|
}
|
|
121
123
|
|
|
122
|
-
|
|
123
|
-
const {toString} = await import('mdast-util-to-string');
|
|
124
|
-
const {valueToEstree} = await import('estree-util-value-to-estree');
|
|
124
|
+
function createTOCHeadingAST({heading}: TOCHeading) {
|
|
125
125
|
const value: TOCItem = {
|
|
126
|
-
value: toHeadingHTMLValue(heading
|
|
126
|
+
value: toHeadingHTMLValue(heading),
|
|
127
127
|
id: heading.data!.id!,
|
|
128
128
|
level: heading.depth,
|
|
129
129
|
};
|
|
130
130
|
return valueToEstree(value);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
|
|
133
|
+
function createTOCItemAST(tocItem: TOCItems[number]) {
|
|
134
134
|
switch (tocItem.type) {
|
|
135
135
|
case 'slice':
|
|
136
136
|
return createTOCSliceAST(tocItem);
|
|
@@ -163,7 +163,7 @@ export async function createTOCExportNodeAST({
|
|
|
163
163
|
},
|
|
164
164
|
init: {
|
|
165
165
|
type: 'ArrayExpression',
|
|
166
|
-
elements:
|
|
166
|
+
elements: tocItems.map(createTOCItemAST),
|
|
167
167
|
},
|
|
168
168
|
},
|
|
169
169
|
],
|
|
@@ -179,12 +179,9 @@ export async function createTOCExportNodeAST({
|
|
|
179
179
|
};
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
function stringifyChildren(
|
|
183
|
-
node: Parent,
|
|
184
|
-
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
185
|
-
): string {
|
|
182
|
+
function stringifyChildren(node: Parent): string {
|
|
186
183
|
return (node.children as PhrasingContent[])
|
|
187
|
-
.map(
|
|
184
|
+
.map(toHeadingHTMLValue)
|
|
188
185
|
.join('')
|
|
189
186
|
.trim();
|
|
190
187
|
}
|
|
@@ -192,10 +189,7 @@ function stringifyChildren(
|
|
|
192
189
|
// TODO This is really a workaround, and not super reliable
|
|
193
190
|
// For now we only support serializing tagName, className and content
|
|
194
191
|
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
195
|
-
function mdxJsxTextElementToHtml(
|
|
196
|
-
element: MdxJsxTextElement,
|
|
197
|
-
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
198
|
-
): string {
|
|
192
|
+
function mdxJsxTextElementToHtml(element: MdxJsxTextElement): string {
|
|
199
193
|
const tag = element.name;
|
|
200
194
|
|
|
201
195
|
// See https://github.com/facebook/docusaurus/issues/11003#issuecomment-2733925363
|
|
@@ -217,33 +211,32 @@ function mdxJsxTextElementToHtml(
|
|
|
217
211
|
|
|
218
212
|
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
219
213
|
|
|
220
|
-
const content = stringifyChildren(element
|
|
214
|
+
const content = stringifyChildren(element);
|
|
221
215
|
|
|
222
216
|
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
223
217
|
}
|
|
224
218
|
|
|
225
219
|
export function toHeadingHTMLValue(
|
|
226
220
|
node: PhrasingContent | Heading | MdxJsxTextElement,
|
|
227
|
-
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
228
221
|
): string {
|
|
229
222
|
switch (node.type) {
|
|
230
223
|
case 'mdxJsxTextElement': {
|
|
231
|
-
return mdxJsxTextElementToHtml(node as MdxJsxTextElement
|
|
224
|
+
return mdxJsxTextElementToHtml(node as MdxJsxTextElement);
|
|
232
225
|
}
|
|
233
226
|
case 'text':
|
|
234
227
|
return escapeHtml(node.value);
|
|
235
228
|
case 'heading':
|
|
236
|
-
return stringifyChildren(node
|
|
229
|
+
return stringifyChildren(node);
|
|
237
230
|
case 'inlineCode':
|
|
238
231
|
return `<code>${escapeHtml(node.value)}</code>`;
|
|
239
232
|
case 'emphasis':
|
|
240
|
-
return `<em>${stringifyChildren(node
|
|
233
|
+
return `<em>${stringifyChildren(node)}</em>`;
|
|
241
234
|
case 'strong':
|
|
242
|
-
return `<strong>${stringifyChildren(node
|
|
235
|
+
return `<strong>${stringifyChildren(node)}</strong>`;
|
|
243
236
|
case 'delete':
|
|
244
|
-
return `<del>${stringifyChildren(node
|
|
237
|
+
return `<del>${stringifyChildren(node)}</del>`;
|
|
245
238
|
case 'link':
|
|
246
|
-
return stringifyChildren(node
|
|
239
|
+
return stringifyChildren(node);
|
|
247
240
|
default:
|
|
248
241
|
return toString(node);
|
|
249
242
|
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
+
import {visit} from 'unist-util-visit';
|
|
10
11
|
import {
|
|
11
12
|
toMessageRelativeFilePath,
|
|
12
13
|
posixPath,
|
|
@@ -246,8 +247,6 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
246
247
|
const onBrokenMarkdownImages = asFunction(options.onBrokenMarkdownImages);
|
|
247
248
|
|
|
248
249
|
return async (root, vfile) => {
|
|
249
|
-
const {visit} = await import('unist-util-visit');
|
|
250
|
-
|
|
251
250
|
const fileLoaderUtils = getFileLoaderUtils(
|
|
252
251
|
vfile.data.compilerName === 'server',
|
|
253
252
|
);
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import fs from 'fs-extra';
|
|
10
|
+
import {visit} from 'unist-util-visit';
|
|
10
11
|
import {
|
|
11
12
|
toMessageRelativeFilePath,
|
|
12
13
|
posixPath,
|
|
@@ -86,7 +87,7 @@ Make sure it references a local Markdown file that exists within the current plu
|
|
|
86
87
|
/**
|
|
87
88
|
* Transforms the link node to a JSX `<a>` element with a `require()` call.
|
|
88
89
|
*/
|
|
89
|
-
|
|
90
|
+
function toAssetRequireNode(
|
|
90
91
|
[node]: Target,
|
|
91
92
|
assetPath: string,
|
|
92
93
|
context: Context,
|
|
@@ -241,7 +242,7 @@ async function processLinkNode(target: Target, context: Context) {
|
|
|
241
242
|
);
|
|
242
243
|
|
|
243
244
|
if (localFilePath) {
|
|
244
|
-
|
|
245
|
+
toAssetRequireNode(target, localFilePath, context);
|
|
245
246
|
} else {
|
|
246
247
|
// The @site alias is the only way to believe that the user wants an asset.
|
|
247
248
|
if (hasSiteAlias) {
|
|
@@ -265,8 +266,6 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
265
266
|
const onBrokenMarkdownLinks = asFunction(options.onBrokenMarkdownLinks);
|
|
266
267
|
|
|
267
268
|
return async (root, vfile) => {
|
|
268
|
-
const {visit} = await import('unist-util-visit');
|
|
269
|
-
|
|
270
269
|
const fileLoaderUtils = getFileLoaderUtils(
|
|
271
270
|
vfile.data.compilerName === 'server',
|
|
272
271
|
);
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import process from 'process';
|
|
9
|
+
import {visit} from 'unist-util-visit';
|
|
9
10
|
import logger from '@docusaurus/logger';
|
|
10
11
|
import {toMessageRelativeFilePath, posixPath} from '@docusaurus/utils';
|
|
11
12
|
import {formatNodePositionExtraMessage, transformNode} from '../utils';
|
|
@@ -138,9 +139,7 @@ const plugin: Plugin<PluginOptions[], Root> = function plugin(
|
|
|
138
139
|
options.onUnusedMarkdownDirectives,
|
|
139
140
|
);
|
|
140
141
|
|
|
141
|
-
return
|
|
142
|
-
const {visit} = await import('unist-util-visit');
|
|
143
|
-
|
|
142
|
+
return (tree, file) => {
|
|
144
143
|
const unusedDirectives: Directives[] = [];
|
|
145
144
|
|
|
146
145
|
// @ts-expect-error: TODO fix type
|