@docusaurus/mdx-loader 0.0.0-5701 → 0.0.0-5703
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 +16 -8
- package/lib/loader.js.map +1 -1
- package/lib/processor.d.ts +11 -2
- package/lib/processor.d.ts.map +1 -1
- package/lib/processor.js +18 -6
- package/lib/processor.js.map +1 -1
- package/lib/remark/contentTitle/index.d.ts +15 -0
- package/lib/remark/contentTitle/index.d.ts.map +1 -0
- package/lib/remark/contentTitle/index.js +38 -0
- package/lib/remark/contentTitle/index.js.map +1 -0
- package/package.json +8 -6
- package/src/loader.ts +21 -14
- package/src/processor.ts +23 -8
- package/src/remark/contentTitle/index.ts +53 -0
- package/src/remark/toc/index.ts +1 -1
package/lib/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,SAAS,CAAC;AAK3C,KAAK,SAAS,GAAG,GAAG,CAAC;AAMrB,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG;IAC1C,cAAc,EAAE,cAAc,CAAC;IAC/B,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;IAC7C,sCAAsC,CAAC,EAAE,OAAO,CAAC;IACjD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;IACvD,YAAY,CAAC,EAAE,CAAC,QAAQ,EAAE;QACxB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;QACtC,QAAQ,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACpC,KAAK;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChC,CAAC;AAsFF,wBAAsB,SAAS,CAC7B,IAAI,EAAE,aAAa,CAAC,OAAO,CAAC,EAC5B,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CA0Hf"}
|
package/lib/loader.js
CHANGED
|
@@ -77,19 +77,22 @@ function ensureMarkdownConfig(reqOptions) {
|
|
|
77
77
|
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* data.contentTitle is set by the remark contentTitle plugin
|
|
82
|
+
*/
|
|
83
|
+
function extractContentTitleData(data) {
|
|
84
|
+
return data.contentTitle;
|
|
85
|
+
}
|
|
80
86
|
async function mdxLoader(fileString) {
|
|
81
87
|
const callback = this.async();
|
|
82
88
|
const filePath = this.resourcePath;
|
|
83
89
|
const reqOptions = this.getOptions();
|
|
84
90
|
const { query } = this;
|
|
85
91
|
ensureMarkdownConfig(reqOptions);
|
|
86
|
-
const { frontMatter
|
|
92
|
+
const { frontMatter } = (0, utils_1.parseFrontMatter)(fileString);
|
|
87
93
|
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
const content = (0, preprocessor_1.default)({
|
|
92
|
-
fileContent: contentUnprocessed,
|
|
94
|
+
const preprocessedContent = (0, preprocessor_1.default)({
|
|
95
|
+
fileContent: fileString,
|
|
93
96
|
filePath,
|
|
94
97
|
admonitions: reqOptions.admonitions,
|
|
95
98
|
markdownConfig: reqOptions.markdownConfig,
|
|
@@ -103,7 +106,11 @@ async function mdxLoader(fileString) {
|
|
|
103
106
|
});
|
|
104
107
|
let result;
|
|
105
108
|
try {
|
|
106
|
-
result = await processor.process({
|
|
109
|
+
result = await processor.process({
|
|
110
|
+
content: preprocessedContent,
|
|
111
|
+
filePath,
|
|
112
|
+
frontMatter,
|
|
113
|
+
});
|
|
107
114
|
}
|
|
108
115
|
catch (errorUnknown) {
|
|
109
116
|
const error = errorUnknown;
|
|
@@ -118,6 +125,7 @@ async function mdxLoader(fileString) {
|
|
|
118
125
|
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
119
126
|
{ cause: error }));
|
|
120
127
|
}
|
|
128
|
+
const contentTitle = extractContentTitleData(result.data);
|
|
121
129
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
122
130
|
// Partial are not expected to have associated metadata files or front matter
|
|
123
131
|
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
|
|
@@ -167,7 +175,7 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
|
167
175
|
`;
|
|
168
176
|
const code = `
|
|
169
177
|
${exportsCode}
|
|
170
|
-
${result}
|
|
178
|
+
${result.content}
|
|
171
179
|
`;
|
|
172
180
|
return callback(null, code);
|
|
173
181
|
}
|
package/lib/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,gEAA0B;AAC1B,wEAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader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D,CAAC,CAAC,SAAS,CAAC;IAEhB,4EAA4E;IAC5E,6BAA6B;IAC7B,MAAM,WAAW,GAAG;6BACO,IAAA,0BAAe,EAAC,WAAW,CAAC;8BAC3B,IAAA,0BAAe,EAAC,YAAY,CAAC;EACzD,kBAAkB,CAAC,CAAC,CAAC,2BAA2B,kBAAkB,GAAG,CAAC,CAAC,CAAC,EAAE;EAC1E,MAAM,CAAC,CAAC,CAAC,yBAAyB,sBAAsB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE;CACzE,CAAC;IAEA,MAAM,IAAI,GAAG;EACb,WAAW;EACX,MAAM,CAAC,OAAO;CACf,CAAC;IAEA,OAAO,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AAC9B,CAAC;AA7HD,8BA6HC"}
|
package/lib/processor.d.ts
CHANGED
|
@@ -8,11 +8,20 @@ import type { MDXFrontMatter } from './frontMatter';
|
|
|
8
8
|
import type { Options } from './loader';
|
|
9
9
|
import type { AdmonitionOptions } from './remark/admonitions';
|
|
10
10
|
type Pluggable = any;
|
|
11
|
+
type SimpleProcessorResult = {
|
|
12
|
+
content: string;
|
|
13
|
+
data: {
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
11
17
|
type SimpleProcessor = {
|
|
12
|
-
process: ({ content, filePath, }: {
|
|
18
|
+
process: ({ content, filePath, frontMatter, }: {
|
|
13
19
|
content: string;
|
|
14
20
|
filePath: string;
|
|
15
|
-
|
|
21
|
+
frontMatter: {
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
}) => Promise<SimpleProcessorResult>;
|
|
16
25
|
};
|
|
17
26
|
export type MDXPlugin = Pluggable;
|
|
18
27
|
export type MDXOptions = {
|
package/lib/processor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;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C1C,QAAQ,EACR,cAAc,EACd,KAAK,EACL,UAAU,GACX,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC;IACxB,UAAU,EAAE,OAAO,CAAC;CACrB,GAAG,OAAO,CAAC,eAAe,CAAC,CAU3B"}
|
package/lib/processor.js
CHANGED
|
@@ -10,6 +10,7 @@ exports.createProcessorCached = exports.createProcessorUncached = void 0;
|
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const remark_emoji_1 = tslib_1.__importDefault(require("remark-emoji"));
|
|
12
12
|
const headings_1 = tslib_1.__importDefault(require("./remark/headings"));
|
|
13
|
+
const contentTitle_1 = tslib_1.__importDefault(require("./remark/contentTitle"));
|
|
13
14
|
const toc_1 = tslib_1.__importDefault(require("./remark/toc"));
|
|
14
15
|
const transformImage_1 = tslib_1.__importDefault(require("./remark/transformImage"));
|
|
15
16
|
const transformLinks_1 = tslib_1.__importDefault(require("./remark/transformLinks"));
|
|
@@ -38,17 +39,21 @@ function getAdmonitionsPlugins(admonitionsOption) {
|
|
|
38
39
|
// Need to be async due to ESM dynamic imports...
|
|
39
40
|
async function createProcessorFactory() {
|
|
40
41
|
const { createProcessor: createMdxProcessor } = await import('@mdx-js/mdx');
|
|
42
|
+
const { default: frontmatter } = await import('remark-frontmatter');
|
|
41
43
|
const { default: rehypeRaw } = await import('rehype-raw');
|
|
42
44
|
const { default: gfm } = await import('remark-gfm');
|
|
43
45
|
// TODO using fork until PR merged: https://github.com/leebyron/remark-comment/pull/3
|
|
44
46
|
const { default: comment } = await import('@slorber/remark-comment');
|
|
45
47
|
const { default: directive } = await import('remark-directive');
|
|
48
|
+
const { VFile } = await import('vfile');
|
|
46
49
|
// /!\ this method is synchronous on purpose
|
|
47
50
|
// Using async code here can create cache entry race conditions!
|
|
48
51
|
function createProcessorSync({ options, format, }) {
|
|
49
52
|
const remarkPlugins = [
|
|
50
53
|
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
54
|
+
frontmatter,
|
|
51
55
|
directive,
|
|
56
|
+
[contentTitle_1.default, { removeContentTitle: options.removeContentTitle }],
|
|
52
57
|
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
53
58
|
...DEFAULT_OPTIONS.remarkPlugins,
|
|
54
59
|
details_1.default,
|
|
@@ -109,12 +114,19 @@ async function createProcessorFactory() {
|
|
|
109
114
|
format,
|
|
110
115
|
});
|
|
111
116
|
return {
|
|
112
|
-
process: async ({ content, filePath }) =>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
117
|
+
process: async ({ content, filePath, frontMatter }) => {
|
|
118
|
+
const vfile = new VFile({
|
|
119
|
+
value: content,
|
|
120
|
+
path: filePath,
|
|
121
|
+
data: {
|
|
122
|
+
frontMatter,
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
return mdxProcessor.process(vfile).then((result) => ({
|
|
126
|
+
content: result.toString(),
|
|
127
|
+
data: result.data,
|
|
128
|
+
}));
|
|
129
|
+
},
|
|
118
130
|
};
|
|
119
131
|
}
|
|
120
132
|
return { createProcessorSync };
|
package/lib/processor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAiC;AACjC,yEAAyC;AACzC,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,oGAAoE;AACpE,qCAAmC;
|
|
1
|
+
{"version":3,"file":"processor.js","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wEAAiC;AACjC,yEAAyC;AACzC,iFAAiD;AACjD,+DAA+B;AAC/B,qFAAqD;AACrD,qFAAqD;AACrD,uEAAu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G,IAAI,GAAG,EAA0C,CAAC;AAE1E,KAAK,UAAU,0BAA0B,CAAC,EACxC,KAAK,EACL,UAAU,GAIX;IACC,MAAM,EAAC,mBAAmB,EAAC,GAAG,MAAM,sBAAsB,EAAE,CAAC;IAE7D,MAAM,SAAS,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC7C,IAAI,SAAS,EAAE;QACb,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,kBAAkB,GAAyB;QAC/C,WAAW,EAAE,mBAAmB,CAAC;YAC/B,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,IAAI;SACb,CAAC;QACF,YAAY,EAAE,mBAAmB,CAAC;YAChC,OAAO,EAAE,UAAU;YACnB,MAAM,EAAE,KAAK;SACd,CAAC;KACH,CAAC;IAEF,eAAe,CAAC,GAAG,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;IAE/C,OAAO,kBAAkB,CAAC;AAC5B,CAAC;AAEM,KAAK,UAAU,qBAAqB,CAAC,EAC1C,QAAQ,EACR,cAAc,EACd,KAAK,EACL,UAAU,GAMX;IACC,MAAM,SAAS,GAAG,MAAM,0BAA0B,CAAC,EAAC,KAAK,EAAE,UAAU,EAAC,CAAC,CAAC;IAExE,MAAM,MAAM,GAAG,IAAA,kBAAS,EAAC;QACvB,QAAQ;QACR,iBAAiB,EAAE,cAAc,CAAC,MAAM;QACxC,oBAAoB,EAAE,UAAU,CAAC,cAAc,CAAC,MAAM;KACvD,CAAC,CAAC;IAEH,OAAO,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,YAAY,CAAC;AAC1E,CAAC;AApBD,sDAoBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
type Plugin = any;
|
|
8
|
+
/**
|
|
9
|
+
* A remark plugin to extract the h1 heading found in Markdown files
|
|
10
|
+
* This is exposed as "data.contentTitle" to the processed vfile
|
|
11
|
+
* Also gives the ability to strip that content title (used for the blog plugin)
|
|
12
|
+
*/
|
|
13
|
+
declare const plugin: Plugin;
|
|
14
|
+
export default plugin;
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAWH,KAAK,MAAM,GAAG,GAAG,CAAC;AAMlB;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MAuBb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const unist_util_visit_1 = tslib_1.__importStar(require("unist-util-visit"));
|
|
11
|
+
/**
|
|
12
|
+
* A remark plugin to extract the h1 heading found in Markdown files
|
|
13
|
+
* This is exposed as "data.contentTitle" to the processed vfile
|
|
14
|
+
* Also gives the ability to strip that content title (used for the blog plugin)
|
|
15
|
+
*/
|
|
16
|
+
const plugin = function plugin(options = {}) {
|
|
17
|
+
// content title is
|
|
18
|
+
const removeContentTitle = options.removeContentTitle ?? false;
|
|
19
|
+
return async (root, vfile) => {
|
|
20
|
+
const { toString } = await import('mdast-util-to-string');
|
|
21
|
+
(0, unist_util_visit_1.default)(root, 'heading', (headingNode, index, parent) => {
|
|
22
|
+
if (headingNode.depth === 1) {
|
|
23
|
+
vfile.data.contentTitle = toString(headingNode);
|
|
24
|
+
if (removeContentTitle) {
|
|
25
|
+
parent.children.splice(index, 1);
|
|
26
|
+
}
|
|
27
|
+
return unist_util_visit_1.EXIT; // We only handle the very first heading
|
|
28
|
+
}
|
|
29
|
+
// We only handle contentTitle if it's the very first heading found
|
|
30
|
+
if (headingNode.depth >= 1) {
|
|
31
|
+
return unist_util_visit_1.EXIT;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
exports.default = plugin;
|
|
38
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6EAA6C;AAe7C;;;;GAIG;AACH,MAAM,MAAM,GAAW,SAAS,MAAM,CACpC,UAAyB,EAAE;IAE3B,mBAAmB;IACnB,MAAM,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,IAAI,KAAK,CAAC;IAE/D,OAAO,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;QACxD,IAAA,0BAAK,EAAC,IAAI,EAAE,SAAS,EAAE,CAAC,WAAoB,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAC7D,IAAI,WAAW,CAAC,KAAK,KAAK,CAAC,EAAE;gBAC3B,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;gBAChD,IAAI,kBAAkB,EAAE;oBACtB,MAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;iBACnC;gBACD,OAAO,uBAAI,CAAC,CAAC,wCAAwC;aACtD;YACD,mEAAmE;YACnE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,EAAE;gBAC1B,OAAO,uBAAI,CAAC;aACb;YACD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5703",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@babel/parser": "^7.22.7",
|
|
22
22
|
"@babel/traverse": "^7.22.8",
|
|
23
|
-
"@docusaurus/logger": "0.0.0-
|
|
24
|
-
"@docusaurus/utils": "0.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
23
|
+
"@docusaurus/logger": "0.0.0-5703",
|
|
24
|
+
"@docusaurus/utils": "0.0.0-5703",
|
|
25
|
+
"@docusaurus/utils-validation": "0.0.0-5703",
|
|
26
26
|
"@mdx-js/mdx": "^2.1.5",
|
|
27
27
|
"@slorber/remark-comment": "^1.0.0",
|
|
28
28
|
"escape-html": "^1.0.3",
|
|
@@ -36,16 +36,18 @@
|
|
|
36
36
|
"rehype-raw": "^6.1.1",
|
|
37
37
|
"remark-directive": "^2.0.1",
|
|
38
38
|
"remark-emoji": "^2.2.0",
|
|
39
|
+
"remark-frontmatter": "^5.0.0",
|
|
39
40
|
"remark-gfm": "^3.0.1",
|
|
40
41
|
"stringify-object": "^3.3.0",
|
|
41
42
|
"tslib": "^2.6.0",
|
|
42
43
|
"unified": "^10.1.2",
|
|
43
44
|
"unist-util-visit": "^2.0.3",
|
|
44
45
|
"url-loader": "^4.1.1",
|
|
46
|
+
"vfile": "^5.3.7",
|
|
45
47
|
"webpack": "^5.88.1"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@docusaurus/types": "0.0.0-
|
|
50
|
+
"@docusaurus/types": "0.0.0-5703",
|
|
49
51
|
"@types/escape-html": "^1.0.2",
|
|
50
52
|
"@types/mdast": "^3.0.12",
|
|
51
53
|
"@types/stringify-object": "^3.3.1",
|
|
@@ -65,5 +67,5 @@
|
|
|
65
67
|
"engines": {
|
|
66
68
|
"node": ">=18.0"
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "b6502cb137998f5080cb59141cdc8979bbf4ce62"
|
|
69
71
|
}
|
package/src/loader.ts
CHANGED
|
@@ -9,7 +9,6 @@ import fs from 'fs-extra';
|
|
|
9
9
|
import logger from '@docusaurus/logger';
|
|
10
10
|
import {
|
|
11
11
|
parseFrontMatter,
|
|
12
|
-
parseMarkdownContentTitle,
|
|
13
12
|
escapePath,
|
|
14
13
|
getFileLoaderUtils,
|
|
15
14
|
} from '@docusaurus/utils';
|
|
@@ -122,6 +121,15 @@ function ensureMarkdownConfig(reqOptions: Options) {
|
|
|
122
121
|
}
|
|
123
122
|
}
|
|
124
123
|
|
|
124
|
+
/**
|
|
125
|
+
* data.contentTitle is set by the remark contentTitle plugin
|
|
126
|
+
*/
|
|
127
|
+
function extractContentTitleData(data: {
|
|
128
|
+
[key: string]: unknown;
|
|
129
|
+
}): string | undefined {
|
|
130
|
+
return data.contentTitle as string | undefined;
|
|
131
|
+
}
|
|
132
|
+
|
|
125
133
|
export async function mdxLoader(
|
|
126
134
|
this: LoaderContext<Options>,
|
|
127
135
|
fileString: string,
|
|
@@ -132,18 +140,11 @@ export async function mdxLoader(
|
|
|
132
140
|
const {query} = this;
|
|
133
141
|
ensureMarkdownConfig(reqOptions);
|
|
134
142
|
|
|
135
|
-
const {frontMatter
|
|
143
|
+
const {frontMatter} = parseFrontMatter(fileString);
|
|
136
144
|
const mdxFrontMatter = validateMDXFrontMatter(frontMatter.mdx);
|
|
137
145
|
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
{
|
|
141
|
-
removeContentTitle: reqOptions.removeContentTitle,
|
|
142
|
-
},
|
|
143
|
-
);
|
|
144
|
-
|
|
145
|
-
const content = preprocessor({
|
|
146
|
-
fileContent: contentUnprocessed,
|
|
146
|
+
const preprocessedContent = preprocessor({
|
|
147
|
+
fileContent: fileString,
|
|
147
148
|
filePath,
|
|
148
149
|
admonitions: reqOptions.admonitions,
|
|
149
150
|
markdownConfig: reqOptions.markdownConfig,
|
|
@@ -158,9 +159,13 @@ export async function mdxLoader(
|
|
|
158
159
|
mdxFrontMatter,
|
|
159
160
|
});
|
|
160
161
|
|
|
161
|
-
let result: string;
|
|
162
|
+
let result: {content: string; data: {[key: string]: unknown}};
|
|
162
163
|
try {
|
|
163
|
-
result = await processor.process({
|
|
164
|
+
result = await processor.process({
|
|
165
|
+
content: preprocessedContent,
|
|
166
|
+
filePath,
|
|
167
|
+
frontMatter,
|
|
168
|
+
});
|
|
164
169
|
} catch (errorUnknown) {
|
|
165
170
|
const error = errorUnknown as Error;
|
|
166
171
|
|
|
@@ -184,6 +189,8 @@ export async function mdxLoader(
|
|
|
184
189
|
);
|
|
185
190
|
}
|
|
186
191
|
|
|
192
|
+
const contentTitle = extractContentTitleData(result.data);
|
|
193
|
+
|
|
187
194
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
188
195
|
// Partial are not expected to have associated metadata files or front matter
|
|
189
196
|
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
|
|
@@ -244,7 +251,7 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
|
244
251
|
|
|
245
252
|
const code = `
|
|
246
253
|
${exportsCode}
|
|
247
|
-
${result}
|
|
254
|
+
${result.content}
|
|
248
255
|
`;
|
|
249
256
|
|
|
250
257
|
return callback(null, code);
|
package/src/processor.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import emoji from 'remark-emoji';
|
|
9
9
|
import headings from './remark/headings';
|
|
10
|
+
import contentTitle from './remark/contentTitle';
|
|
10
11
|
import toc from './remark/toc';
|
|
11
12
|
import transformImage from './remark/transformImage';
|
|
12
13
|
import transformLinks from './remark/transformLinks';
|
|
@@ -28,15 +29,19 @@ import type {ProcessorOptions} from '@mdx-js/mdx';
|
|
|
28
29
|
// See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
|
|
29
30
|
type Pluggable = any; // TODO fix this asap
|
|
30
31
|
|
|
32
|
+
type SimpleProcessorResult = {content: string; data: {[key: string]: unknown}};
|
|
33
|
+
|
|
31
34
|
// TODO alt interface because impossible to import type Processor (ESM + TS :/)
|
|
32
35
|
type SimpleProcessor = {
|
|
33
36
|
process: ({
|
|
34
37
|
content,
|
|
35
38
|
filePath,
|
|
39
|
+
frontMatter,
|
|
36
40
|
}: {
|
|
37
41
|
content: string;
|
|
38
42
|
filePath: string;
|
|
39
|
-
|
|
43
|
+
frontMatter: {[key: string]: unknown};
|
|
44
|
+
}) => Promise<SimpleProcessorResult>;
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
const DEFAULT_OPTIONS: MDXOptions = {
|
|
@@ -74,11 +79,13 @@ function getAdmonitionsPlugins(
|
|
|
74
79
|
// Need to be async due to ESM dynamic imports...
|
|
75
80
|
async function createProcessorFactory() {
|
|
76
81
|
const {createProcessor: createMdxProcessor} = await import('@mdx-js/mdx');
|
|
82
|
+
const {default: frontmatter} = await import('remark-frontmatter');
|
|
77
83
|
const {default: rehypeRaw} = await import('rehype-raw');
|
|
78
84
|
const {default: gfm} = await import('remark-gfm');
|
|
79
85
|
// TODO using fork until PR merged: https://github.com/leebyron/remark-comment/pull/3
|
|
80
86
|
const {default: comment} = await import('@slorber/remark-comment');
|
|
81
87
|
const {default: directive} = await import('remark-directive');
|
|
88
|
+
const {VFile} = await import('vfile');
|
|
82
89
|
|
|
83
90
|
// /!\ this method is synchronous on purpose
|
|
84
91
|
// Using async code here can create cache entry race conditions!
|
|
@@ -91,7 +98,9 @@ async function createProcessorFactory() {
|
|
|
91
98
|
}): SimpleProcessor {
|
|
92
99
|
const remarkPlugins: MDXPlugin[] = [
|
|
93
100
|
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
101
|
+
frontmatter,
|
|
94
102
|
directive,
|
|
103
|
+
[contentTitle, {removeContentTitle: options.removeContentTitle}],
|
|
95
104
|
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
96
105
|
...DEFAULT_OPTIONS.remarkPlugins,
|
|
97
106
|
details,
|
|
@@ -158,13 +167,19 @@ async function createProcessorFactory() {
|
|
|
158
167
|
});
|
|
159
168
|
|
|
160
169
|
return {
|
|
161
|
-
process: async ({content, filePath}) =>
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
170
|
+
process: async ({content, filePath, frontMatter}) => {
|
|
171
|
+
const vfile = new VFile({
|
|
172
|
+
value: content,
|
|
173
|
+
path: filePath,
|
|
174
|
+
data: {
|
|
175
|
+
frontMatter,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
return mdxProcessor.process(vfile).then((result) => ({
|
|
179
|
+
content: result.toString(),
|
|
180
|
+
data: result.data,
|
|
181
|
+
}));
|
|
182
|
+
},
|
|
168
183
|
};
|
|
169
184
|
}
|
|
170
185
|
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import visit, {EXIT} from 'unist-util-visit';
|
|
9
|
+
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
10
|
+
import type {Transformer} from 'unified';
|
|
11
|
+
import type {Heading} from 'mdast';
|
|
12
|
+
|
|
13
|
+
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
14
|
+
// TODO upgrade to TS 5.3
|
|
15
|
+
// See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
|
|
16
|
+
// import type {Plugin} from 'unified';
|
|
17
|
+
type Plugin = any; // TODO fix this asap
|
|
18
|
+
|
|
19
|
+
interface PluginOptions {
|
|
20
|
+
removeContentTitle?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* A remark plugin to extract the h1 heading found in Markdown files
|
|
25
|
+
* This is exposed as "data.contentTitle" to the processed vfile
|
|
26
|
+
* Also gives the ability to strip that content title (used for the blog plugin)
|
|
27
|
+
*/
|
|
28
|
+
const plugin: Plugin = function plugin(
|
|
29
|
+
options: PluginOptions = {},
|
|
30
|
+
): Transformer {
|
|
31
|
+
// content title is
|
|
32
|
+
const removeContentTitle = options.removeContentTitle ?? false;
|
|
33
|
+
|
|
34
|
+
return async (root, vfile) => {
|
|
35
|
+
const {toString} = await import('mdast-util-to-string');
|
|
36
|
+
visit(root, 'heading', (headingNode: Heading, index, parent) => {
|
|
37
|
+
if (headingNode.depth === 1) {
|
|
38
|
+
vfile.data.contentTitle = toString(headingNode);
|
|
39
|
+
if (removeContentTitle) {
|
|
40
|
+
parent!.children.splice(index, 1);
|
|
41
|
+
}
|
|
42
|
+
return EXIT; // We only handle the very first heading
|
|
43
|
+
}
|
|
44
|
+
// We only handle contentTitle if it's the very first heading found
|
|
45
|
+
if (headingNode.depth >= 1) {
|
|
46
|
+
return EXIT;
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export default plugin;
|
package/src/remark/toc/index.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type {Heading, Literal} from 'mdast';
|
|
|
17
17
|
import type {Transformer} from 'unified';
|
|
18
18
|
|
|
19
19
|
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
20
|
-
//
|
|
20
|
+
// TODO upgrade to TS 5.3
|
|
21
21
|
// See https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1517839391
|
|
22
22
|
// import type {Plugin} from 'unified';
|
|
23
23
|
type Plugin = any; // TODO fix this asap
|