@mui/internal-markdown 1.0.18 → 1.0.20
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/loader.js +115 -20
- package/package.json +3 -3
- package/parseMarkdown.js +0 -7
- package/prepareMarkdown.js +6 -0
- package/prepareMarkdown.test.js +14 -14
package/loader.js
CHANGED
|
@@ -148,11 +148,12 @@ module.exports = async function demoLoader() {
|
|
|
148
148
|
* @param {*} moduleFilepath
|
|
149
149
|
* @param {*} variant
|
|
150
150
|
* @param {*} importModuleID
|
|
151
|
+
* @returns {string} The name of the imported module along with a resolved extension if not provided
|
|
151
152
|
* @example detectRelativeImports('ComboBox.js', '', JS', './top100Films') => relativeModules.set('ComboBox.js', new Map([['./top100Films.js', ['JS']]]))
|
|
152
153
|
*/
|
|
153
154
|
function detectRelativeImports(demoName, moduleFilepath, variant, importModuleID) {
|
|
155
|
+
let relativeModuleFilename = importModuleID;
|
|
154
156
|
if (importModuleID.startsWith('.')) {
|
|
155
|
-
let relativeModuleFilename = importModuleID;
|
|
156
157
|
const demoMap = relativeModules.get(demoName);
|
|
157
158
|
// If the moduleID does not end with an extension, or ends with an unsupported extension (e.g. ".styling") we need to resolve it
|
|
158
159
|
// Fastest way to get a file extension, see: https://stackoverflow.com/a/12900504/
|
|
@@ -198,6 +199,27 @@ module.exports = async function demoLoader() {
|
|
|
198
199
|
}
|
|
199
200
|
}
|
|
200
201
|
}
|
|
202
|
+
return relativeModuleFilename;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Inserts the moduleData into the relativeModules object
|
|
207
|
+
* @param string demoName
|
|
208
|
+
* @param {*} moduleData
|
|
209
|
+
* @param string variant
|
|
210
|
+
* @example updateRelativeModules(demoName, {module: 'constants.js', raw: ... }, 'JS') => demos[demoName].relativeModules[variant].push(moduleData)
|
|
211
|
+
*/
|
|
212
|
+
function updateRelativeModules(demoName, moduleData, variant) {
|
|
213
|
+
if (demos[demoName].relativeModules[variant]) {
|
|
214
|
+
// Avoid duplicates
|
|
215
|
+
if (
|
|
216
|
+
!demos[demoName].relativeModules[variant].some((elem) => elem.module === moduleData.module)
|
|
217
|
+
) {
|
|
218
|
+
demos[demoName].relativeModules[variant].push(moduleData);
|
|
219
|
+
}
|
|
220
|
+
} else {
|
|
221
|
+
demos[demoName].relativeModules[variant] = [moduleData];
|
|
222
|
+
}
|
|
201
223
|
}
|
|
202
224
|
|
|
203
225
|
await Promise.all(
|
|
@@ -438,32 +460,105 @@ module.exports = async function demoLoader() {
|
|
|
438
460
|
demos[demoName].relativeModules = {};
|
|
439
461
|
}
|
|
440
462
|
|
|
463
|
+
const addedModulesRelativeToModulePath = new Set();
|
|
441
464
|
await Promise.all(
|
|
442
465
|
Array.from(relativeModules.get(demoName)).map(async ([relativeModuleID, variants]) => {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
} catch {
|
|
449
|
-
throw new Error(
|
|
450
|
-
`Could not find a module for the relative import "${relativeModuleID}" in the demo "${demoName}"`,
|
|
466
|
+
for (const variant of variants) {
|
|
467
|
+
let raw = '';
|
|
468
|
+
const relativeModuleFilePath = path.join(
|
|
469
|
+
path.dirname(moduleFilepath),
|
|
470
|
+
relativeModuleID,
|
|
451
471
|
);
|
|
452
|
-
}
|
|
453
472
|
|
|
454
|
-
|
|
455
|
-
|
|
473
|
+
// the file has already been processed
|
|
474
|
+
if (addedModulesRelativeToModulePath.has(relativeModuleFilePath)) {
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
456
477
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
//
|
|
460
|
-
|
|
461
|
-
|
|
478
|
+
try {
|
|
479
|
+
// We are only iterating trough an array that looks
|
|
480
|
+
// like this: ['JS', 'TS'], so it is safe to await
|
|
481
|
+
// eslint-disable-next-line no-await-in-loop
|
|
482
|
+
raw = await fs.readFile(relativeModuleFilePath, {
|
|
483
|
+
encoding: 'utf8',
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
const importedProcessedModuleIDs = new Set();
|
|
487
|
+
const importedProcessedModulesIDsParents = new Map();
|
|
488
|
+
// Find the relative paths in the relative module
|
|
489
|
+
extractImports(raw).forEach((importModuleID) => {
|
|
490
|
+
// detect relative import
|
|
491
|
+
const importModuleIdWithExtension = detectRelativeImports(
|
|
492
|
+
relativeModuleID,
|
|
493
|
+
relativeModuleFilePath,
|
|
494
|
+
variant,
|
|
495
|
+
importModuleID,
|
|
496
|
+
);
|
|
497
|
+
if (importModuleID.startsWith('.')) {
|
|
498
|
+
importedProcessedModuleIDs.add(importModuleIdWithExtension);
|
|
499
|
+
importedProcessedModulesIDsParents.set(
|
|
500
|
+
importModuleIdWithExtension,
|
|
501
|
+
relativeModuleFilePath,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
updateRelativeModules(demoName, { module: relativeModuleID, raw }, variant);
|
|
507
|
+
addedModulesRelativeToModulePath.add(relativeModuleFilePath);
|
|
508
|
+
|
|
509
|
+
// iterate recursively over the relative imports
|
|
510
|
+
while (importedProcessedModuleIDs.size > 0) {
|
|
511
|
+
for (const entry of importedProcessedModuleIDs) {
|
|
512
|
+
if (entry.startsWith('.')) {
|
|
513
|
+
const entryModuleFilePath = path.join(
|
|
514
|
+
path.dirname(importedProcessedModulesIDsParents.get(entry)),
|
|
515
|
+
entry,
|
|
516
|
+
);
|
|
517
|
+
|
|
518
|
+
// We are only iterating trough an array that looks
|
|
519
|
+
// like this: ['JS', 'TS'], so it is safe to await
|
|
520
|
+
// eslint-disable-next-line no-await-in-loop
|
|
521
|
+
const rawEntry = await fs.readFile(entryModuleFilePath, { encoding: 'utf8' });
|
|
522
|
+
|
|
523
|
+
extractImports(rawEntry).forEach((importModuleID) => {
|
|
524
|
+
// detect relative import
|
|
525
|
+
const importModuleIdWithExtension = detectRelativeImports(
|
|
526
|
+
relativeModuleID,
|
|
527
|
+
entryModuleFilePath,
|
|
528
|
+
variant,
|
|
529
|
+
importModuleID,
|
|
530
|
+
);
|
|
531
|
+
if (importModuleID.startsWith('.')) {
|
|
532
|
+
importedProcessedModuleIDs.add(importModuleIdWithExtension);
|
|
533
|
+
importedProcessedModulesIDsParents.set(
|
|
534
|
+
importModuleIdWithExtension,
|
|
535
|
+
entryModuleFilePath,
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
if (!addedModulesRelativeToModulePath.has(entryModuleFilePath)) {
|
|
541
|
+
const modulePathDirectory = moduleFilepath
|
|
542
|
+
.split('/')
|
|
543
|
+
.slice(0, -1)
|
|
544
|
+
.join('/');
|
|
545
|
+
const moduleData = {
|
|
546
|
+
module: `.${entryModuleFilePath.replace(modulePathDirectory, '')}`,
|
|
547
|
+
raw: rawEntry,
|
|
548
|
+
};
|
|
549
|
+
updateRelativeModules(demoName, moduleData, variant);
|
|
550
|
+
addedModulesRelativeToModulePath.add(entryModuleFilePath);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
importedProcessedModuleIDs.delete(entry);
|
|
554
|
+
}
|
|
462
555
|
}
|
|
463
|
-
}
|
|
464
|
-
|
|
556
|
+
} catch {
|
|
557
|
+
throw new Error(
|
|
558
|
+
`Could not find a module for the relative import "${relativeModuleID}" in the demo "${demoName}"`,
|
|
559
|
+
);
|
|
465
560
|
}
|
|
466
|
-
}
|
|
561
|
+
}
|
|
467
562
|
}),
|
|
468
563
|
);
|
|
469
564
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/internal-markdown",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.20",
|
|
4
4
|
"author": "MUI Team",
|
|
5
5
|
"description": "MUI markdown parser. This is an internal package not meant for general use.",
|
|
6
6
|
"main": "./index.js",
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"directory": "packages/markdown"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@babel/runtime": "^7.
|
|
19
|
+
"@babel/runtime": "^7.26.0",
|
|
20
20
|
"lodash": "^4.17.21",
|
|
21
|
-
"marked": "^14.1.
|
|
21
|
+
"marked": "^14.1.4",
|
|
22
22
|
"prismjs": "^1.29.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
package/parseMarkdown.js
CHANGED
|
@@ -7,15 +7,8 @@ const prism = require('./prism');
|
|
|
7
7
|
*/
|
|
8
8
|
const markedOptions = {
|
|
9
9
|
gfm: true,
|
|
10
|
-
tables: true,
|
|
11
10
|
breaks: false,
|
|
12
11
|
pedantic: false,
|
|
13
|
-
sanitize: false,
|
|
14
|
-
smartLists: true,
|
|
15
|
-
smartypants: false,
|
|
16
|
-
headerPrefix: false,
|
|
17
|
-
headerIds: false,
|
|
18
|
-
mangle: false,
|
|
19
12
|
};
|
|
20
13
|
|
|
21
14
|
const headerRegExp = /---[\r\n]([\s\S]*)[\r\n]---/;
|
package/prepareMarkdown.js
CHANGED
|
@@ -102,6 +102,12 @@ function prepareMarkdown(config) {
|
|
|
102
102
|
);
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
if (description.slice(-1) !== '.' && description.slice(-1) !== '!') {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`docs-infra: The description "${description}" should end with a "." or "!", those are sentences.`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
105
111
|
const contents = getContents(markdown);
|
|
106
112
|
|
|
107
113
|
if (headers.unstyled) {
|
package/prepareMarkdown.test.js
CHANGED
|
@@ -13,7 +13,7 @@ describe('prepareMarkdown', () => {
|
|
|
13
13
|
const markdown = `
|
|
14
14
|
# Support
|
|
15
15
|
|
|
16
|
-
<p class="description">Foo
|
|
16
|
+
<p class="description">Foo.</p>
|
|
17
17
|
|
|
18
18
|
## Community help (free)
|
|
19
19
|
### GitHub <img src="/static/images/logos/github.svg" width="24" height="24" alt="GitHub logo" loading="lazy" />
|
|
@@ -64,7 +64,7 @@ describe('prepareMarkdown', () => {
|
|
|
64
64
|
const markdown = `
|
|
65
65
|
# Theming
|
|
66
66
|
|
|
67
|
-
<p class="description">Foo
|
|
67
|
+
<p class="description">Foo.</p>
|
|
68
68
|
|
|
69
69
|
## API
|
|
70
70
|
### responsiveFontSizes(theme, options) => theme
|
|
@@ -105,7 +105,7 @@ describe('prepareMarkdown', () => {
|
|
|
105
105
|
const markdownEn = `
|
|
106
106
|
# Localization
|
|
107
107
|
|
|
108
|
-
<p class="description">Foo
|
|
108
|
+
<p class="description">Foo.</p>
|
|
109
109
|
|
|
110
110
|
## Locales
|
|
111
111
|
### Example
|
|
@@ -115,7 +115,7 @@ describe('prepareMarkdown', () => {
|
|
|
115
115
|
const markdownPt = `
|
|
116
116
|
# Localização
|
|
117
117
|
|
|
118
|
-
<p class="description">Foo
|
|
118
|
+
<p class="description">Foo.</p>
|
|
119
119
|
|
|
120
120
|
## Idiomas
|
|
121
121
|
### Exemplo
|
|
@@ -125,7 +125,7 @@ describe('prepareMarkdown', () => {
|
|
|
125
125
|
const markdownZh = `
|
|
126
126
|
# 所在位置
|
|
127
127
|
|
|
128
|
-
<p class="description">Foo
|
|
128
|
+
<p class="description">Foo.</p>
|
|
129
129
|
|
|
130
130
|
## 语言环境
|
|
131
131
|
### 例
|
|
@@ -211,7 +211,7 @@ describe('prepareMarkdown', () => {
|
|
|
211
211
|
const markdownEn = `
|
|
212
212
|
# Localization
|
|
213
213
|
|
|
214
|
-
<p class="description">Foo
|
|
214
|
+
<p class="description">Foo.</p>
|
|
215
215
|
|
|
216
216
|
## Locales
|
|
217
217
|
### Example
|
|
@@ -221,7 +221,7 @@ describe('prepareMarkdown', () => {
|
|
|
221
221
|
const markdownPt = `
|
|
222
222
|
# Localização
|
|
223
223
|
|
|
224
|
-
<p class="description">Foo
|
|
224
|
+
<p class="description">Foo.</p>
|
|
225
225
|
|
|
226
226
|
## Idiomas
|
|
227
227
|
### Exemplo
|
|
@@ -292,7 +292,7 @@ describe('prepareMarkdown', () => {
|
|
|
292
292
|
const markdown = `
|
|
293
293
|
# Localization
|
|
294
294
|
|
|
295
|
-
<p class="description">Foo
|
|
295
|
+
<p class="description">Foo.</p>
|
|
296
296
|
|
|
297
297
|
[bar](/bar/)
|
|
298
298
|
[foo](/foo)
|
|
@@ -314,7 +314,7 @@ See https://ahrefs.com/blog/trailing-slash/ for more details.
|
|
|
314
314
|
const markdown = `
|
|
315
315
|
# Localization
|
|
316
316
|
|
|
317
|
-
<p class="description">Foo
|
|
317
|
+
<p class="description">Foo.</p>
|
|
318
318
|
|
|
319
319
|
[bar](/bar/)
|
|
320
320
|
[foo](foo/)
|
|
@@ -334,7 +334,7 @@ See https://ahrefs.com/blog/trailing-slash/ for more details.
|
|
|
334
334
|
const markdown = `
|
|
335
335
|
# Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
|
|
336
336
|
|
|
337
|
-
<p class="description">Foo
|
|
337
|
+
<p class="description">Foo.</p>
|
|
338
338
|
|
|
339
339
|
`;
|
|
340
340
|
|
|
@@ -354,7 +354,7 @@ https://developers.google.com/search/docs/advanced/appearance/title-link
|
|
|
354
354
|
const markdown = `
|
|
355
355
|
# Foo
|
|
356
356
|
|
|
357
|
-
<p class="description">
|
|
357
|
+
<p class="description">Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo.</p>
|
|
358
358
|
|
|
359
359
|
`;
|
|
360
360
|
|
|
@@ -364,7 +364,7 @@ https://developers.google.com/search/docs/advanced/appearance/title-link
|
|
|
364
364
|
translations: [{ filename: 'index.md', markdown, userLanguage: 'en' }],
|
|
365
365
|
});
|
|
366
366
|
}).to
|
|
367
|
-
.throw(`docs-infra: The description "
|
|
367
|
+
.throw(`docs-infra: The description "Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo." is too long (188 characters).
|
|
368
368
|
It needs to have fewer than 170 characters—ideally less than 160. For more details, see:
|
|
369
369
|
https://ahrefs.com/blog/meta-description/#4-be-concise
|
|
370
370
|
`);
|
|
@@ -374,7 +374,7 @@ https://ahrefs.com/blog/meta-description/#4-be-concise
|
|
|
374
374
|
const markdown = `
|
|
375
375
|
# Foo
|
|
376
376
|
|
|
377
|
-
<p class="description">Fo
|
|
377
|
+
<p class="description">Fo.</p>
|
|
378
378
|
|
|
379
379
|
\`\`\`sh
|
|
380
380
|
npm install @mui/material
|
|
@@ -401,7 +401,7 @@ Use "bash" instead.
|
|
|
401
401
|
const markdown = `
|
|
402
402
|
# Localization
|
|
403
403
|
|
|
404
|
-
<p class="description">Foo
|
|
404
|
+
<p class="description">Foo.</p>
|
|
405
405
|
|
|
406
406
|
[foo](/foo/)
|
|
407
407
|
[bar](/bar//#foo)
|