@docusaurus/mdx-loader 3.7.0-canary-6258 → 3.7.0-canary-6261
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/remark/toc/utils.d.ts +3 -1
- package/lib/remark/toc/utils.d.ts.map +1 -1
- package/lib/remark/toc/utils.js +52 -2
- package/lib/remark/toc/utils.js.map +1 -1
- package/lib/remark/utils/index.d.ts +2 -5
- package/lib/remark/utils/index.d.ts.map +1 -1
- package/lib/remark/utils/index.js +0 -47
- package/lib/remark/utils/index.js.map +1 -1
- package/package.json +6 -6
- package/src/remark/toc/utils.ts +79 -4
- package/src/remark/utils/index.ts +2 -72
|
@@ -5,9 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Node } from 'unist';
|
|
8
|
-
import type { MdxjsEsm } from 'mdast-util-mdx';
|
|
8
|
+
import type { MdxjsEsm, MdxJsxTextElement } from 'mdast-util-mdx';
|
|
9
9
|
import type { TOCItems } from './types';
|
|
10
10
|
import type { Program, ImportDeclaration, ImportSpecifier } from 'estree';
|
|
11
|
+
import type { Heading, PhrasingContent } from 'mdast';
|
|
11
12
|
export declare function getImportDeclarations(program: Program): ImportDeclaration[];
|
|
12
13
|
export declare function isMarkdownImport(node: Node): node is ImportDeclaration;
|
|
13
14
|
export declare function findDefaultImportName(importDeclaration: ImportDeclaration): string | undefined;
|
|
@@ -22,4 +23,5 @@ export declare function createTOCExportNodeAST({ tocExportName, tocItems, }: {
|
|
|
22
23
|
tocExportName: string;
|
|
23
24
|
tocItems: TOCItems;
|
|
24
25
|
}): Promise<MdxjsEsm>;
|
|
26
|
+
export declare function toHeadingHTMLValue(node: PhrasingContent | Heading | MdxJsxTextElement, toString: (param: unknown) => string): string;
|
|
25
27
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,IAAI,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/remark/toc/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,IAAI,EAAS,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EACV,QAAQ,EAER,iBAAiB,EAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAsB,QAAQ,EAAW,MAAM,SAAS,CAAC;AACrE,OAAO,KAAK,EACV,OAAO,EAEP,iBAAiB,EACjB,eAAe,EAChB,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAC,OAAO,EAAE,eAAe,EAAC,MAAM,OAAO,CAAC;AAEpD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,iBAAiB,EAAE,CAI3E;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,iBAAiB,CAMtE;AAED,wBAAgB,qBAAqB,CACnC,iBAAiB,EAAE,iBAAiB,GACnC,MAAM,GAAG,SAAS,CAIpB;AAED,wBAAgB,wBAAwB,CACtC,iBAAiB,EAAE,iBAAiB,EACpC,SAAS,EAAE,MAAM,GAChB,eAAe,GAAG,SAAS,CAM7B;AAID,wBAAgB,yBAAyB,CAAC,EACxC,iBAAiB,EACjB,aAAa,EACb,kBAAkB,GACnB,EAAE;IACD,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,GAAG,IAAI,CASP;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,MAAM,GACjB,IAAI,IAAI,QAAQ,CAyBlB;AAED,wBAAsB,sBAAsB,CAAC,EAC3C,aAAa,EACb,QAAQ,GACT,EAAE;IACD,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,QAAQ,CAAC;CACpB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAiEpB;AA6CD,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,eAAe,GAAG,OAAO,GAAG,iBAAiB,EACnD,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,GACnC,MAAM,CAsBR"}
|
package/lib/remark/toc/utils.js
CHANGED
|
@@ -13,7 +13,9 @@ exports.findNamedImportSpecifier = findNamedImportSpecifier;
|
|
|
13
13
|
exports.addTocSliceImportIfNeeded = addTocSliceImportIfNeeded;
|
|
14
14
|
exports.isNamedExport = isNamedExport;
|
|
15
15
|
exports.createTOCExportNodeAST = createTOCExportNodeAST;
|
|
16
|
-
|
|
16
|
+
exports.toHeadingHTMLValue = toHeadingHTMLValue;
|
|
17
|
+
const tslib_1 = require("tslib");
|
|
18
|
+
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
17
19
|
function getImportDeclarations(program) {
|
|
18
20
|
return program.body.filter((item) => item.type === 'ImportDeclaration');
|
|
19
21
|
}
|
|
@@ -79,7 +81,7 @@ async function createTOCExportNodeAST({ tocExportName, tocItems, }) {
|
|
|
79
81
|
const { toString } = await import('mdast-util-to-string');
|
|
80
82
|
const { valueToEstree } = await import('estree-util-value-to-estree');
|
|
81
83
|
const value = {
|
|
82
|
-
value: (
|
|
84
|
+
value: toHeadingHTMLValue(heading, toString),
|
|
83
85
|
id: heading.data.id,
|
|
84
86
|
level: heading.depth,
|
|
85
87
|
};
|
|
@@ -131,4 +133,52 @@ async function createTOCExportNodeAST({ tocExportName, tocItems, }) {
|
|
|
131
133
|
},
|
|
132
134
|
};
|
|
133
135
|
}
|
|
136
|
+
function stringifyChildren(node, toString) {
|
|
137
|
+
return node.children
|
|
138
|
+
.map((item) => toHeadingHTMLValue(item, toString))
|
|
139
|
+
.join('')
|
|
140
|
+
.trim();
|
|
141
|
+
}
|
|
142
|
+
// TODO This is really a workaround, and not super reliable
|
|
143
|
+
// For now we only support serializing tagName, className and content
|
|
144
|
+
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
145
|
+
function mdxJsxTextElementToHtml(element, toString) {
|
|
146
|
+
const tag = element.name;
|
|
147
|
+
// See https://github.com/facebook/docusaurus/issues/11003#issuecomment-2733925363
|
|
148
|
+
if (tag === 'img') {
|
|
149
|
+
return '';
|
|
150
|
+
}
|
|
151
|
+
const attributes = element.attributes.filter((child) => child.type === 'mdxJsxAttribute');
|
|
152
|
+
const classAttribute = attributes.find((attr) => attr.name === 'className') ??
|
|
153
|
+
attributes.find((attr) => attr.name === 'class');
|
|
154
|
+
const classAttributeString = classAttribute
|
|
155
|
+
? `class="${(0, escape_html_1.default)(String(classAttribute.value))}"`
|
|
156
|
+
: ``;
|
|
157
|
+
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
158
|
+
const content = stringifyChildren(element, toString);
|
|
159
|
+
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
160
|
+
}
|
|
161
|
+
function toHeadingHTMLValue(node, toString) {
|
|
162
|
+
switch (node.type) {
|
|
163
|
+
case 'mdxJsxTextElement': {
|
|
164
|
+
return mdxJsxTextElementToHtml(node, toString);
|
|
165
|
+
}
|
|
166
|
+
case 'text':
|
|
167
|
+
return (0, escape_html_1.default)(node.value);
|
|
168
|
+
case 'heading':
|
|
169
|
+
return stringifyChildren(node, toString);
|
|
170
|
+
case 'inlineCode':
|
|
171
|
+
return `<code>${(0, escape_html_1.default)(node.value)}</code>`;
|
|
172
|
+
case 'emphasis':
|
|
173
|
+
return `<em>${stringifyChildren(node, toString)}</em>`;
|
|
174
|
+
case 'strong':
|
|
175
|
+
return `<strong>${stringifyChildren(node, toString)}</strong>`;
|
|
176
|
+
case 'delete':
|
|
177
|
+
return `<del>${stringifyChildren(node, toString)}</del>`;
|
|
178
|
+
case 'link':
|
|
179
|
+
return stringifyChildren(node, toString);
|
|
180
|
+
default:
|
|
181
|
+
return toString(node);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
134
184
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/remark/toc/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/remark/toc/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAkBH,sDAIC;AAED,4CAMC;AAED,sDAMC;AAED,4DASC;AAID,8DAiBC;AAED,sCA4BC;AAED,wDAuEC;AA6CD,gDAyBC;;AAjPD,sEAAqC;AAgBrC,SAAgB,qBAAqB,CAAC,OAAgB;IACpD,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CACxB,CAAC,IAAI,EAA6B,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,mBAAmB,CACvE,CAAC;AACJ,CAAC;AAED,SAAgB,gBAAgB,CAAC,IAAU;IACzC,IAAI,IAAI,CAAC,IAAI,KAAK,mBAAmB,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,MAAM,UAAU,GAAI,IAA0B,CAAC,MAAM,CAAC,KAAK,CAAC;IAC5D,OAAO,OAAO,UAAU,KAAK,QAAQ,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;AACtE,CAAC;AAED,SAAgB,qBAAqB,CACnC,iBAAoC;IAEpC,OAAO,iBAAiB,CAAC,UAAU,CAAC,IAAI,CACtC,CAAC,CAAO,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,wBAAwB,CACjD,EAAE,KAAK,CAAC,IAAI,CAAC;AAChB,CAAC;AAED,SAAgB,wBAAwB,CACtC,iBAAoC,EACpC,SAAiB;IAEjB,OAAO,iBAAiB,EAAE,UAAU,CAAC,IAAI,CACvC,CAAC,SAAS,EAAgC,EAAE,CAC1C,SAAS,CAAC,IAAI,KAAK,iBAAiB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AE,QAAQ,CAAC,WAAW,CAAC;QACjE,KAAK,QAAQ;YACX,OAAO,QAAQ,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,QAAQ,CAAC;QAC3D,KAAK,MAAM;YACT,OAAO,iBAAiB,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC3C;YACE,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;AACH,CAAC"}
|
|
@@ -4,9 +4,8 @@
|
|
|
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 {
|
|
8
|
-
import type {
|
|
9
|
-
import type { MdxJsxAttributeValueExpression, MdxJsxTextElement } from 'mdast-util-mdx';
|
|
7
|
+
import type { Node } from 'unist';
|
|
8
|
+
import type { MdxJsxAttributeValueExpression } from 'mdast-util-mdx';
|
|
10
9
|
/**
|
|
11
10
|
* Util to transform one node type to another node type
|
|
12
11
|
* The input node is mutated in place
|
|
@@ -14,7 +13,5 @@ import type { MdxJsxAttributeValueExpression, MdxJsxTextElement } from 'mdast-ut
|
|
|
14
13
|
* @param newNode what the original node should become become
|
|
15
14
|
*/
|
|
16
15
|
export declare function transformNode<NewNode extends Node>(node: Node, newNode: NewNode): NewNode;
|
|
17
|
-
export declare function stringifyContent(node: Parent, toString: (param: unknown) => string): string;
|
|
18
|
-
export declare function toValue(node: PhrasingContent | Heading | MdxJsxTextElement, toString: (param: unknown) => string): string;
|
|
19
16
|
export declare function assetRequireAttributeValue(requireString: string, hash: string): MdxJsxAttributeValueExpression;
|
|
20
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,KAAK,EAAC,8BAA8B,EAAC,MAAM,gBAAgB,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,IAAI,EAChD,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,OAAO,GACf,OAAO,CAUT;AAED,wBAAgB,0BAA0B,CACxC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,GACX,8BAA8B,CAkDhC"}
|
|
@@ -7,11 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.transformNode = transformNode;
|
|
10
|
-
exports.stringifyContent = stringifyContent;
|
|
11
|
-
exports.toValue = toValue;
|
|
12
10
|
exports.assetRequireAttributeValue = assetRequireAttributeValue;
|
|
13
|
-
const tslib_1 = require("tslib");
|
|
14
|
-
const escape_html_1 = tslib_1.__importDefault(require("escape-html"));
|
|
15
11
|
/**
|
|
16
12
|
* Util to transform one node type to another node type
|
|
17
13
|
* The input node is mutated in place
|
|
@@ -29,49 +25,6 @@ function transformNode(node, newNode) {
|
|
|
29
25
|
});
|
|
30
26
|
return node;
|
|
31
27
|
}
|
|
32
|
-
function stringifyContent(node, toString) {
|
|
33
|
-
return node.children
|
|
34
|
-
.map((item) => toValue(item, toString))
|
|
35
|
-
.join('');
|
|
36
|
-
}
|
|
37
|
-
// TODO This is really a workaround, and not super reliable
|
|
38
|
-
// For now we only support serializing tagName, className and content
|
|
39
|
-
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
40
|
-
function mdxJsxTextElementToHtml(element, toString) {
|
|
41
|
-
const tag = element.name;
|
|
42
|
-
const attributes = element.attributes.filter((child) => child.type === 'mdxJsxAttribute');
|
|
43
|
-
const classAttribute = attributes.find((attr) => attr.name === 'className') ??
|
|
44
|
-
attributes.find((attr) => attr.name === 'class');
|
|
45
|
-
const classAttributeString = classAttribute
|
|
46
|
-
? `class="${(0, escape_html_1.default)(String(classAttribute.value))}"`
|
|
47
|
-
: ``;
|
|
48
|
-
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
49
|
-
const content = stringifyContent(element, toString);
|
|
50
|
-
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
51
|
-
}
|
|
52
|
-
function toValue(node, toString) {
|
|
53
|
-
switch (node.type) {
|
|
54
|
-
case 'mdxJsxTextElement': {
|
|
55
|
-
return mdxJsxTextElementToHtml(node, toString);
|
|
56
|
-
}
|
|
57
|
-
case 'text':
|
|
58
|
-
return (0, escape_html_1.default)(node.value);
|
|
59
|
-
case 'heading':
|
|
60
|
-
return stringifyContent(node, toString);
|
|
61
|
-
case 'inlineCode':
|
|
62
|
-
return `<code>${(0, escape_html_1.default)(node.value)}</code>`;
|
|
63
|
-
case 'emphasis':
|
|
64
|
-
return `<em>${stringifyContent(node, toString)}</em>`;
|
|
65
|
-
case 'strong':
|
|
66
|
-
return `<strong>${stringifyContent(node, toString)}</strong>`;
|
|
67
|
-
case 'delete':
|
|
68
|
-
return `<del>${stringifyContent(node, toString)}</del>`;
|
|
69
|
-
case 'link':
|
|
70
|
-
return stringifyContent(node, toString);
|
|
71
|
-
default:
|
|
72
|
-
return toString(node);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
28
|
function assetRequireAttributeValue(requireString, hash) {
|
|
76
29
|
return {
|
|
77
30
|
type: 'mdxJsxAttributeValueExpression',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/remark/utils/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AAWH,sCAaC;AAED,gEAqDC;AA1ED;;;;;GAKG;AACH,SAAgB,aAAa,CAC3B,IAAU,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AAE,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/mdx-loader",
|
|
3
|
-
"version": "3.7.0-canary-
|
|
3
|
+
"version": "3.7.0-canary-6261",
|
|
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": "3.7.0-canary-
|
|
22
|
-
"@docusaurus/utils": "3.7.0-canary-
|
|
23
|
-
"@docusaurus/utils-validation": "3.7.0-canary-
|
|
21
|
+
"@docusaurus/logger": "3.7.0-canary-6261",
|
|
22
|
+
"@docusaurus/utils": "3.7.0-canary-6261",
|
|
23
|
+
"@docusaurus/utils-validation": "3.7.0-canary-6261",
|
|
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": "3.7.0-canary-
|
|
47
|
+
"@docusaurus/types": "3.7.0-canary-6261",
|
|
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": "a93b982c4a8fd345bae11d2d896c5381af5af2b0"
|
|
68
68
|
}
|
package/src/remark/toc/utils.ts
CHANGED
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import type {Node} from 'unist';
|
|
10
|
-
import type {
|
|
8
|
+
import escapeHtml from 'escape-html';
|
|
9
|
+
import type {Node, Parent} from 'unist';
|
|
10
|
+
import type {
|
|
11
|
+
MdxjsEsm,
|
|
12
|
+
MdxJsxAttribute,
|
|
13
|
+
MdxJsxTextElement,
|
|
14
|
+
} from 'mdast-util-mdx';
|
|
11
15
|
import type {TOCHeading, TOCItem, TOCItems, TOCSlice} from './types';
|
|
12
16
|
import type {
|
|
13
17
|
Program,
|
|
@@ -15,6 +19,7 @@ import type {
|
|
|
15
19
|
ImportDeclaration,
|
|
16
20
|
ImportSpecifier,
|
|
17
21
|
} from 'estree';
|
|
22
|
+
import type {Heading, PhrasingContent} from 'mdast';
|
|
18
23
|
|
|
19
24
|
export function getImportDeclarations(program: Program): ImportDeclaration[] {
|
|
20
25
|
return program.body.filter(
|
|
@@ -118,7 +123,7 @@ export async function createTOCExportNodeAST({
|
|
|
118
123
|
const {toString} = await import('mdast-util-to-string');
|
|
119
124
|
const {valueToEstree} = await import('estree-util-value-to-estree');
|
|
120
125
|
const value: TOCItem = {
|
|
121
|
-
value:
|
|
126
|
+
value: toHeadingHTMLValue(heading, toString),
|
|
122
127
|
id: heading.data!.id!,
|
|
123
128
|
level: heading.depth,
|
|
124
129
|
};
|
|
@@ -172,3 +177,73 @@ export async function createTOCExportNodeAST({
|
|
|
172
177
|
},
|
|
173
178
|
};
|
|
174
179
|
}
|
|
180
|
+
|
|
181
|
+
function stringifyChildren(
|
|
182
|
+
node: Parent,
|
|
183
|
+
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
184
|
+
): string {
|
|
185
|
+
return (node.children as PhrasingContent[])
|
|
186
|
+
.map((item) => toHeadingHTMLValue(item, toString))
|
|
187
|
+
.join('')
|
|
188
|
+
.trim();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// TODO This is really a workaround, and not super reliable
|
|
192
|
+
// For now we only support serializing tagName, className and content
|
|
193
|
+
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
194
|
+
function mdxJsxTextElementToHtml(
|
|
195
|
+
element: MdxJsxTextElement,
|
|
196
|
+
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
197
|
+
): string {
|
|
198
|
+
const tag = element.name;
|
|
199
|
+
|
|
200
|
+
// See https://github.com/facebook/docusaurus/issues/11003#issuecomment-2733925363
|
|
201
|
+
if (tag === 'img') {
|
|
202
|
+
return '';
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const attributes = element.attributes.filter(
|
|
206
|
+
(child): child is MdxJsxAttribute => child.type === 'mdxJsxAttribute',
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const classAttribute =
|
|
210
|
+
attributes.find((attr) => attr.name === 'className') ??
|
|
211
|
+
attributes.find((attr) => attr.name === 'class');
|
|
212
|
+
|
|
213
|
+
const classAttributeString = classAttribute
|
|
214
|
+
? `class="${escapeHtml(String(classAttribute.value))}"`
|
|
215
|
+
: ``;
|
|
216
|
+
|
|
217
|
+
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
218
|
+
|
|
219
|
+
const content = stringifyChildren(element, toString);
|
|
220
|
+
|
|
221
|
+
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function toHeadingHTMLValue(
|
|
225
|
+
node: PhrasingContent | Heading | MdxJsxTextElement,
|
|
226
|
+
toString: (param: unknown) => string, // TODO temporary, due to ESM
|
|
227
|
+
): string {
|
|
228
|
+
switch (node.type) {
|
|
229
|
+
case 'mdxJsxTextElement': {
|
|
230
|
+
return mdxJsxTextElementToHtml(node as MdxJsxTextElement, toString);
|
|
231
|
+
}
|
|
232
|
+
case 'text':
|
|
233
|
+
return escapeHtml(node.value);
|
|
234
|
+
case 'heading':
|
|
235
|
+
return stringifyChildren(node, toString);
|
|
236
|
+
case 'inlineCode':
|
|
237
|
+
return `<code>${escapeHtml(node.value)}</code>`;
|
|
238
|
+
case 'emphasis':
|
|
239
|
+
return `<em>${stringifyChildren(node, toString)}</em>`;
|
|
240
|
+
case 'strong':
|
|
241
|
+
return `<strong>${stringifyChildren(node, toString)}</strong>`;
|
|
242
|
+
case 'delete':
|
|
243
|
+
return `<del>${stringifyChildren(node, toString)}</del>`;
|
|
244
|
+
case 'link':
|
|
245
|
+
return stringifyChildren(node, toString);
|
|
246
|
+
default:
|
|
247
|
+
return toString(node);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
@@ -5,14 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import type {
|
|
10
|
-
import type {PhrasingContent, Heading} from 'mdast';
|
|
11
|
-
import type {
|
|
12
|
-
MdxJsxAttribute,
|
|
13
|
-
MdxJsxAttributeValueExpression,
|
|
14
|
-
MdxJsxTextElement,
|
|
15
|
-
} from 'mdast-util-mdx';
|
|
8
|
+
import type {Node} from 'unist';
|
|
9
|
+
import type {MdxJsxAttributeValueExpression} from 'mdast-util-mdx';
|
|
16
10
|
|
|
17
11
|
/**
|
|
18
12
|
* Util to transform one node type to another node type
|
|
@@ -35,70 +29,6 @@ export function transformNode<NewNode extends Node>(
|
|
|
35
29
|
return node as NewNode;
|
|
36
30
|
}
|
|
37
31
|
|
|
38
|
-
export function stringifyContent(
|
|
39
|
-
node: Parent,
|
|
40
|
-
toString: (param: unknown) => string, // TODO weird but works
|
|
41
|
-
): string {
|
|
42
|
-
return (node.children as PhrasingContent[])
|
|
43
|
-
.map((item) => toValue(item, toString))
|
|
44
|
-
.join('');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// TODO This is really a workaround, and not super reliable
|
|
48
|
-
// For now we only support serializing tagName, className and content
|
|
49
|
-
// Can we implement the TOC with real JSX nodes instead of html strings later?
|
|
50
|
-
function mdxJsxTextElementToHtml(
|
|
51
|
-
element: MdxJsxTextElement,
|
|
52
|
-
toString: (param: unknown) => string, // TODO weird but works
|
|
53
|
-
): string {
|
|
54
|
-
const tag = element.name;
|
|
55
|
-
|
|
56
|
-
const attributes = element.attributes.filter(
|
|
57
|
-
(child): child is MdxJsxAttribute => child.type === 'mdxJsxAttribute',
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
const classAttribute =
|
|
61
|
-
attributes.find((attr) => attr.name === 'className') ??
|
|
62
|
-
attributes.find((attr) => attr.name === 'class');
|
|
63
|
-
|
|
64
|
-
const classAttributeString = classAttribute
|
|
65
|
-
? `class="${escapeHtml(String(classAttribute.value))}"`
|
|
66
|
-
: ``;
|
|
67
|
-
|
|
68
|
-
const allAttributes = classAttributeString ? ` ${classAttributeString}` : '';
|
|
69
|
-
|
|
70
|
-
const content = stringifyContent(element, toString);
|
|
71
|
-
|
|
72
|
-
return `<${tag}${allAttributes}>${content}</${tag}>`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function toValue(
|
|
76
|
-
node: PhrasingContent | Heading | MdxJsxTextElement,
|
|
77
|
-
toString: (param: unknown) => string, // TODO weird but works
|
|
78
|
-
): string {
|
|
79
|
-
switch (node.type) {
|
|
80
|
-
case 'mdxJsxTextElement': {
|
|
81
|
-
return mdxJsxTextElementToHtml(node as MdxJsxTextElement, toString);
|
|
82
|
-
}
|
|
83
|
-
case 'text':
|
|
84
|
-
return escapeHtml(node.value);
|
|
85
|
-
case 'heading':
|
|
86
|
-
return stringifyContent(node, toString);
|
|
87
|
-
case 'inlineCode':
|
|
88
|
-
return `<code>${escapeHtml(node.value)}</code>`;
|
|
89
|
-
case 'emphasis':
|
|
90
|
-
return `<em>${stringifyContent(node, toString)}</em>`;
|
|
91
|
-
case 'strong':
|
|
92
|
-
return `<strong>${stringifyContent(node, toString)}</strong>`;
|
|
93
|
-
case 'delete':
|
|
94
|
-
return `<del>${stringifyContent(node, toString)}</del>`;
|
|
95
|
-
case 'link':
|
|
96
|
-
return stringifyContent(node, toString);
|
|
97
|
-
default:
|
|
98
|
-
return toString(node);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
32
|
export function assetRequireAttributeValue(
|
|
103
33
|
requireString: string,
|
|
104
34
|
hash: string,
|