@docusaurus/mdx-loader 3.0.0-alpha.0 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/format.d.ts +4 -2
- package/lib/format.d.ts.map +1 -1
- package/lib/format.js +14 -7
- package/lib/format.js.map +1 -1
- package/lib/frontMatter.d.ts +2 -1
- package/lib/frontMatter.d.ts.map +1 -1
- package/lib/frontMatter.js +2 -4
- package/lib/frontMatter.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/loader.d.ts.map +1 -1
- package/lib/loader.js +26 -12
- 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 +22 -8
- 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/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +16 -2
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +19 -17
- package/src/format.ts +17 -7
- package/src/frontMatter.ts +5 -5
- package/src/index.ts +4 -0
- package/src/loader.ts +36 -18
- package/src/processor.ts +27 -10
- package/src/remark/contentTitle/index.ts +53 -0
- package/src/remark/toc/index.ts +1 -1
- package/src/remark/utils/index.ts +36 -5
package/lib/format.d.ts
CHANGED
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { MDXFrontMatter } from './frontMatter';
|
|
8
|
-
|
|
8
|
+
import type { Format, FormatInput } from './index';
|
|
9
|
+
export declare function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }: {
|
|
9
10
|
filePath: string;
|
|
10
11
|
frontMatterFormat: MDXFrontMatter['format'];
|
|
11
|
-
|
|
12
|
+
markdownConfigFormat: FormatInput;
|
|
13
|
+
}): Format;
|
|
12
14
|
//# sourceMappingURL=format.d.ts.map
|
package/lib/format.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,MAAM,EAAE,WAAW,EAAC,MAAM,SAAS,CAAC;AAqBjD,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GACrB,EAAE;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC5C,oBAAoB,EAAE,WAAW,CAAC;CACnC,GAAG,MAAM,CAWT"}
|
package/lib/format.js
CHANGED
|
@@ -21,15 +21,22 @@ const mdFormatExtensions = [
|
|
|
21
21
|
'.mkdown',
|
|
22
22
|
'.ron',
|
|
23
23
|
];
|
|
24
|
-
function
|
|
25
|
-
|
|
24
|
+
function getExtensionFormat(filepath) {
|
|
25
|
+
const isMDFormat = mdFormatExtensions.includes(path_1.default.extname(filepath));
|
|
26
|
+
// Bias toward mdx if unknown extension
|
|
27
|
+
return isMDFormat ? 'md' : 'mdx';
|
|
26
28
|
}
|
|
27
|
-
function getFormat({ filePath, frontMatterFormat, }) {
|
|
28
|
-
if (frontMatterFormat
|
|
29
|
-
|
|
29
|
+
function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }) {
|
|
30
|
+
if (frontMatterFormat) {
|
|
31
|
+
if (frontMatterFormat !== 'detect') {
|
|
32
|
+
return frontMatterFormat;
|
|
33
|
+
}
|
|
34
|
+
return getExtensionFormat(filePath);
|
|
30
35
|
}
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
if (markdownConfigFormat !== 'detect') {
|
|
37
|
+
return markdownConfigFormat;
|
|
38
|
+
}
|
|
39
|
+
return getExtensionFormat(filePath);
|
|
33
40
|
}
|
|
34
41
|
exports.getFormat = getFormat;
|
|
35
42
|
//# sourceMappingURL=format.js.map
|
package/lib/format.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;AAIxB,kEAAkE;AAClE,0DAA0D;AAC1D,MAAM,kBAAkB,GAAG;IACzB,KAAK;IACL,WAAW;IACX,QAAQ;IACR,OAAO;IACP,MAAM;IACN,OAAO;IACP,SAAS;IACT,MAAM;CACP,CAAC;AAEF,SAAS,kBAAkB,CAAC,QAAgB;IAC1C,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IACvE,uCAAuC;IACvC,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACnC,CAAC;AAED,SAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,iBAAiB,EACjB,oBAAoB,GAKrB;IACC,IAAI,iBAAiB,EAAE;QACrB,IAAI,iBAAiB,KAAK,QAAQ,EAAE;YAClC,OAAO,iBAAiB,CAAC;SAC1B;QACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;KACrC;IACD,IAAI,oBAAoB,KAAK,QAAQ,EAAE;QACrC,OAAO,oBAAoB,CAAC;KAC7B;IACD,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;AACtC,CAAC;AAnBD,8BAmBC"}
|
package/lib/frontMatter.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
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 { FormatInput } from './index';
|
|
7
8
|
export type MDXFrontMatter = {
|
|
8
|
-
format
|
|
9
|
+
format?: FormatInput;
|
|
9
10
|
};
|
|
10
11
|
export declare const DefaultMDXFrontMatter: MDXFrontMatter;
|
|
11
12
|
export declare function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter;
|
package/lib/frontMatter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontMatter.d.ts","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"frontMatter.d.ts","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,SAAS,CAAC;AAEzC,MAAM,MAAM,cAAc,GAAG;IAC3B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,cAEnC,CAAC;AAMF,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,OAAO,GAAG,cAAc,CAI3E"}
|
package/lib/frontMatter.js
CHANGED
|
@@ -9,12 +9,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.validateMDXFrontMatter = exports.DefaultMDXFrontMatter = void 0;
|
|
10
10
|
const utils_validation_1 = require("@docusaurus/utils-validation");
|
|
11
11
|
exports.DefaultMDXFrontMatter = {
|
|
12
|
-
format:
|
|
12
|
+
format: undefined,
|
|
13
13
|
};
|
|
14
14
|
const MDXFrontMatterSchema = utils_validation_1.JoiFrontMatter.object({
|
|
15
|
-
format: utils_validation_1.JoiFrontMatter.string()
|
|
16
|
-
.equal('md', 'mdx', 'detect')
|
|
17
|
-
.default(exports.DefaultMDXFrontMatter.format),
|
|
15
|
+
format: utils_validation_1.JoiFrontMatter.string().equal('md', 'mdx', 'detect').optional(),
|
|
18
16
|
}).default(exports.DefaultMDXFrontMatter);
|
|
19
17
|
function validateMDXFrontMatter(frontMatter) {
|
|
20
18
|
return (0, utils_validation_1.validateFrontMatter)(frontMatter, MDXFrontMatterSchema, {
|
package/lib/frontMatter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frontMatter.js","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAGsC;
|
|
1
|
+
{"version":3,"file":"frontMatter.js","sourceRoot":"","sources":["../src/frontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mEAGsC;AAQzB,QAAA,qBAAqB,GAAmB;IACnD,MAAM,EAAE,SAAS;CAClB,CAAC;AAEF,MAAM,oBAAoB,GAAG,iCAAG,CAAC,MAAM,CAAiB;IACtD,MAAM,EAAE,iCAAG,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;CAC7D,CAAC,CAAC,OAAO,CAAC,6BAAqB,CAAC,CAAC;AAElC,SAAgB,sBAAsB,CAAC,WAAoB;IACzD,OAAO,IAAA,sCAAmB,EAAC,WAAW,EAAE,oBAAoB,EAAE;QAC5D,YAAY,EAAE,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAJD,wDAIC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ import { mdxLoader } from './loader';
|
|
|
8
8
|
import type { TOCItem as TOCItemImported } from './remark/toc';
|
|
9
9
|
export default mdxLoader;
|
|
10
10
|
export type TOCItem = TOCItemImported;
|
|
11
|
+
export type Format = 'md' | 'mdx';
|
|
12
|
+
export type FormatInput = Format | 'detect';
|
|
11
13
|
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
12
14
|
/** As verbatim declared in the MDX document. */
|
|
13
15
|
readonly frontMatter: FrontMatter;
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7D,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AACjD,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AAEnC,OAAO,KAAK,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,cAAc,CAAC;AAE7D,eAAe,SAAS,CAAC;AAEzB,MAAM,MAAM,OAAO,GAAG,eAAe,CAAC;AAEtC,MAAM,MAAM,MAAM,GAAG,IAAI,GAAG,KAAK,CAAC;AAElC,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,QAAQ,CAAC;AAE5C,MAAM,MAAM,gBAAgB,CAAC,WAAW,EAAE,QAAQ,EAAE,MAAM,GAAG,SAAS,IAAI;IACxE,gDAAgD;IAChD,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC;IAClC,yCAAyC;IACzC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,sCAAsC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACjC,yCAAyC;IACzC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,IAAI,GAAG,CAAC,OAAO,CAAC;CACjB,CAAC;AAEF,YAAY,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,UAAU,CAAC;AACjD,YAAY,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC"}
|
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
|
@@ -15,7 +15,7 @@ const stringify_object_1 = tslib_1.__importDefault(require("stringify-object"));
|
|
|
15
15
|
const preprocessor_1 = tslib_1.__importDefault(require("./preprocessor"));
|
|
16
16
|
const frontMatter_1 = require("./frontMatter");
|
|
17
17
|
const processor_1 = require("./processor");
|
|
18
|
-
const { loaders: {
|
|
18
|
+
const { loaders: { inlineMarkdownAssetImageFileLoader }, } = (0, utils_1.getFileLoaderUtils)();
|
|
19
19
|
/**
|
|
20
20
|
* When this throws, it generally means that there's no metadata file associated
|
|
21
21
|
* with this MDX document. It can happen when using MDX partials (usually
|
|
@@ -56,8 +56,7 @@ function createAssetsExportCode(assets) {
|
|
|
56
56
|
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
|
|
57
57
|
// TODO do we have other use-cases than image assets?
|
|
58
58
|
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
|
|
59
|
-
|
|
60
|
-
return `require("${inlineLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
|
|
59
|
+
return `require("${inlineMarkdownAssetImageFileLoader}${(0, utils_1.escapePath)(assetValue)}").default`;
|
|
61
60
|
}
|
|
62
61
|
return undefined;
|
|
63
62
|
}
|
|
@@ -78,19 +77,22 @@ function ensureMarkdownConfig(reqOptions) {
|
|
|
78
77
|
throw new Error('Docusaurus v3+ requires MDX loader options.markdownConfig - plugin authors using the MDX loader should make sure to provide that option');
|
|
79
78
|
}
|
|
80
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* data.contentTitle is set by the remark contentTitle plugin
|
|
82
|
+
*/
|
|
83
|
+
function extractContentTitleData(data) {
|
|
84
|
+
return data.contentTitle;
|
|
85
|
+
}
|
|
81
86
|
async function mdxLoader(fileString) {
|
|
82
87
|
const callback = this.async();
|
|
83
88
|
const filePath = this.resourcePath;
|
|
84
89
|
const reqOptions = this.getOptions();
|
|
85
90
|
const { query } = this;
|
|
86
91
|
ensureMarkdownConfig(reqOptions);
|
|
87
|
-
const { frontMatter
|
|
92
|
+
const { frontMatter } = (0, utils_1.parseFrontMatter)(fileString);
|
|
88
93
|
const mdxFrontMatter = (0, frontMatter_1.validateMDXFrontMatter)(frontMatter.mdx);
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
});
|
|
92
|
-
const content = (0, preprocessor_1.default)({
|
|
93
|
-
fileContent: contentUnprocessed,
|
|
94
|
+
const preprocessedContent = (0, preprocessor_1.default)({
|
|
95
|
+
fileContent: fileString,
|
|
94
96
|
filePath,
|
|
95
97
|
admonitions: reqOptions.admonitions,
|
|
96
98
|
markdownConfig: reqOptions.markdownConfig,
|
|
@@ -104,14 +106,26 @@ async function mdxLoader(fileString) {
|
|
|
104
106
|
});
|
|
105
107
|
let result;
|
|
106
108
|
try {
|
|
107
|
-
result = await processor.process({
|
|
109
|
+
result = await processor.process({
|
|
110
|
+
content: preprocessedContent,
|
|
111
|
+
filePath,
|
|
112
|
+
frontMatter,
|
|
113
|
+
});
|
|
108
114
|
}
|
|
109
115
|
catch (errorUnknown) {
|
|
110
116
|
const error = errorUnknown;
|
|
111
|
-
|
|
117
|
+
// MDX can emit errors that have useful extra attributes
|
|
118
|
+
const errorJSON = JSON.stringify(error, null, 2);
|
|
119
|
+
const errorDetails = errorJSON === '{}'
|
|
120
|
+
? // regular JS error case: print stacktrace
|
|
121
|
+
error.stack ?? 'N/A'
|
|
122
|
+
: // MDX error: print extra attributes + stacktrace
|
|
123
|
+
`${errorJSON}\n${error.stack}`;
|
|
124
|
+
return callback(new Error(`MDX compilation failed for file ${logger_1.default.path(filePath)}\nCause: ${error.message}\nDetails:\n${errorDetails}`,
|
|
112
125
|
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
113
126
|
{ cause: error }));
|
|
114
127
|
}
|
|
128
|
+
const contentTitle = extractContentTitleData(result.data);
|
|
115
129
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
116
130
|
// Partial are not expected to have associated metadata files or front matter
|
|
117
131
|
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
|
|
@@ -161,7 +175,7 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
|
161
175
|
`;
|
|
162
176
|
const code = `
|
|
163
177
|
${exportsCode}
|
|
164
|
-
${result}
|
|
178
|
+
${result.content}
|
|
165
179
|
`;
|
|
166
180
|
return callback(null, code);
|
|
167
181
|
}
|
package/lib/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":";AAAA;;;;;G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,IAAI,QAAQ;QACjC,CAAC,CAAC,UAAU,CAAC,YAAY,CAAC,EAAC,WAAW,EAAE,QAAQ,EAAC,CAAC;QAClD,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;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"processor.d.ts","sourceRoot":"","sources":["../src/processor.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAcH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,UAAU,CAAC;AACtC,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAQ5D,KAAK,SAAS,GAAG,GAAG,CAAC;AAErB,KAAK,qBAAqB,GAAG;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAA;CAAC,CAAC;AAG/E,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,CAAC,EACR,OAAO,EACP,QAAQ,EACR,WAAW,GACZ,EAAE;QACD,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE,MAAM,CAAC;QACjB,WAAW,EAAE;YAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;SAAC,CAAC;KACvC,KAAK,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACtC,CAAC;AAUF,MAAM,MAAM,SAAS,GAAG,SAAS,CAAC;AAElC,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,OAAO,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClD,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,aAAa,EAAE,SAAS,EAAE,CAAC;IAC3B,0BAA0B,EAAE,SAAS,EAAE,CAAC;IACxC,0BAA0B,EAAE,SAAS,EAAE,CAAC;CACzC,CAAC;AA+HF,wBAAsB,uBAAuB,CAAC,UAAU,EAAE;IACxD,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC;CACtB,GAAG,OAAO,CAAC,eAAe,CAAC,CAG3B;AA0CD,wBAAsB,qBAAqB,CAAC,EAC1C,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"));
|
|
@@ -22,7 +23,7 @@ const format_1 = require("./format");
|
|
|
22
23
|
const DEFAULT_OPTIONS = {
|
|
23
24
|
admonitions: true,
|
|
24
25
|
rehypePlugins: [],
|
|
25
|
-
remarkPlugins: [
|
|
26
|
+
remarkPlugins: [headings_1.default, remark_emoji_1.default, toc_1.default],
|
|
26
27
|
beforeDefaultRemarkPlugins: [],
|
|
27
28
|
beforeDefaultRehypePlugins: [],
|
|
28
29
|
};
|
|
@@ -38,16 +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
|
|
46
|
+
const { default: comment } = await import('@slorber/remark-comment');
|
|
44
47
|
const { default: directive } = await import('remark-directive');
|
|
48
|
+
const { VFile } = await import('vfile');
|
|
45
49
|
// /!\ this method is synchronous on purpose
|
|
46
50
|
// Using async code here can create cache entry race conditions!
|
|
47
51
|
function createProcessorSync({ options, format, }) {
|
|
48
52
|
const remarkPlugins = [
|
|
49
53
|
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
54
|
+
frontmatter,
|
|
50
55
|
directive,
|
|
56
|
+
[contentTitle_1.default, { removeContentTitle: options.removeContentTitle }],
|
|
51
57
|
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
52
58
|
...DEFAULT_OPTIONS.remarkPlugins,
|
|
53
59
|
details_1.default,
|
|
@@ -108,12 +114,19 @@ async function createProcessorFactory() {
|
|
|
108
114
|
format,
|
|
109
115
|
});
|
|
110
116
|
return {
|
|
111
|
-
process: async ({ content, filePath }) =>
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
+
},
|
|
117
130
|
};
|
|
118
131
|
}
|
|
119
132
|
return { createProcessorSync };
|
|
@@ -151,6 +164,7 @@ async function createProcessorCached({ filePath, mdxFrontMatter, query, reqOptio
|
|
|
151
164
|
const format = (0, format_1.getFormat)({
|
|
152
165
|
filePath,
|
|
153
166
|
frontMatterFormat: mdxFrontMatter.format,
|
|
167
|
+
markdownConfigFormat: reqOptions.markdownConfig.format,
|
|
154
168
|
});
|
|
155
169
|
return format === 'md' ? compilers.mdProcessor : compilers.mdxProcessor;
|
|
156
170
|
}
|
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,uEAAuC;AACvC,iEAAiC;AACjC,uEAAuC;AACvC,+EAAwD;AACxD,oGAAoE;AACpE,qCAAmC;AA4BnC,MAAM,eAAe,GAAe;IAClC,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,EAAE;IACjB,aAAa,EAAE,CAAC,kBAAQ,EAAE,sBAAK,EAAE,aAAG,CAAC;IACrC,0BAA0B,EAAE,EAAE;IAC9B,0BAA0B,EAAE,EAAE;CAC/B,CAAC;AAYF,SAAS,qBAAqB,CAC5B,iBAA4C;IAE5C,IAAI,iBAAiB,EAAE;QACrB,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;KACjB;IAED,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,iDAAiD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E/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"}
|
|
@@ -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;AAClC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,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,EAAC,MAAM,OAAO,CAAC;AAClC,OAAO,KAAK,EAAC,eAAe,EAAE,OAAO,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,KAAK,EAEV,8BAA8B,EAG/B,MAAM,gBAAgB,CAAC;AAExB,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,EAC/B,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"}
|
|
@@ -15,11 +15,25 @@ function stringifyContent(node, toString) {
|
|
|
15
15
|
.join('');
|
|
16
16
|
}
|
|
17
17
|
exports.stringifyContent = stringifyContent;
|
|
18
|
+
// TODO This is really a workaround, and not super reliable
|
|
19
|
+
// For now we only support serializing tagName, className and content
|
|
20
|
+
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
21
|
+
function mdxJsxTextElementToHtml(element, toString) {
|
|
22
|
+
const tag = element.name;
|
|
23
|
+
const attributes = element.attributes.filter((child) => child.type === 'mdxJsxAttribute');
|
|
24
|
+
const classAttribute = attributes.find((attr) => attr.name === 'className') ??
|
|
25
|
+
attributes.find((attr) => attr.name === 'class');
|
|
26
|
+
const classAttributeString = classAttribute
|
|
27
|
+
? `class="${(0, escape_html_1.default)(String(classAttribute.value))}"`
|
|
28
|
+
: ``;
|
|
29
|
+
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
30
|
+
const content = stringifyContent(element, toString);
|
|
31
|
+
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
32
|
+
}
|
|
18
33
|
function toValue(node, toString) {
|
|
19
34
|
switch (node.type) {
|
|
20
35
|
case 'mdxJsxTextElement': {
|
|
21
|
-
|
|
22
|
-
return `<${tag}>${stringifyContent(node, toString)}</${tag}>`;
|
|
36
|
+
return mdxJsxTextElementToHtml(node, toString);
|
|
23
37
|
}
|
|
24
38
|
case 'text':
|
|
25
39
|
return (0, escape_html_1.default)(node.value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,sEAAqC;
|
|
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,CACtE,CAAC;IAEF,MAAM,cAAc,GAClB,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;QACpD,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;IAEnD,MAAM,oBAAoB,GAAG,cAAc;QACzC,CAAC,CAAC,UAAU,IAAA,qBAA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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;AArDD,gEAqDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,40 +18,42 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@babel/parser": "^7.
|
|
22
|
-
"@babel/traverse": "^7.
|
|
23
|
-
"@docusaurus/logger": "3.0.0-
|
|
24
|
-
"@docusaurus/utils": "3.0.0-
|
|
25
|
-
"@docusaurus/utils-validation": "3.0.0-
|
|
21
|
+
"@babel/parser": "^7.22.7",
|
|
22
|
+
"@babel/traverse": "^7.22.8",
|
|
23
|
+
"@docusaurus/logger": "3.0.0-rc.0",
|
|
24
|
+
"@docusaurus/utils": "3.0.0-rc.0",
|
|
25
|
+
"@docusaurus/utils-validation": "3.0.0-rc.0",
|
|
26
26
|
"@mdx-js/mdx": "^2.1.5",
|
|
27
|
+
"@slorber/remark-comment": "^1.0.0",
|
|
27
28
|
"escape-html": "^1.0.3",
|
|
28
29
|
"estree-util-value-to-estree": "^2.1.0",
|
|
29
30
|
"file-loader": "^6.2.0",
|
|
30
|
-
"fs-extra": "^11.1.
|
|
31
|
+
"fs-extra": "^11.1.1",
|
|
31
32
|
"hastscript": "^7.1.0",
|
|
32
33
|
"image-size": "^1.0.2",
|
|
33
34
|
"mdast-util-mdx": "^2.0.0",
|
|
34
|
-
"mdast-util-to-string": "^3.
|
|
35
|
+
"mdast-util-to-string": "^3.2.0",
|
|
35
36
|
"rehype-raw": "^6.1.1",
|
|
36
|
-
"remark-comment": "^1.0.0",
|
|
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
|
-
"tslib": "^2.
|
|
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",
|
|
45
|
-
"
|
|
46
|
+
"vfile": "^5.3.7",
|
|
47
|
+
"webpack": "^5.88.1"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@docusaurus/types": "3.0.0-
|
|
50
|
+
"@docusaurus/types": "3.0.0-rc.0",
|
|
49
51
|
"@types/escape-html": "^1.0.2",
|
|
50
|
-
"@types/mdast": "^3.0.
|
|
52
|
+
"@types/mdast": "^3.0.12",
|
|
51
53
|
"@types/stringify-object": "^3.3.1",
|
|
52
|
-
"@types/unist": "^2.0.
|
|
54
|
+
"@types/unist": "^2.0.7",
|
|
53
55
|
"rehype-stringify": "^8.0.0",
|
|
54
|
-
"remark": "^14.0.
|
|
56
|
+
"remark": "^14.0.3",
|
|
55
57
|
"remark-mdx": "^2.1.5",
|
|
56
58
|
"remark-rehype": "^8.1.0",
|
|
57
59
|
"to-vfile": "^6.1.0",
|
|
@@ -63,7 +65,7 @@
|
|
|
63
65
|
"react-dom": "^18.0.0"
|
|
64
66
|
},
|
|
65
67
|
"engines": {
|
|
66
|
-
"node": ">=
|
|
68
|
+
"node": ">=18.0"
|
|
67
69
|
},
|
|
68
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "e66dfe04d2972edce66f431908470c61340f8ffc"
|
|
69
71
|
}
|
package/src/format.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import type {MDXFrontMatter} from './frontMatter';
|
|
10
|
+
import type {Format, FormatInput} from './index';
|
|
10
11
|
|
|
11
12
|
// Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions
|
|
12
13
|
// Although we are likely to only use .md / .mdx anyway...
|
|
@@ -21,20 +22,29 @@ const mdFormatExtensions = [
|
|
|
21
22
|
'.ron',
|
|
22
23
|
];
|
|
23
24
|
|
|
24
|
-
function
|
|
25
|
-
|
|
25
|
+
function getExtensionFormat(filepath: string): Format {
|
|
26
|
+
const isMDFormat = mdFormatExtensions.includes(path.extname(filepath));
|
|
27
|
+
// Bias toward mdx if unknown extension
|
|
28
|
+
return isMDFormat ? 'md' : 'mdx';
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
export function getFormat({
|
|
29
32
|
filePath,
|
|
30
33
|
frontMatterFormat,
|
|
34
|
+
markdownConfigFormat,
|
|
31
35
|
}: {
|
|
32
36
|
filePath: string;
|
|
33
37
|
frontMatterFormat: MDXFrontMatter['format'];
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
markdownConfigFormat: FormatInput;
|
|
39
|
+
}): Format {
|
|
40
|
+
if (frontMatterFormat) {
|
|
41
|
+
if (frontMatterFormat !== 'detect') {
|
|
42
|
+
return frontMatterFormat;
|
|
43
|
+
}
|
|
44
|
+
return getExtensionFormat(filePath);
|
|
37
45
|
}
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
if (markdownConfigFormat !== 'detect') {
|
|
47
|
+
return markdownConfigFormat;
|
|
48
|
+
}
|
|
49
|
+
return getExtensionFormat(filePath);
|
|
40
50
|
}
|
package/src/frontMatter.ts
CHANGED
|
@@ -10,18 +10,18 @@ import {
|
|
|
10
10
|
validateFrontMatter,
|
|
11
11
|
} from '@docusaurus/utils-validation';
|
|
12
12
|
|
|
13
|
+
import type {FormatInput} from './index';
|
|
14
|
+
|
|
13
15
|
export type MDXFrontMatter = {
|
|
14
|
-
format
|
|
16
|
+
format?: FormatInput;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
export const DefaultMDXFrontMatter: MDXFrontMatter = {
|
|
18
|
-
format:
|
|
20
|
+
format: undefined,
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
const MDXFrontMatterSchema = Joi.object<MDXFrontMatter>({
|
|
22
|
-
format: Joi.string()
|
|
23
|
-
.equal('md', 'mdx', 'detect')
|
|
24
|
-
.default(DefaultMDXFrontMatter.format),
|
|
24
|
+
format: Joi.string().equal('md', 'mdx', 'detect').optional(),
|
|
25
25
|
}).default(DefaultMDXFrontMatter);
|
|
26
26
|
|
|
27
27
|
export function validateMDXFrontMatter(frontMatter: unknown): MDXFrontMatter {
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,10 @@ export default mdxLoader;
|
|
|
13
13
|
|
|
14
14
|
export type TOCItem = TOCItemImported;
|
|
15
15
|
|
|
16
|
+
export type Format = 'md' | 'mdx';
|
|
17
|
+
|
|
18
|
+
export type FormatInput = Format | 'detect';
|
|
19
|
+
|
|
16
20
|
export type LoadedMDXContent<FrontMatter, Metadata, Assets = undefined> = {
|
|
17
21
|
/** As verbatim declared in the MDX document. */
|
|
18
22
|
readonly frontMatter: FrontMatter;
|
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';
|
|
@@ -28,7 +27,7 @@ import type {LoaderContext} from 'webpack';
|
|
|
28
27
|
type Pluggable = any; // TODO fix this asap
|
|
29
28
|
|
|
30
29
|
const {
|
|
31
|
-
loaders: {
|
|
30
|
+
loaders: {inlineMarkdownAssetImageFileLoader},
|
|
32
31
|
} = getFileLoaderUtils();
|
|
33
32
|
|
|
34
33
|
export type MDXPlugin = Pluggable;
|
|
@@ -92,8 +91,9 @@ function createAssetsExportCode(assets: unknown) {
|
|
|
92
91
|
if (typeof assetValue === 'string' && assetValue.startsWith('./')) {
|
|
93
92
|
// TODO do we have other use-cases than image assets?
|
|
94
93
|
// Probably not worth adding more support, as we want to move to Webpack 5 new asset system (https://github.com/facebook/docusaurus/pull/4708)
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
return `require("${inlineMarkdownAssetImageFileLoader}${escapePath(
|
|
95
|
+
assetValue,
|
|
96
|
+
)}").default`;
|
|
97
97
|
}
|
|
98
98
|
return undefined;
|
|
99
99
|
}
|
|
@@ -121,6 +121,15 @@ function ensureMarkdownConfig(reqOptions: Options) {
|
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
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
|
+
|
|
124
133
|
export async function mdxLoader(
|
|
125
134
|
this: LoaderContext<Options>,
|
|
126
135
|
fileString: string,
|
|
@@ -131,18 +140,11 @@ export async function mdxLoader(
|
|
|
131
140
|
const {query} = this;
|
|
132
141
|
ensureMarkdownConfig(reqOptions);
|
|
133
142
|
|
|
134
|
-
const {frontMatter
|
|
143
|
+
const {frontMatter} = parseFrontMatter(fileString);
|
|
135
144
|
const mdxFrontMatter = validateMDXFrontMatter(frontMatter.mdx);
|
|
136
145
|
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
{
|
|
140
|
-
removeContentTitle: reqOptions.removeContentTitle,
|
|
141
|
-
},
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const content = preprocessor({
|
|
145
|
-
fileContent: contentUnprocessed,
|
|
146
|
+
const preprocessedContent = preprocessor({
|
|
147
|
+
fileContent: fileString,
|
|
146
148
|
filePath,
|
|
147
149
|
admonitions: reqOptions.admonitions,
|
|
148
150
|
markdownConfig: reqOptions.markdownConfig,
|
|
@@ -157,22 +159,38 @@ export async function mdxLoader(
|
|
|
157
159
|
mdxFrontMatter,
|
|
158
160
|
});
|
|
159
161
|
|
|
160
|
-
let result: string;
|
|
162
|
+
let result: {content: string; data: {[key: string]: unknown}};
|
|
161
163
|
try {
|
|
162
|
-
result = await processor.process({
|
|
164
|
+
result = await processor.process({
|
|
165
|
+
content: preprocessedContent,
|
|
166
|
+
filePath,
|
|
167
|
+
frontMatter,
|
|
168
|
+
});
|
|
163
169
|
} catch (errorUnknown) {
|
|
164
170
|
const error = errorUnknown as Error;
|
|
171
|
+
|
|
172
|
+
// MDX can emit errors that have useful extra attributes
|
|
173
|
+
const errorJSON = JSON.stringify(error, null, 2);
|
|
174
|
+
const errorDetails =
|
|
175
|
+
errorJSON === '{}'
|
|
176
|
+
? // regular JS error case: print stacktrace
|
|
177
|
+
error.stack ?? 'N/A'
|
|
178
|
+
: // MDX error: print extra attributes + stacktrace
|
|
179
|
+
`${errorJSON}\n${error.stack}`;
|
|
180
|
+
|
|
165
181
|
return callback(
|
|
166
182
|
new Error(
|
|
167
183
|
`MDX compilation failed for file ${logger.path(filePath)}\nCause: ${
|
|
168
184
|
error.message
|
|
169
|
-
}\nDetails:\n${
|
|
185
|
+
}\nDetails:\n${errorDetails}`,
|
|
170
186
|
// TODO error cause doesn't seem to be used by Webpack stats.errors :s
|
|
171
187
|
{cause: error},
|
|
172
188
|
),
|
|
173
189
|
);
|
|
174
190
|
}
|
|
175
191
|
|
|
192
|
+
const contentTitle = extractContentTitleData(result.data);
|
|
193
|
+
|
|
176
194
|
// MDX partials are MDX files starting with _ or in a folder starting with _
|
|
177
195
|
// Partial are not expected to have associated metadata files or front matter
|
|
178
196
|
const isMDXPartial = reqOptions.isMDXPartial?.(filePath);
|
|
@@ -233,7 +251,7 @@ ${assets ? `export const assets = ${createAssetsExportCode(assets)};` : ''}
|
|
|
233
251
|
|
|
234
252
|
const code = `
|
|
235
253
|
${exportsCode}
|
|
236
|
-
${result}
|
|
254
|
+
${result.content}
|
|
237
255
|
`;
|
|
238
256
|
|
|
239
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,21 +29,25 @@ 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 = {
|
|
43
48
|
admonitions: true,
|
|
44
49
|
rehypePlugins: [],
|
|
45
|
-
remarkPlugins: [
|
|
50
|
+
remarkPlugins: [headings, emoji, toc],
|
|
46
51
|
beforeDefaultRemarkPlugins: [],
|
|
47
52
|
beforeDefaultRehypePlugins: [],
|
|
48
53
|
};
|
|
@@ -74,10 +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
|
|
86
|
+
const {default: comment} = await import('@slorber/remark-comment');
|
|
80
87
|
const {default: directive} = await import('remark-directive');
|
|
88
|
+
const {VFile} = await import('vfile');
|
|
81
89
|
|
|
82
90
|
// /!\ this method is synchronous on purpose
|
|
83
91
|
// Using async code here can create cache entry race conditions!
|
|
@@ -90,7 +98,9 @@ async function createProcessorFactory() {
|
|
|
90
98
|
}): SimpleProcessor {
|
|
91
99
|
const remarkPlugins: MDXPlugin[] = [
|
|
92
100
|
...(options.beforeDefaultRemarkPlugins ?? []),
|
|
101
|
+
frontmatter,
|
|
93
102
|
directive,
|
|
103
|
+
[contentTitle, {removeContentTitle: options.removeContentTitle}],
|
|
94
104
|
...getAdmonitionsPlugins(options.admonitions ?? false),
|
|
95
105
|
...DEFAULT_OPTIONS.remarkPlugins,
|
|
96
106
|
details,
|
|
@@ -157,13 +167,19 @@ async function createProcessorFactory() {
|
|
|
157
167
|
});
|
|
158
168
|
|
|
159
169
|
return {
|
|
160
|
-
process: async ({content, filePath}) =>
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
+
},
|
|
167
183
|
};
|
|
168
184
|
}
|
|
169
185
|
|
|
@@ -235,6 +251,7 @@ export async function createProcessorCached({
|
|
|
235
251
|
const format = getFormat({
|
|
236
252
|
filePath,
|
|
237
253
|
frontMatterFormat: mdxFrontMatter.format,
|
|
254
|
+
markdownConfigFormat: reqOptions.markdownConfig.format,
|
|
238
255
|
});
|
|
239
256
|
|
|
240
257
|
return format === 'md' ? compilers.mdProcessor : compilers.mdxProcessor;
|
|
@@ -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
|
|
@@ -8,26 +8,57 @@
|
|
|
8
8
|
import escapeHtml from 'escape-html';
|
|
9
9
|
import type {Parent} from 'unist';
|
|
10
10
|
import type {PhrasingContent, Heading} from 'mdast';
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import type {
|
|
12
|
+
MdxJsxAttribute,
|
|
13
|
+
MdxJsxAttributeValueExpression,
|
|
14
|
+
MdxJsxTextElement,
|
|
15
|
+
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
16
|
+
} from 'mdast-util-mdx';
|
|
13
17
|
|
|
14
18
|
export function stringifyContent(
|
|
15
19
|
node: Parent,
|
|
16
|
-
toString: (param: unknown) => string, // TODO weird but works
|
|
20
|
+
toString: (param: unknown) => string, // TODO weird but works
|
|
17
21
|
): string {
|
|
18
22
|
return (node.children as PhrasingContent[])
|
|
19
23
|
.map((item) => toValue(item, toString))
|
|
20
24
|
.join('');
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
// TODO This is really a workaround, and not super reliable
|
|
28
|
+
// For now we only support serializing tagName, className and content
|
|
29
|
+
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
30
|
+
function mdxJsxTextElementToHtml(
|
|
31
|
+
element: MdxJsxTextElement,
|
|
32
|
+
toString: (param: unknown) => string, // TODO weird but works
|
|
33
|
+
): string {
|
|
34
|
+
const tag = element.name;
|
|
35
|
+
|
|
36
|
+
const attributes = element.attributes.filter(
|
|
37
|
+
(child): child is MdxJsxAttribute => child.type === 'mdxJsxAttribute',
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const classAttribute =
|
|
41
|
+
attributes.find((attr) => attr.name === 'className') ??
|
|
42
|
+
attributes.find((attr) => attr.name === 'class');
|
|
43
|
+
|
|
44
|
+
const classAttributeString = classAttribute
|
|
45
|
+
? `class="${escapeHtml(String(classAttribute.value))}"`
|
|
46
|
+
: ``;
|
|
47
|
+
|
|
48
|
+
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
49
|
+
|
|
50
|
+
const content = stringifyContent(element, toString);
|
|
51
|
+
|
|
52
|
+
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
53
|
+
}
|
|
54
|
+
|
|
23
55
|
export function toValue(
|
|
24
56
|
node: PhrasingContent | Heading,
|
|
25
57
|
toString: (param: unknown) => string, // TODO weird but works
|
|
26
58
|
): string {
|
|
27
59
|
switch (node.type) {
|
|
28
60
|
case 'mdxJsxTextElement': {
|
|
29
|
-
|
|
30
|
-
return `<${tag}>${stringifyContent(node, toString)}</${tag}>`;
|
|
61
|
+
return mdxJsxTextElementToHtml(node as MdxJsxTextElement, toString);
|
|
31
62
|
}
|
|
32
63
|
case 'text':
|
|
33
64
|
return escapeHtml(node.value);
|