@docusaurus/mdx-loader 0.0.0-6004 → 0.0.0-6007
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,KAAK,MAAM,GAAG,GAAG,CAAC;AAoBlB;;;;GAIG;AACH,QAAA,MAAM,MAAM,EAAE,MAuCb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -6,6 +6,15 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
function wrapHeadingInJsxHeader(headingNode, parent, index) {
|
|
10
|
+
const header = {
|
|
11
|
+
type: 'mdxJsxFlowElement',
|
|
12
|
+
name: 'header',
|
|
13
|
+
attributes: [],
|
|
14
|
+
children: [headingNode],
|
|
15
|
+
};
|
|
16
|
+
parent.children[index] = header;
|
|
17
|
+
}
|
|
9
18
|
/**
|
|
10
19
|
* A remark plugin to extract the h1 heading found in Markdown files
|
|
11
20
|
* This is exposed as "data.contentTitle" to the processed vfile
|
|
@@ -20,12 +29,19 @@ const plugin = function plugin(options = {}) {
|
|
|
20
29
|
visit(root, ['heading', 'thematicBreak'], (node, index, parent) => {
|
|
21
30
|
if (node.type === 'heading') {
|
|
22
31
|
const headingNode = node;
|
|
32
|
+
// console.log('headingNode:', headingNode);
|
|
23
33
|
if (headingNode.depth === 1) {
|
|
24
34
|
vfile.data.contentTitle = toString(headingNode);
|
|
25
35
|
if (removeContentTitle) {
|
|
26
36
|
// @ts-expect-error: TODO how to fix?
|
|
27
37
|
parent.children.splice(index, 1);
|
|
28
38
|
}
|
|
39
|
+
else {
|
|
40
|
+
// TODO in the future it might be better to export contentTitle as
|
|
41
|
+
// as JSX node to keep this logic a theme concern?
|
|
42
|
+
// See https://github.com/facebook/docusaurus/pull/10335#issuecomment-2250187371
|
|
43
|
+
wrapHeadingInJsxHeader(headingNode, parent, index);
|
|
44
|
+
}
|
|
29
45
|
return EXIT; // We only handle the very first heading
|
|
30
46
|
}
|
|
31
47
|
// We only handle contentTitle if it's the very first heading found
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/contentTitle/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAmBH,SAAS,sBAAsB,CAC7B,WAAoB,EACpB,MAAc,EACd,KAAa;IAEb,MAAM,MAAM,GAAsB;QAChC,IAAI,EAAE,mBAAmB;QACzB,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,CAAC,WAAW,CAAC;KACxB,CAAC;IACF,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC;AAClC,CAAC;AAED;;;;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,MAAM,EAAC,KAAK,EAAE,IAAI,EAAC,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;QACvD,KAAK,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,eAAe,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;YAChE,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC5B,MAAM,WAAW,GAAG,IAAe,CAAC;gBACpC,4CAA4C;gBAE5C,IAAI,WAAW,CAAC,KAAK,KAAK,CAAC,EAAE,CAAC;oBAC5B,KAAK,CAAC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;oBAChD,IAAI,kBAAkB,EAAE,CAAC;wBACvB,qCAAqC;wBACrC,MAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;oBACpC,CAAC;yBAAM,CAAC;wBACN,kEAAkE;wBAClE,kDAAkD;wBAClD,gFAAgF;wBAChF,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAM,CAAC,CAAC;oBACtD,CAAC;oBACD,OAAO,IAAI,CAAC,CAAC,wCAAwC;gBACvD,CAAC;gBACD,mEAAmE;gBACnE,IAAI,WAAW,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC;oBAC3B,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC;YACD,uEAAuE;YACvE,IAAI,IAAI,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;gBAClC,OAAO,IAAI,CAAC;YACd,CAAC;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-6007",
|
|
4
4
|
"description": "Docusaurus Loader for MDX",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "0.0.0-
|
|
22
|
-
"@docusaurus/utils": "0.0.0-
|
|
23
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
21
|
+
"@docusaurus/logger": "0.0.0-6007",
|
|
22
|
+
"@docusaurus/utils": "0.0.0-6007",
|
|
23
|
+
"@docusaurus/utils-validation": "0.0.0-6007",
|
|
24
24
|
"@mdx-js/mdx": "^3.0.0",
|
|
25
25
|
"@slorber/remark-comment": "^1.0.0",
|
|
26
26
|
"escape-html": "^1.0.3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"webpack": "^5.88.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@docusaurus/types": "0.0.0-
|
|
47
|
+
"@docusaurus/types": "0.0.0-6007",
|
|
48
48
|
"@types/escape-html": "^1.0.2",
|
|
49
49
|
"@types/mdast": "^4.0.2",
|
|
50
50
|
"@types/stringify-object": "^3.3.1",
|
|
@@ -64,5 +64,5 @@
|
|
|
64
64
|
"engines": {
|
|
65
65
|
"node": ">=18.0"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "11b572bf7a938077e10a53ed8438a4fcd5298574"
|
|
68
68
|
}
|
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
|
|
8
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
9
9
|
import type {Transformer} from 'unified';
|
|
10
|
-
import type {Heading} from 'mdast';
|
|
10
|
+
import type {Heading, Parent} from 'mdast';
|
|
11
|
+
|
|
12
|
+
// @ts-expect-error: ES support...
|
|
13
|
+
import type {MdxJsxFlowElement} from 'mdast-util-mdx';
|
|
11
14
|
|
|
12
15
|
// TODO as of April 2023, no way to import/re-export this ESM type easily :/
|
|
13
16
|
// TODO upgrade to TS 5.3
|
|
@@ -19,6 +22,20 @@ interface PluginOptions {
|
|
|
19
22
|
removeContentTitle?: boolean;
|
|
20
23
|
}
|
|
21
24
|
|
|
25
|
+
function wrapHeadingInJsxHeader(
|
|
26
|
+
headingNode: Heading,
|
|
27
|
+
parent: Parent,
|
|
28
|
+
index: number,
|
|
29
|
+
) {
|
|
30
|
+
const header: MdxJsxFlowElement = {
|
|
31
|
+
type: 'mdxJsxFlowElement',
|
|
32
|
+
name: 'header',
|
|
33
|
+
attributes: [],
|
|
34
|
+
children: [headingNode],
|
|
35
|
+
};
|
|
36
|
+
parent.children[index] = header;
|
|
37
|
+
}
|
|
38
|
+
|
|
22
39
|
/**
|
|
23
40
|
* A remark plugin to extract the h1 heading found in Markdown files
|
|
24
41
|
* This is exposed as "data.contentTitle" to the processed vfile
|
|
@@ -33,15 +50,21 @@ const plugin: Plugin = function plugin(
|
|
|
33
50
|
return async (root, vfile) => {
|
|
34
51
|
const {toString} = await import('mdast-util-to-string');
|
|
35
52
|
const {visit, EXIT} = await import('unist-util-visit');
|
|
36
|
-
|
|
37
53
|
visit(root, ['heading', 'thematicBreak'], (node, index, parent) => {
|
|
38
54
|
if (node.type === 'heading') {
|
|
39
55
|
const headingNode = node as Heading;
|
|
56
|
+
// console.log('headingNode:', headingNode);
|
|
57
|
+
|
|
40
58
|
if (headingNode.depth === 1) {
|
|
41
59
|
vfile.data.contentTitle = toString(headingNode);
|
|
42
60
|
if (removeContentTitle) {
|
|
43
61
|
// @ts-expect-error: TODO how to fix?
|
|
44
62
|
parent!.children.splice(index, 1);
|
|
63
|
+
} else {
|
|
64
|
+
// TODO in the future it might be better to export contentTitle as
|
|
65
|
+
// as JSX node to keep this logic a theme concern?
|
|
66
|
+
// See https://github.com/facebook/docusaurus/pull/10335#issuecomment-2250187371
|
|
67
|
+
wrapHeadingInJsxHeader(headingNode, parent, index!);
|
|
45
68
|
}
|
|
46
69
|
return EXIT; // We only handle the very first heading
|
|
47
70
|
}
|
package/src/remark/head/index.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
9
9
|
import type {Transformer} from 'unified';
|
|
10
10
|
|
|
11
|
-
// @ts-expect-error:
|
|
11
|
+
// @ts-expect-error: TODO see https://github.com/microsoft/TypeScript/issues/49721
|
|
12
12
|
import type {MdxJsxFlowElement} from 'mdast-util-mdx';
|
|
13
13
|
|
|
14
14
|
// Transform <head> to <Head>
|