@mui/internal-docs-infra 0.12.1-canary.46 → 0.12.1-canary.48
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/package.json +2 -3
- package/pipeline/parseSource/index.d.mts +1 -1
- package/pipeline/parseSource/index.mjs +1 -1
- package/pipeline/parseSource/parseSource.d.mts +11 -1
- package/pipeline/parseSource/parseSource.mjs +15 -0
- package/pipeline/transformHtmlCodeInline/transformHtmlCodeInline.mjs +18 -50
- package/useSearch/types.d.mts +1 -1
- package/useSearch/useSearch.mjs +1 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-docs-infra",
|
|
3
|
-
"version": "0.12.1-canary.
|
|
3
|
+
"version": "0.12.1-canary.48",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI Infra - internal documentation creation tools.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"@orama/orama": "^3.1.18",
|
|
37
37
|
"@orama/plugin-qps": "^3.1.18",
|
|
38
38
|
"@orama/stemmers": "^3.1.18",
|
|
39
|
-
"@orama/stopwords": "^3.1.18",
|
|
40
39
|
"@wooorm/starry-night": "^3.11.0",
|
|
41
40
|
"autoprefixer": "^10.5.5",
|
|
42
41
|
"chalk": "^6.0.0",
|
|
@@ -815,5 +814,5 @@
|
|
|
815
814
|
"bin": {
|
|
816
815
|
"docs-infra": "./cli/index.mjs"
|
|
817
816
|
},
|
|
818
|
-
"gitSha": "
|
|
817
|
+
"gitSha": "b296c98bc17f685db974504d2c00094a59d1698d"
|
|
819
818
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { createParseSource, parsePlainText, parseSource, registerAllGrammars, registerGrammars, resetStarryNight } from "./parseSource.mjs";
|
|
2
2
|
export { getGrammarFromLanguage, languageToGrammarMap, extensionMap } from "./grammarMaps.mjs";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { createParseSource, parsePlainText, parseSource, registerAllGrammars, registerGrammars, resetStarryNight } from "./parseSource.mjs";
|
|
2
2
|
export { getGrammarFromLanguage, languageToGrammarMap, extensionMap } from "./grammarMaps.mjs";
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { createStarryNight } from '@wooorm/starry-night';
|
|
1
2
|
import type { ParseSource } from "../../CodeHighlighter/types.mjs";
|
|
3
|
+
type StarryNight = Awaited<ReturnType<typeof createStarryNight>>;
|
|
2
4
|
/**
|
|
3
5
|
* Parses source into a line-guttered HAST **without** syntax highlighting — the
|
|
4
6
|
* raw text wrapped in the same `.line`/`.frame` structure `parseSource` produces,
|
|
@@ -51,8 +53,16 @@ export declare function registerAllGrammars(): Promise<void>;
|
|
|
51
53
|
* @returns A Promise that resolves to the initialized `parseSource` function
|
|
52
54
|
*/
|
|
53
55
|
export declare const createParseSource: (initialScopes?: string[]) => Promise<ParseSource>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns the shared Starry Night instance after registering every grammar.
|
|
58
|
+
*
|
|
59
|
+
* Inline highlighting can follow code that initialized a lazy subset, so it must
|
|
60
|
+
* initialize the complete registry before using the shared instance.
|
|
61
|
+
*/
|
|
62
|
+
export declare function getStarryNightInstance(): Promise<StarryNight>;
|
|
54
63
|
/**
|
|
55
64
|
* Clears the global Starry Night singleton and registration state. Intended for
|
|
56
65
|
* tests exercising lazy registration from a known-empty registry.
|
|
57
66
|
*/
|
|
58
|
-
export declare function resetStarryNight(): void;
|
|
67
|
+
export declare function resetStarryNight(): void;
|
|
68
|
+
export {};
|
|
@@ -232,6 +232,21 @@ export const createParseSource = async initialScopes => {
|
|
|
232
232
|
return parseSource;
|
|
233
233
|
};
|
|
234
234
|
|
|
235
|
+
/**
|
|
236
|
+
* Returns the shared Starry Night instance after registering every grammar.
|
|
237
|
+
*
|
|
238
|
+
* Inline highlighting can follow code that initialized a lazy subset, so it must
|
|
239
|
+
* initialize the complete registry before using the shared instance.
|
|
240
|
+
*/
|
|
241
|
+
export async function getStarryNightInstance() {
|
|
242
|
+
await createParseSource();
|
|
243
|
+
const instance = getInstance();
|
|
244
|
+
if (!instance) {
|
|
245
|
+
throw new Error('Starry Night failed to initialize.');
|
|
246
|
+
}
|
|
247
|
+
return instance;
|
|
248
|
+
}
|
|
249
|
+
|
|
235
250
|
/**
|
|
236
251
|
* Clears the global Starry Night singleton and registration state. Intended for
|
|
237
252
|
* tests exercising lazy registration from a known-empty registry.
|
|
@@ -1,29 +1,27 @@
|
|
|
1
|
-
import { createStarryNight } from '@wooorm/starry-night';
|
|
2
1
|
import { visit } from 'unist-util-visit';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { getStarryNightInstance } from "../parseSource/parseSource.mjs";
|
|
3
|
+
import { getGrammarFromLanguage } from "../parseSource/grammarMaps.mjs";
|
|
5
4
|
import { extendSyntaxTokens } from "../parseSource/extendSyntaxTokens.mjs";
|
|
6
5
|
import { getLanguageCapabilitiesFromScope } from "../parseSource/languageCapabilities.mjs";
|
|
7
6
|
import { getHastTextContent } from "../hastUtils/index.mjs";
|
|
8
7
|
import { removePrefixFromHighlightedNodes } from "./removePrefixFromHighlightedNodes.mjs";
|
|
9
8
|
import { removeSuffixFromHighlightedNodes } from "./removeSuffixFromHighlightedNodes.mjs";
|
|
10
|
-
|
|
9
|
+
function getGrammarScope(node) {
|
|
10
|
+
const className = node.properties?.className;
|
|
11
|
+
if (!Array.isArray(className)) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
const languageClass = className.find(classNameValue => typeof classNameValue === 'string' && classNameValue.startsWith('language-'));
|
|
15
|
+
if (typeof languageClass !== 'string') {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
return getGrammarFromLanguage(languageClass.replace('language-', ''));
|
|
19
|
+
}
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* Options for the transformHtmlCodeInline plugin.
|
|
14
23
|
*/
|
|
15
24
|
|
|
16
|
-
/**
|
|
17
|
-
* Ensures Starry Night is initialized and returns the instance.
|
|
18
|
-
* Uses a global singleton for efficiency across multiple plugin invocations.
|
|
19
|
-
*/
|
|
20
|
-
async function getStarryNight() {
|
|
21
|
-
if (!globalThis[STARRY_NIGHT_KEY]) {
|
|
22
|
-
globalThis[STARRY_NIGHT_KEY] = await createStarryNight(grammars);
|
|
23
|
-
}
|
|
24
|
-
return globalThis[STARRY_NIGHT_KEY];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
25
|
/**
|
|
28
26
|
* A rehype plugin that applies inline syntax highlighting to code elements.
|
|
29
27
|
* Unlike transformHtmlCodeBlock, this does NOT add line gutters or precomputed data.
|
|
@@ -39,7 +37,7 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
39
37
|
includePreElements = false
|
|
40
38
|
} = options;
|
|
41
39
|
return async tree => {
|
|
42
|
-
const starryNight = await
|
|
40
|
+
const starryNight = await getStarryNightInstance();
|
|
43
41
|
visit(tree, 'element', (node, _index, parent) => {
|
|
44
42
|
// Only process code elements (inline code or code blocks without special handling)
|
|
45
43
|
if (node.tagName !== 'code') {
|
|
@@ -78,41 +76,11 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
78
76
|
// out the keys via `splitObjectKeys`. The wrapping characters are stripped after highlighting.
|
|
79
77
|
let objectWrap = false;
|
|
80
78
|
|
|
81
|
-
// Determine language from className (e.g., 'language-ts')
|
|
82
|
-
const className = node.properties?.className;
|
|
83
|
-
let fileType;
|
|
84
|
-
if (Array.isArray(className)) {
|
|
85
|
-
const langClass = className.find(c => typeof c === 'string' && c.startsWith('language-'));
|
|
86
|
-
if (langClass && typeof langClass === 'string') {
|
|
87
|
-
const lang = langClass.replace('language-', '');
|
|
88
|
-
// Map common language names to file extensions
|
|
89
|
-
const langToExt = {
|
|
90
|
-
ts: '.ts',
|
|
91
|
-
typescript: '.ts',
|
|
92
|
-
js: '.js',
|
|
93
|
-
javascript: '.js',
|
|
94
|
-
jsx: '.jsx',
|
|
95
|
-
tsx: '.tsx',
|
|
96
|
-
css: '.css',
|
|
97
|
-
html: '.html',
|
|
98
|
-
json: '.json',
|
|
99
|
-
md: '.md',
|
|
100
|
-
markdown: '.md',
|
|
101
|
-
sh: '.sh',
|
|
102
|
-
shell: '.sh',
|
|
103
|
-
bash: '.sh',
|
|
104
|
-
yaml: '.yaml',
|
|
105
|
-
yml: '.yaml'
|
|
106
|
-
};
|
|
107
|
-
fileType = langToExt[lang] || `.${lang}`;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
79
|
// Skip if no language specified or unsupported type
|
|
112
|
-
|
|
80
|
+
const grammarScope = getGrammarScope(node);
|
|
81
|
+
if (!grammarScope) {
|
|
113
82
|
return;
|
|
114
83
|
}
|
|
115
|
-
const grammarScope = extensionMap[fileType];
|
|
116
84
|
if (!highlightingPrefix && getLanguageCapabilitiesFromScope(grammarScope).semantics === 'js') {
|
|
117
85
|
const trimmed = sourceToHighlight.trim();
|
|
118
86
|
if (trimmed.length >= 2 && trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
@@ -122,8 +90,8 @@ export default function transformHtmlCodeInline(options = {}) {
|
|
|
122
90
|
}
|
|
123
91
|
|
|
124
92
|
// Apply syntax highlighting
|
|
125
|
-
const highlighted = starryNight.highlight(sourceToHighlight,
|
|
126
|
-
extendSyntaxTokens(highlighted,
|
|
93
|
+
const highlighted = starryNight.highlight(sourceToHighlight, grammarScope);
|
|
94
|
+
extendSyntaxTokens(highlighted, grammarScope);
|
|
127
95
|
|
|
128
96
|
// Replace the code element's children with the highlighted nodes
|
|
129
97
|
if (highlighted.type === 'root' && highlighted.children) {
|
package/useSearch/types.d.mts
CHANGED
|
@@ -84,7 +84,7 @@ export interface UseSearchOptions {
|
|
|
84
84
|
tolerance?: number;
|
|
85
85
|
/** Maximum number of search results */
|
|
86
86
|
limit?: number;
|
|
87
|
-
/** Enable stemming
|
|
87
|
+
/** Enable stemming (uses English by default) */
|
|
88
88
|
enableStemming?: boolean;
|
|
89
89
|
/** Boost values for different result types and fields */
|
|
90
90
|
boost?: Partial<Record<string, number>>;
|
package/useSearch/useSearch.mjs
CHANGED
|
@@ -4,17 +4,8 @@ import * as React from 'react';
|
|
|
4
4
|
import { create, insertMultiple, search as oramaSearch } from '@orama/orama';
|
|
5
5
|
import { pluginQPS } from '@orama/plugin-qps';
|
|
6
6
|
import { stemmer, language } from '@orama/stemmers/english';
|
|
7
|
-
import { stopwords as englishStopwords } from '@orama/stopwords/english';
|
|
8
7
|
import { resolvePageUrl } from "../resolvePageUrl/index.mjs";
|
|
9
8
|
|
|
10
|
-
// https://github.com/oramasearch/orama/blob/main/packages/stopwords/lib/en.js
|
|
11
|
-
// Removed words that might be meaningful in a software documentation context
|
|
12
|
-
const stopWords = englishStopwords.filter(word => word !== 'about' && word !== 'but' &&
|
|
13
|
-
// start of button
|
|
14
|
-
word !== 'for' &&
|
|
15
|
-
// part of form
|
|
16
|
-
word !== 'between' && word !== 'before' && word !== 'after' && word !== 'above' && word !== 'below' && word !== 'once' && word !== 'then' && word !== 'where' && word !== 'to' && word !== 'from' && word !== 'up' && word !== 'down' && word !== 'in' && word !== 'out' && word !== 'on' && word !== 'off' && word !== 'over' && word !== 'under');
|
|
17
|
-
|
|
18
9
|
/**
|
|
19
10
|
* Type for our search document structure
|
|
20
11
|
*/
|
|
@@ -354,8 +345,7 @@ export function useSearch(options) {
|
|
|
354
345
|
stemming: true,
|
|
355
346
|
language,
|
|
356
347
|
stemmer,
|
|
357
|
-
stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props']
|
|
358
|
-
stopWords
|
|
348
|
+
stemmerSkipProperties: ['type', 'group', 'slug', 'sectionTitle', 'page', 'part', 'export', 'dataAttributes', 'cssVariables', 'props']
|
|
359
349
|
}
|
|
360
350
|
} : undefined,
|
|
361
351
|
plugins: [pluginQPS()]
|