@mui/internal-docs-infra 0.2.3-canary.9 → 0.3.1-canary.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/README.md +3 -2
- package/esm/CodeHighlighter/CodeHighlighter.js +16 -16
- package/esm/CodeHighlighter/CodeHighlighterClient.js +33 -33
- package/esm/CodeHighlighter/errors.js +3 -3
- package/esm/CodeHighlighter/types.d.ts +1 -1
- package/esm/CodeProvider/CodeContext.d.ts +4 -4
- package/esm/CodeProvider/CodeProvider.js +7 -7
- package/esm/cli/index.d.ts +1 -0
- package/esm/cli/index.js +6 -0
- package/esm/cli/runValidate.d.ts +8 -0
- package/esm/cli/runValidate.js +297 -0
- package/esm/createSitemap/createSitemap.d.ts +23 -0
- package/esm/createSitemap/createSitemap.js +45 -0
- package/esm/createSitemap/index.d.ts +1 -0
- package/esm/createSitemap/index.js +1 -0
- package/esm/createSitemap/types.d.ts +68 -0
- package/esm/createSitemap/types.js +1 -0
- package/esm/pipeline/getFileConventions/fileConventions.d.ts +4 -0
- package/esm/pipeline/getFileConventions/fileConventions.js +4 -0
- package/esm/pipeline/getFileConventions/getFileConventions.d.ts +4 -0
- package/esm/pipeline/getFileConventions/getFileConventions.js +17 -0
- package/esm/pipeline/getFileConventions/index.d.ts +1 -0
- package/esm/pipeline/getFileConventions/index.js +1 -0
- package/esm/{CodeHighlighter/addPathsToVariant.d.ts → pipeline/loadCodeVariant/addCodeVariantPaths.d.ts} +1 -1
- package/esm/{CodeHighlighter/applyTransform.d.ts → pipeline/loadCodeVariant/applyCodeTransform.d.ts} +3 -3
- package/esm/{CodeHighlighter/applyTransform.js → pipeline/loadCodeVariant/applyCodeTransform.js} +4 -4
- package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.js +1 -1
- package/esm/{CodeHighlighter/transformCode.d.ts → pipeline/loadCodeVariant/computeHastDeltas.d.ts} +9 -5
- package/esm/{CodeHighlighter/transformCode.js → pipeline/loadCodeVariant/computeHastDeltas.js} +20 -16
- package/esm/pipeline/loadCodeVariant/diffHast.d.ts +3 -0
- package/esm/{CodeHighlighter/transformParsedSource.js → pipeline/loadCodeVariant/diffHast.js} +5 -5
- package/esm/{CodeHighlighter/examineVariant.d.ts → pipeline/loadCodeVariant/examineCodeVariant.d.ts} +2 -2
- package/esm/{CodeHighlighter/examineVariant.js → pipeline/loadCodeVariant/examineCodeVariant.js} +1 -1
- package/esm/{useDemo/flattenVariant.d.ts → pipeline/loadCodeVariant/flattenCodeVariant.d.ts} +2 -2
- package/esm/{useDemo/flattenVariant.js → pipeline/loadCodeVariant/flattenCodeVariant.js} +3 -3
- package/esm/{CodeHighlighter/hasAllVariants.d.ts → pipeline/loadCodeVariant/hasAllCodeVariants.d.ts} +1 -1
- package/esm/pipeline/loadCodeVariant/index.d.ts +10 -0
- package/esm/pipeline/loadCodeVariant/index.js +17 -0
- package/esm/{CodeHighlighter/loadFallbackCode.d.ts → pipeline/loadCodeVariant/loadCodeFallback.d.ts} +2 -2
- package/esm/{CodeHighlighter/loadFallbackCode.js → pipeline/loadCodeVariant/loadCodeFallback.js} +180 -106
- package/esm/{CodeHighlighter/loadVariant.d.ts → pipeline/loadCodeVariant/loadCodeVariant.d.ts} +2 -2
- package/esm/{CodeHighlighter/loadVariant.js → pipeline/loadCodeVariant/loadCodeVariant.js} +122 -49
- package/esm/{CodeHighlighter/maybeInitialData.d.ts → pipeline/loadCodeVariant/maybeCodeInitialData.d.ts} +6 -6
- package/esm/{CodeHighlighter/maybeInitialData.js → pipeline/loadCodeVariant/maybeCodeInitialData.js} +6 -6
- package/esm/{CodeHighlighter/mergeMetadata.d.ts → pipeline/loadCodeVariant/mergeCodeMetadata.d.ts} +3 -3
- package/esm/{CodeHighlighter/mergeMetadata.js → pipeline/loadCodeVariant/mergeCodeMetadata.js} +3 -3
- package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.d.ts +1 -1
- package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.d.ts +1 -1
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +86 -13
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.d.ts +30 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +77 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +7 -7
- package/esm/pipeline/loadPrecomputedSitemap/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedSitemap/index.js +4 -0
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.ts +10 -0
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +213 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +2 -1
- package/esm/pipeline/loadServerCodeMeta/index.js +2 -1
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +1 -1
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +2 -2
- package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.d.ts +1 -1
- package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.js +1 -1
- package/esm/pipeline/loadServerPageIndex/index.d.ts +2 -0
- package/esm/pipeline/loadServerPageIndex/index.js +1 -0
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.d.ts +51 -0
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +174 -0
- package/esm/pipeline/loadServerSitemap/index.d.ts +2 -0
- package/esm/pipeline/loadServerSitemap/index.js +1 -0
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.d.ts +39 -0
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +168 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +1 -1
- package/esm/pipeline/loaderUtils/externalsToPackages.js +1 -1
- package/esm/pipeline/loaderUtils/processRelativeImports.js +16 -3
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +36 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +139 -8
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.d.ts +76 -0
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +305 -0
- package/esm/pipeline/syncPageIndex/index.d.ts +1 -0
- package/esm/pipeline/syncPageIndex/index.js +1 -0
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.d.ts +58 -0
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +214 -0
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.d.ts +67 -0
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +1486 -0
- package/esm/pipeline/syncPageIndex/syncPageIndex.d.ts +108 -0
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +540 -0
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +2 -2
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +5 -5
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
- package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
- package/esm/pipeline/transformMarkdownMetadata/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownMetadata/index.js +4 -0
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.d.ts +3 -0
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +1010 -0
- package/esm/pipeline/transformMarkdownMetadata/types.d.ts +110 -0
- package/esm/pipeline/transformMarkdownMetadata/types.js +1 -0
- package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +15 -0
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +40 -0
- package/esm/useCode/Pre.js +15 -2
- package/esm/useCode/useCode.d.ts +15 -2
- package/esm/useCode/useCode.js +15 -6
- package/esm/useCode/useCodeUtils.js +3 -3
- package/esm/useCode/useFileNavigation.d.ts +9 -3
- package/esm/useCode/useFileNavigation.js +124 -81
- package/esm/useCode/useUIState.d.ts +4 -1
- package/esm/useCode/useUIState.js +17 -2
- package/esm/useCode/useVariantSelection.d.ts +8 -3
- package/esm/useCode/useVariantSelection.js +144 -52
- package/esm/useCopier/index.js +5 -4
- package/esm/useDemo/createCodeSandbox.d.ts +1 -1
- package/esm/useDemo/createStackBlitz.d.ts +1 -1
- package/esm/useDemo/exportVariant.js +13 -11
- package/esm/useDemo/index.d.ts +1 -1
- package/esm/useDemo/index.js +1 -1
- package/esm/useDemo/useDemo.d.ts +5 -5
- package/esm/useDemo/useDemo.js +6 -6
- package/esm/useErrors/useErrors.d.ts +1 -1
- package/esm/useErrors/useErrors.js +6 -2
- package/esm/useSearch/index.d.ts +1 -0
- package/esm/useSearch/index.js +1 -0
- package/esm/useSearch/types.d.ts +165 -0
- package/esm/useSearch/types.js +1 -0
- package/esm/useSearch/useSearch.d.ts +56 -0
- package/esm/useSearch/useSearch.js +647 -0
- package/esm/withDocsInfra/withDeploymentConfig.js +4 -2
- package/esm/withDocsInfra/withDocsInfra.d.ts +39 -0
- package/esm/withDocsInfra/withDocsInfra.js +79 -7
- package/package.json +105 -5
- package/esm/CodeHighlighter/transformParsedSource.d.ts +0 -3
- /package/esm/{CodeHighlighter/addPathsToVariant.js → pipeline/loadCodeVariant/addCodeVariantPaths.js} +0 -0
- /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.d.ts +0 -0
- /package/esm/{CodeHighlighter/hasAllVariants.js → pipeline/loadCodeVariant/hasAllCodeVariants.js} +0 -0
- /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.js +0 -0
- /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.d.ts +0 -0
- /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.js +0 -0
- /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.js +0 -0
|
@@ -3,6 +3,137 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
3
3
|
* Interface for rewrite replacement operations.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Converts import statements to const declarations set to null.
|
|
8
|
+
* This preserves variable names while removing the actual imports.
|
|
9
|
+
* Useful when precomputing data that makes the imports unnecessary.
|
|
10
|
+
*
|
|
11
|
+
* @param source - The source code to process
|
|
12
|
+
* @param importPathsToRewrite - Set of import paths whose import statements should be rewritten
|
|
13
|
+
* @param importResult - Import result with position and name data
|
|
14
|
+
* @returns The source code with import statements rewritten to const declarations
|
|
15
|
+
*/
|
|
16
|
+
export function rewriteImportsToNull(source, importPathsToRewrite, importResult) {
|
|
17
|
+
var replacements = [];
|
|
18
|
+
|
|
19
|
+
// Find all import statements to rewrite
|
|
20
|
+
importPathsToRewrite.forEach(function (importPath) {
|
|
21
|
+
var importData = importResult[importPath];
|
|
22
|
+
if (importData && importData.positions.length > 0) {
|
|
23
|
+
// For each position (there should typically be one per import statement)
|
|
24
|
+
var _iterator = _createForOfIteratorHelper(importData.positions),
|
|
25
|
+
_step;
|
|
26
|
+
try {
|
|
27
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
28
|
+
var position = _step.value;
|
|
29
|
+
// Parse backwards from the quote to find 'import' keyword
|
|
30
|
+
var importStart = position.start;
|
|
31
|
+
var targetWord = 'import';
|
|
32
|
+
while (importStart >= targetWord.length) {
|
|
33
|
+
var slice = source.slice(importStart - targetWord.length, importStart);
|
|
34
|
+
var prevChar = importStart > targetWord.length ? source[importStart - targetWord.length - 1] : '';
|
|
35
|
+
if (slice === targetWord && (!prevChar || /\s/.test(prevChar))) {
|
|
36
|
+
importStart -= targetWord.length;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
importStart -= 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Parse forwards from after the closing quote to find semicolon/newline
|
|
43
|
+
// position.end points to the character AFTER the closing quote
|
|
44
|
+
var importEnd = position.end;
|
|
45
|
+
|
|
46
|
+
// Check for optional semicolon
|
|
47
|
+
if (importEnd < source.length && source[importEnd] === ';') {
|
|
48
|
+
importEnd += 1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Check for newline after the statement
|
|
52
|
+
var hasTrailingNewline = false;
|
|
53
|
+
if (importEnd < source.length && source[importEnd] === '\n') {
|
|
54
|
+
hasTrailingNewline = true;
|
|
55
|
+
importEnd += 1;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Generate const declarations from import names
|
|
59
|
+
var constDeclarations = importData.names.map(function (nameInfo) {
|
|
60
|
+
var varName = nameInfo.alias || nameInfo.name;
|
|
61
|
+
return "const ".concat(varName, " = null;");
|
|
62
|
+
}).join('\n');
|
|
63
|
+
|
|
64
|
+
// Add newline if original import had one
|
|
65
|
+
var newText = constDeclarations + (hasTrailingNewline ? '\n' : '');
|
|
66
|
+
replacements.push({
|
|
67
|
+
start: importStart,
|
|
68
|
+
end: importEnd,
|
|
69
|
+
newText: newText
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
} catch (err) {
|
|
73
|
+
_iterator.e(err);
|
|
74
|
+
} finally {
|
|
75
|
+
_iterator.f();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Sort replacements by position (descending) to avoid position shifts
|
|
81
|
+
replacements.sort(function (a, b) {
|
|
82
|
+
return b.start - a.start;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Apply replacements from right to left (using same logic as rewriteImports)
|
|
86
|
+
var result = source;
|
|
87
|
+
for (var _i = 0, _replacements = replacements; _i < _replacements.length; _i++) {
|
|
88
|
+
var replacement = _replacements[_i];
|
|
89
|
+
result = result.slice(0, replacement.start) + replacement.newText + result.slice(replacement.end);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Removes entire import statements for the specified import paths.
|
|
96
|
+
* This removes the full import line, not just the path.
|
|
97
|
+
*
|
|
98
|
+
* @param source - The source code to process
|
|
99
|
+
* @param importPathsToRemove - Set of import paths whose entire import statements should be removed
|
|
100
|
+
* @param importResult - Import result with position data
|
|
101
|
+
* @returns The source code with import statements removed
|
|
102
|
+
*/
|
|
103
|
+
export function removeImports(source, importPathsToRemove, importResult) {
|
|
104
|
+
var linesToRemove = new Set();
|
|
105
|
+
|
|
106
|
+
// Find all line numbers that contain imports to remove
|
|
107
|
+
importPathsToRemove.forEach(function (importPath) {
|
|
108
|
+
var _importResult$importP;
|
|
109
|
+
var positions = (_importResult$importP = importResult[importPath]) == null ? void 0 : _importResult$importP.positions;
|
|
110
|
+
if (positions && positions.length > 0) {
|
|
111
|
+
var _iterator2 = _createForOfIteratorHelper(positions),
|
|
112
|
+
_step2;
|
|
113
|
+
try {
|
|
114
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
115
|
+
var position = _step2.value;
|
|
116
|
+
// Find which line this position is on
|
|
117
|
+
var beforePosition = source.slice(0, position.start);
|
|
118
|
+
var lineNumber = (beforePosition.match(/\n/g) || []).length;
|
|
119
|
+
linesToRemove.add(lineNumber);
|
|
120
|
+
}
|
|
121
|
+
} catch (err) {
|
|
122
|
+
_iterator2.e(err);
|
|
123
|
+
} finally {
|
|
124
|
+
_iterator2.f();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
// Split source into lines and filter out lines to remove
|
|
130
|
+
var lines = source.split('\n');
|
|
131
|
+
var filteredLines = lines.filter(function (_, index) {
|
|
132
|
+
return !linesToRemove.has(index);
|
|
133
|
+
});
|
|
134
|
+
return filteredLines.join('\n');
|
|
135
|
+
}
|
|
136
|
+
|
|
6
137
|
/**
|
|
7
138
|
* Efficiently rewrites import paths using position data.
|
|
8
139
|
* This avoids regex parsing and uses precise position information for replacement.
|
|
@@ -22,11 +153,11 @@ export function rewriteImports(source, importPathMapping, importResult) {
|
|
|
22
153
|
var positions = (_importResult$origina = importResult[originalPath]) == null ? void 0 : _importResult$origina.positions;
|
|
23
154
|
if (positions && positions.length > 0) {
|
|
24
155
|
// Process all positions where this import path appears
|
|
25
|
-
var
|
|
26
|
-
|
|
156
|
+
var _iterator3 = _createForOfIteratorHelper(positions),
|
|
157
|
+
_step3;
|
|
27
158
|
try {
|
|
28
|
-
for (
|
|
29
|
-
var position =
|
|
159
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
160
|
+
var position = _step3.value;
|
|
30
161
|
// Validate position bounds
|
|
31
162
|
if (position.start >= 0 && position.end <= source.length && position.start < position.end) {
|
|
32
163
|
// The positions include the quotes, so we need to preserve them
|
|
@@ -43,9 +174,9 @@ export function rewriteImports(source, importPathMapping, importResult) {
|
|
|
43
174
|
}
|
|
44
175
|
}
|
|
45
176
|
} catch (err) {
|
|
46
|
-
|
|
177
|
+
_iterator3.e(err);
|
|
47
178
|
} finally {
|
|
48
|
-
|
|
179
|
+
_iterator3.f();
|
|
49
180
|
}
|
|
50
181
|
}
|
|
51
182
|
});
|
|
@@ -57,8 +188,8 @@ export function rewriteImports(source, importPathMapping, importResult) {
|
|
|
57
188
|
|
|
58
189
|
// Apply replacements from right to left
|
|
59
190
|
var result = source;
|
|
60
|
-
for (var
|
|
61
|
-
var replacement =
|
|
191
|
+
for (var _i2 = 0, _replacements2 = replacements; _i2 < _replacements2.length; _i2++) {
|
|
192
|
+
var replacement = _replacements2[_i2];
|
|
62
193
|
result = result.slice(0, replacement.start) + replacement.newText + result.slice(replacement.end);
|
|
63
194
|
}
|
|
64
195
|
return result;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createMarkdownNodes.ts - Helper functions for creating MD AST nodes
|
|
3
|
+
*
|
|
4
|
+
* This module provides utility functions to create nodes for Markdown
|
|
5
|
+
* abstract syntax trees, making transformer code more readable and maintainable.
|
|
6
|
+
*/
|
|
7
|
+
import type { PhrasingContent, Text, Paragraph, Heading, Code, InlineCode, Table, Emphasis, Strong, Definition } from 'mdast';
|
|
8
|
+
/**
|
|
9
|
+
* Create a text node
|
|
10
|
+
* @param value - The text content
|
|
11
|
+
* @returns A text node
|
|
12
|
+
*/
|
|
13
|
+
export declare function text(value: string): Text;
|
|
14
|
+
type Child = PhrasingContent | string;
|
|
15
|
+
/**
|
|
16
|
+
* Create a paragraph node
|
|
17
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
18
|
+
* @returns A paragraph node
|
|
19
|
+
*/
|
|
20
|
+
export declare function paragraph(children: Child | Child[]): Paragraph;
|
|
21
|
+
/**
|
|
22
|
+
* Create an emphasis (italic) node
|
|
23
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
24
|
+
* @returns An emphasis node
|
|
25
|
+
*/
|
|
26
|
+
export declare function emphasis(children: Child | Child[]): Emphasis;
|
|
27
|
+
/**
|
|
28
|
+
* Create a strong (bold) node
|
|
29
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
30
|
+
* @returns A strong node
|
|
31
|
+
*/
|
|
32
|
+
export declare function strong(children: Child | Child[]): Strong;
|
|
33
|
+
/**
|
|
34
|
+
* Create a heading node
|
|
35
|
+
* @param depth - Heading level (1-6)
|
|
36
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
37
|
+
* @returns A heading node
|
|
38
|
+
*/
|
|
39
|
+
export declare function heading(depth: 1 | 2 | 3 | 4 | 5 | 6, children: Child | Child[]): Heading;
|
|
40
|
+
/**
|
|
41
|
+
* Create a code block node
|
|
42
|
+
* @param {string} value - Code content
|
|
43
|
+
* @param {string} lang - Language for syntax highlighting
|
|
44
|
+
* @returns {Object} A code node
|
|
45
|
+
*/
|
|
46
|
+
export declare function code(value: string, lang?: string): Code;
|
|
47
|
+
/**
|
|
48
|
+
* Create an inline code node
|
|
49
|
+
* @param {string} value - Code content
|
|
50
|
+
* @returns {Object} An inline code node
|
|
51
|
+
*/
|
|
52
|
+
export declare function inlineCode(value: string): InlineCode;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a markdown table node (GFM)
|
|
55
|
+
* @param {Array<string|Object>} headers - Array of header strings or nodes
|
|
56
|
+
* @param {Array<Array<string|Object>>} rows - Array of row data, each row is an array of cell content
|
|
57
|
+
* @param {Array<string>} [alignment] - Optional array of alignments ('left', 'center', 'right') for each column
|
|
58
|
+
* @param {number} [widthIncrements] - Optional value to control the increments that tables expand for cleaner
|
|
59
|
+
* @returns {Object} A table node
|
|
60
|
+
*/
|
|
61
|
+
export declare function table(headers: (Child | Child[])[], rows: (Child | Child[])[][], alignment?: string[] | null, widthIncrements?: number): Table;
|
|
62
|
+
/**
|
|
63
|
+
* Create a comment node. Comment text will not be rendered in HTML output.
|
|
64
|
+
* @param value - Comment text
|
|
65
|
+
* @returns A comment node
|
|
66
|
+
*/
|
|
67
|
+
export declare function comment(value: string, ref?: string): Definition;
|
|
68
|
+
/**
|
|
69
|
+
* Create a link node
|
|
70
|
+
* @param url - The URL to link to
|
|
71
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
72
|
+
* @param title - Optional title attribute
|
|
73
|
+
* @returns A link node
|
|
74
|
+
*/
|
|
75
|
+
export declare function link(url: string, children: Child | Child[], title?: string): PhrasingContent;
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
/**
|
|
4
|
+
* createMarkdownNodes.ts - Helper functions for creating MD AST nodes
|
|
5
|
+
*
|
|
6
|
+
* This module provides utility functions to create nodes for Markdown
|
|
7
|
+
* abstract syntax trees, making transformer code more readable and maintainable.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Create a text node
|
|
12
|
+
* @param value - The text content
|
|
13
|
+
* @returns A text node
|
|
14
|
+
*/
|
|
15
|
+
export function text(value) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'text',
|
|
18
|
+
value: value || ''
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Helper to normalize children (handles string, node, or array)
|
|
23
|
+
* @param children - Child content
|
|
24
|
+
* @returns Normalized array of nodes
|
|
25
|
+
*/
|
|
26
|
+
function normalizeChildren(children) {
|
|
27
|
+
// Handle empty or undefined
|
|
28
|
+
if (!children) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Convert to array if not already
|
|
33
|
+
var childArray = Array.isArray(children) ? children : [children];
|
|
34
|
+
|
|
35
|
+
// Convert strings to text nodes
|
|
36
|
+
return childArray.map(function (child) {
|
|
37
|
+
return typeof child === 'string' ? text(child) : child;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Create a paragraph node
|
|
43
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
44
|
+
* @returns A paragraph node
|
|
45
|
+
*/
|
|
46
|
+
export function paragraph(children) {
|
|
47
|
+
return {
|
|
48
|
+
type: 'paragraph',
|
|
49
|
+
children: normalizeChildren(children)
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create an emphasis (italic) node
|
|
55
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
56
|
+
* @returns An emphasis node
|
|
57
|
+
*/
|
|
58
|
+
export function emphasis(children) {
|
|
59
|
+
return {
|
|
60
|
+
type: 'emphasis',
|
|
61
|
+
children: normalizeChildren(children)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Create a strong (bold) node
|
|
67
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
68
|
+
* @returns A strong node
|
|
69
|
+
*/
|
|
70
|
+
export function strong(children) {
|
|
71
|
+
return {
|
|
72
|
+
type: 'strong',
|
|
73
|
+
children: normalizeChildren(children)
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a heading node
|
|
79
|
+
* @param depth - Heading level (1-6)
|
|
80
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
81
|
+
* @returns A heading node
|
|
82
|
+
*/
|
|
83
|
+
export function heading(depth, children) {
|
|
84
|
+
return {
|
|
85
|
+
type: 'heading',
|
|
86
|
+
depth: depth || 1,
|
|
87
|
+
children: normalizeChildren(children)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create a code block node
|
|
93
|
+
* @param {string} value - Code content
|
|
94
|
+
* @param {string} lang - Language for syntax highlighting
|
|
95
|
+
* @returns {Object} A code node
|
|
96
|
+
*/
|
|
97
|
+
export function code(value, lang) {
|
|
98
|
+
return {
|
|
99
|
+
type: 'code',
|
|
100
|
+
lang: lang || null,
|
|
101
|
+
value: value || ''
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Create an inline code node
|
|
107
|
+
* @param {string} value - Code content
|
|
108
|
+
* @returns {Object} An inline code node
|
|
109
|
+
*/
|
|
110
|
+
export function inlineCode(value) {
|
|
111
|
+
return {
|
|
112
|
+
type: 'inlineCode',
|
|
113
|
+
value: value || ''
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Calculate the visual length of phrasing content
|
|
119
|
+
* (e.g., "One `two` three" has visual length of ~13, or ~9 if excludeFormatting=true)
|
|
120
|
+
* @param node - The phrasing content node
|
|
121
|
+
* @param excludeFormatting - If true, don't count formatting characters like backticks, brackets, etc.
|
|
122
|
+
* This allows "`false`" and "false" to both be treated as length 5.
|
|
123
|
+
*/
|
|
124
|
+
function getPhrasingContentLength(node) {
|
|
125
|
+
var excludeFormatting = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
126
|
+
switch (node.type) {
|
|
127
|
+
case 'text':
|
|
128
|
+
return node.value.length;
|
|
129
|
+
case 'inlineCode':
|
|
130
|
+
// Backticks add 2 chars, but exclude them if normalizing
|
|
131
|
+
return node.value.length + (excludeFormatting ? 0 : 2);
|
|
132
|
+
case 'emphasis':
|
|
133
|
+
// Asterisks/underscores add chars, but exclude them if normalizing
|
|
134
|
+
return (node.children || []).reduce(function (sum, child) {
|
|
135
|
+
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
136
|
+
}, excludeFormatting ? 0 : 2 // *text* or _text_ adds 2 chars
|
|
137
|
+
);
|
|
138
|
+
case 'strong':
|
|
139
|
+
// Double asterisks/underscores add chars, but exclude them if normalizing
|
|
140
|
+
return (node.children || []).reduce(function (sum, child) {
|
|
141
|
+
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
142
|
+
}, excludeFormatting ? 0 : 4 // **text** or __text__ adds 4 chars
|
|
143
|
+
);
|
|
144
|
+
case 'delete':
|
|
145
|
+
// Tildes add chars, but exclude them if normalizing
|
|
146
|
+
return (node.children || []).reduce(function (sum, child) {
|
|
147
|
+
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
148
|
+
}, excludeFormatting ? 0 : 4 // ~~text~~ adds 4 chars
|
|
149
|
+
);
|
|
150
|
+
case 'link':
|
|
151
|
+
{
|
|
152
|
+
var _node$url;
|
|
153
|
+
// [text](url) format adds chars, but exclude them if normalizing
|
|
154
|
+
var childrenLength = (node.children || []).reduce(function (sum, child) {
|
|
155
|
+
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
156
|
+
}, 0);
|
|
157
|
+
return excludeFormatting ? childrenLength : childrenLength + 4 + (((_node$url = node.url) == null ? void 0 : _node$url.length) || 0); // [](url) adds 4 + url length
|
|
158
|
+
}
|
|
159
|
+
case 'image':
|
|
160
|
+
{
|
|
161
|
+
var _node$url2;
|
|
162
|
+
//  format
|
|
163
|
+
var altLength = (node.alt || '').length;
|
|
164
|
+
return excludeFormatting ? altLength : altLength + 5 + (((_node$url2 = node.url) == null ? void 0 : _node$url2.length) || 0); //  adds 5 + url length
|
|
165
|
+
}
|
|
166
|
+
case 'break':
|
|
167
|
+
return 0;
|
|
168
|
+
default:
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Creates a table cell node
|
|
175
|
+
* @param content - Cell content
|
|
176
|
+
* @param widthIncrements - Optional width increment for padding alignment
|
|
177
|
+
* @param excludeFormatting - If true, don't count formatting chars when calculating width
|
|
178
|
+
* @returns Table cell node
|
|
179
|
+
*/
|
|
180
|
+
function tableCell(content, widthIncrements) {
|
|
181
|
+
var excludeFormatting = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
|
182
|
+
var children = normalizeChildren(content);
|
|
183
|
+
if (widthIncrements) {
|
|
184
|
+
// Calculate total visual length of all content
|
|
185
|
+
var totalLength = children.reduce(function (sum, child) {
|
|
186
|
+
return sum + getPhrasingContentLength(child, excludeFormatting);
|
|
187
|
+
}, 0);
|
|
188
|
+
|
|
189
|
+
// Calculate padding needed
|
|
190
|
+
var paddingNeeded = Math.ceil(totalLength / widthIncrements) * widthIncrements - totalLength;
|
|
191
|
+
|
|
192
|
+
// Add padding as trailing spaces to the last text node, or create a new text node
|
|
193
|
+
if (paddingNeeded > 0) {
|
|
194
|
+
var spaces = new Array(paddingNeeded).fill(' ').join('');
|
|
195
|
+
|
|
196
|
+
// Find the last text node and append spaces (reverse search)
|
|
197
|
+
var lastTextIndex = -1;
|
|
198
|
+
for (var i = children.length - 1; i >= 0; i -= 1) {
|
|
199
|
+
if (children[i].type === 'text') {
|
|
200
|
+
lastTextIndex = i;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (lastTextIndex >= 0) {
|
|
205
|
+
var lastText = children[lastTextIndex];
|
|
206
|
+
children[lastTextIndex] = _extends(_extends({}, lastText), {}, {
|
|
207
|
+
value: "".concat(lastText.value).concat(spaces)
|
|
208
|
+
});
|
|
209
|
+
} else {
|
|
210
|
+
// No text node found, add a new text node with just spaces
|
|
211
|
+
children.push(text(spaces));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
type: 'tableCell',
|
|
217
|
+
children: children
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Creates a table row node
|
|
223
|
+
* @param cells - Array of cell contents
|
|
224
|
+
* @returns Table row node
|
|
225
|
+
*/
|
|
226
|
+
function tableRow(cells, widthIncrements) {
|
|
227
|
+
return {
|
|
228
|
+
type: 'tableRow',
|
|
229
|
+
children: cells.map(function (cell) {
|
|
230
|
+
return tableCell(cell, widthIncrements);
|
|
231
|
+
})
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Creates a markdown table node (GFM)
|
|
237
|
+
* @param {Array<string|Object>} headers - Array of header strings or nodes
|
|
238
|
+
* @param {Array<Array<string|Object>>} rows - Array of row data, each row is an array of cell content
|
|
239
|
+
* @param {Array<string>} [alignment] - Optional array of alignments ('left', 'center', 'right') for each column
|
|
240
|
+
* @param {number} [widthIncrements] - Optional value to control the increments that tables expand for cleaner
|
|
241
|
+
* @returns {Object} A table node
|
|
242
|
+
*/
|
|
243
|
+
export function table(headers, rows) {
|
|
244
|
+
var alignment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
245
|
+
var widthIncrements = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 7;
|
|
246
|
+
// Convert alignment strings to AST format
|
|
247
|
+
var align = headers.map(function (_, index) {
|
|
248
|
+
if (!alignment || !alignment[index]) {
|
|
249
|
+
return null;
|
|
250
|
+
}
|
|
251
|
+
switch (alignment[index]) {
|
|
252
|
+
case 'center':
|
|
253
|
+
return 'center';
|
|
254
|
+
case 'right':
|
|
255
|
+
return 'right';
|
|
256
|
+
default:
|
|
257
|
+
return 'left';
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// Create header row
|
|
262
|
+
var headerRow = tableRow(headers);
|
|
263
|
+
|
|
264
|
+
// Create data rows - rows is actually an array of arrays
|
|
265
|
+
var dataRows = rows.map(function (row) {
|
|
266
|
+
return tableRow(row, widthIncrements);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Return table node
|
|
270
|
+
return {
|
|
271
|
+
type: 'table',
|
|
272
|
+
align: align,
|
|
273
|
+
children: [headerRow].concat(_toConsumableArray(dataRows))
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Create a comment node. Comment text will not be rendered in HTML output.
|
|
279
|
+
* @param value - Comment text
|
|
280
|
+
* @returns A comment node
|
|
281
|
+
*/
|
|
282
|
+
export function comment(value, ref) {
|
|
283
|
+
return {
|
|
284
|
+
type: 'definition',
|
|
285
|
+
identifier: '//',
|
|
286
|
+
url: ref || '#',
|
|
287
|
+
title: value
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Create a link node
|
|
293
|
+
* @param url - The URL to link to
|
|
294
|
+
* @param children - Child node, string, or array of nodes/strings
|
|
295
|
+
* @param title - Optional title attribute
|
|
296
|
+
* @returns A link node
|
|
297
|
+
*/
|
|
298
|
+
export function link(url, children, title) {
|
|
299
|
+
return {
|
|
300
|
+
type: 'link',
|
|
301
|
+
url: url,
|
|
302
|
+
title: title,
|
|
303
|
+
children: normalizeChildren(children)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./syncPageIndex.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./syncPageIndex.js";
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type MetadataToMarkdownOptions, type PagesMetadata } from "./metadataToMarkdown.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for mergeMetadataMarkdown
|
|
4
|
+
*/
|
|
5
|
+
export interface MergeMetadataMarkdownOptions extends Omit<MetadataToMarkdownOptions, 'editableMarker' | 'indexWrapperComponent'> {
|
|
6
|
+
/** If true, pages in existing markdown that aren't in newMetadata will be preserved. If false (default), they are removed. */
|
|
7
|
+
preserveUnlisted?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Component name to wrap the autogenerated content.
|
|
10
|
+
* - `undefined`: preserve existing wrapper (if any)
|
|
11
|
+
* - `null`: explicitly remove the wrapper
|
|
12
|
+
* - `string`: use this component name
|
|
13
|
+
*/
|
|
14
|
+
indexWrapperComponent?: string | null;
|
|
15
|
+
/**
|
|
16
|
+
* The path to the file being generated. Used in autogenerated comments to help
|
|
17
|
+
* users validate the file.
|
|
18
|
+
*/
|
|
19
|
+
path?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Merges new page metadata with existing markdown content, preserving the order
|
|
23
|
+
* of pages from the existing markdown when available, unless the file contains
|
|
24
|
+
* only the autogeneration marker (no editable section), in which case pages are
|
|
25
|
+
* sorted alphabetically by title.
|
|
26
|
+
*
|
|
27
|
+
* Pages are matched by their `path` property (e.g., './button/page.mdx'), not by slug.
|
|
28
|
+
* This allows multiple pages to have the same slug (anchor) while still being treated
|
|
29
|
+
* as distinct pages.
|
|
30
|
+
*
|
|
31
|
+
* @param existingMarkdown - The existing markdown content (or undefined if none exists)
|
|
32
|
+
* @param newMetadata - The new metadata to merge in
|
|
33
|
+
* @param options - Optional configuration
|
|
34
|
+
* @param options.preserveUnlisted - If true, pages in existing markdown that aren't in newMetadata will be preserved. If false (default), they are removed.
|
|
35
|
+
* @param options.indexWrapperComponent - Optional component name to wrap the autogenerated content (e.g., 'PagesIndex')
|
|
36
|
+
* @returns The updated markdown content with merged metadata
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* const existingMarkdown = `# Components
|
|
41
|
+
* - [Button](#button) - [Full Docs](./button/page.mdx) - A button
|
|
42
|
+
* - [Checkbox](#checkbox) - [Full Docs](./checkbox/page.mdx) - A checkbox
|
|
43
|
+
* `;
|
|
44
|
+
*
|
|
45
|
+
* const newMetadata = {
|
|
46
|
+
* title: 'Components',
|
|
47
|
+
* pages: [
|
|
48
|
+
* { slug: 'checkbox', path: './checkbox/page.mdx', title: 'Checkbox', description: 'Updated checkbox' },
|
|
49
|
+
* { slug: 'button', path: './button/page.mdx', title: 'Button', description: 'Updated button' },
|
|
50
|
+
* { slug: 'input', path: './input/page.mdx', title: 'Input', description: 'New input' },
|
|
51
|
+
* ],
|
|
52
|
+
* };
|
|
53
|
+
*
|
|
54
|
+
* const result = await mergeMetadataMarkdown(existingMarkdown, newMetadata);
|
|
55
|
+
* // Result preserves Button, Checkbox order from existing markdown, adds Input at the end
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function mergeMetadataMarkdown(existingMarkdown: string | undefined, newMetadata: PagesMetadata, options?: MergeMetadataMarkdownOptions): Promise<string>;
|