@mui/internal-markdown 1.0.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/CHANGELOG.md +5 -0
- package/LICENSE +21 -0
- package/README.md +11 -0
- package/extractImports.js +8 -0
- package/extractImports.test.js +39 -0
- package/index.d.ts +19 -0
- package/index.js +3 -0
- package/loader.js +415 -0
- package/package.json +35 -0
- package/parseMarkdown.js +481 -0
- package/parseMarkdown.test.js +326 -0
- package/prepareMarkdown.js +259 -0
- package/prepareMarkdown.test.js +417 -0
- package/prism.d.ts +1 -0
- package/prism.js +61 -0
- package/textToHash.js +36 -0
- package/textToHash.test.js +32 -0
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import {
|
|
3
|
+
getContents,
|
|
4
|
+
getDescription,
|
|
5
|
+
getTitle,
|
|
6
|
+
getHeaders,
|
|
7
|
+
getCodeblock,
|
|
8
|
+
renderMarkdown,
|
|
9
|
+
createRender,
|
|
10
|
+
} from './parseMarkdown';
|
|
11
|
+
|
|
12
|
+
describe('parseMarkdown', () => {
|
|
13
|
+
describe('getTitle', () => {
|
|
14
|
+
it('remove backticks', () => {
|
|
15
|
+
expect(
|
|
16
|
+
getTitle(`
|
|
17
|
+
# \`@mui/styled-engine\`
|
|
18
|
+
|
|
19
|
+
<p class="description">Configuring your preferred styling library.</p>
|
|
20
|
+
`),
|
|
21
|
+
).to.equal('@mui/styled-engine');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
describe('getDescription', () => {
|
|
26
|
+
it('trims the description', () => {
|
|
27
|
+
expect(
|
|
28
|
+
getDescription(`
|
|
29
|
+
<p class="description">
|
|
30
|
+
Some description
|
|
31
|
+
</p>
|
|
32
|
+
`),
|
|
33
|
+
).to.equal('Some description');
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('remove backticks', () => {
|
|
37
|
+
expect(
|
|
38
|
+
getDescription(`
|
|
39
|
+
<p class="description">
|
|
40
|
+
Some \`description\`
|
|
41
|
+
</p>
|
|
42
|
+
`),
|
|
43
|
+
).to.equal('Some description');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should not be greedy', () => {
|
|
47
|
+
expect(
|
|
48
|
+
getDescription(`
|
|
49
|
+
<p class="description">
|
|
50
|
+
Some description
|
|
51
|
+
</p>
|
|
52
|
+
## Foo
|
|
53
|
+
<p>bar</p>
|
|
54
|
+
`),
|
|
55
|
+
).to.equal('Some description');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('getHeaders', () => {
|
|
60
|
+
it('should return a correct result', () => {
|
|
61
|
+
expect(
|
|
62
|
+
getHeaders(`
|
|
63
|
+
---
|
|
64
|
+
title: React Alert component
|
|
65
|
+
components: Alert, AlertTitle
|
|
66
|
+
hooks: useAlert
|
|
67
|
+
githubLabel: 'component: alert'
|
|
68
|
+
packageName: '@mui/lab'
|
|
69
|
+
waiAria: https://www.w3.org/TR/wai-aria-practices/#alert
|
|
70
|
+
authors: ['foo', 'bar']
|
|
71
|
+
---
|
|
72
|
+
`),
|
|
73
|
+
).to.deep.equal({
|
|
74
|
+
components: ['Alert', 'AlertTitle'],
|
|
75
|
+
hooks: ['useAlert'],
|
|
76
|
+
githubLabel: 'component: alert',
|
|
77
|
+
packageName: '@mui/lab',
|
|
78
|
+
title: 'React Alert component',
|
|
79
|
+
waiAria: 'https://www.w3.org/TR/wai-aria-practices/#alert',
|
|
80
|
+
authors: ['foo', 'bar'],
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should work with authors broken in two lines', () => {
|
|
85
|
+
expect(
|
|
86
|
+
getHeaders(`
|
|
87
|
+
---
|
|
88
|
+
title: React Alert component
|
|
89
|
+
components: Alert, AlertTitle
|
|
90
|
+
githubLabel: 'component: alert'
|
|
91
|
+
packageName: '@mui/lab'
|
|
92
|
+
waiAria: https://www.w3.org/TR/wai-aria-practices/#alert
|
|
93
|
+
authors:
|
|
94
|
+
['foo', 'bar']
|
|
95
|
+
---
|
|
96
|
+
`),
|
|
97
|
+
).to.deep.equal({
|
|
98
|
+
components: ['Alert', 'AlertTitle'],
|
|
99
|
+
hooks: [],
|
|
100
|
+
githubLabel: 'component: alert',
|
|
101
|
+
packageName: '@mui/lab',
|
|
102
|
+
title: 'React Alert component',
|
|
103
|
+
waiAria: 'https://www.w3.org/TR/wai-aria-practices/#alert',
|
|
104
|
+
authors: ['foo', 'bar'],
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should work with one author per line', () => {
|
|
109
|
+
expect(
|
|
110
|
+
getHeaders(`
|
|
111
|
+
---
|
|
112
|
+
title: React Alert component
|
|
113
|
+
components: Alert, AlertTitle
|
|
114
|
+
githubLabel: 'component: alert'
|
|
115
|
+
packageName: '@mui/lab'
|
|
116
|
+
waiAria: https://www.w3.org/TR/wai-aria-practices/#alert
|
|
117
|
+
authors:
|
|
118
|
+
[
|
|
119
|
+
'foo',
|
|
120
|
+
'bar',
|
|
121
|
+
]
|
|
122
|
+
---
|
|
123
|
+
`),
|
|
124
|
+
).to.deep.equal({
|
|
125
|
+
components: ['Alert', 'AlertTitle'],
|
|
126
|
+
hooks: [],
|
|
127
|
+
githubLabel: 'component: alert',
|
|
128
|
+
packageName: '@mui/lab',
|
|
129
|
+
title: 'React Alert component',
|
|
130
|
+
waiAria: 'https://www.w3.org/TR/wai-aria-practices/#alert',
|
|
131
|
+
authors: ['foo', 'bar'],
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('getContents', () => {
|
|
137
|
+
describe('Split markdown into an array, separating demos', () => {
|
|
138
|
+
it('returns a single entry without a demo', () => {
|
|
139
|
+
expect(getContents('# SomeGuide\nwhich has no demo')).to.deep.equal([
|
|
140
|
+
'# SomeGuide\nwhich has no demo',
|
|
141
|
+
]);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('uses a `{{"demo"` marker to split', () => {
|
|
145
|
+
expect(
|
|
146
|
+
getContents('# SomeGuide\n{{"demo": "GuideDemo.js" }}\n## NextHeading'),
|
|
147
|
+
).to.deep.equal(['# SomeGuide\n', '"demo": "GuideDemo.js" ', '\n## NextHeading']);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('ignores possible code', () => {
|
|
151
|
+
expect(getContents('# SomeGuide\n```jsx\n<Button props={{\nfoo: 1\n}}')).to.deep.equal([
|
|
152
|
+
'# SomeGuide\n```jsx\n<Button props={{\nfoo: 1\n}}',
|
|
153
|
+
]);
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('Split markdown into an array, separating codeblocks', () => {
|
|
158
|
+
it('uses a `<codeblock>` tag to split', () => {
|
|
159
|
+
expect(
|
|
160
|
+
getContents(
|
|
161
|
+
[
|
|
162
|
+
'## Tabs',
|
|
163
|
+
'',
|
|
164
|
+
'<codeblock storageKey="package-manager">',
|
|
165
|
+
'',
|
|
166
|
+
'```bash npm',
|
|
167
|
+
'npm install @mui/material @emotion/react @emotion/styled',
|
|
168
|
+
'```',
|
|
169
|
+
'',
|
|
170
|
+
'```bash yarn',
|
|
171
|
+
'yarn add @mui/material @emotion/react @emotion/styled',
|
|
172
|
+
'```',
|
|
173
|
+
'',
|
|
174
|
+
'</codeblock>',
|
|
175
|
+
].join('\n'),
|
|
176
|
+
),
|
|
177
|
+
).to.deep.equal([
|
|
178
|
+
'## Tabs\n\n',
|
|
179
|
+
[
|
|
180
|
+
'<codeblock storageKey="package-manager">',
|
|
181
|
+
'',
|
|
182
|
+
'```bash npm',
|
|
183
|
+
'npm install @mui/material @emotion/react @emotion/styled',
|
|
184
|
+
'```',
|
|
185
|
+
'',
|
|
186
|
+
'```bash yarn',
|
|
187
|
+
'yarn add @mui/material @emotion/react @emotion/styled',
|
|
188
|
+
'```',
|
|
189
|
+
'',
|
|
190
|
+
'</codeblock>',
|
|
191
|
+
].join('\n'),
|
|
192
|
+
]);
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe('getCodeblock', () => {
|
|
198
|
+
it('should return undefined if no codeblock found', () => {
|
|
199
|
+
const codeblock = getCodeblock('## Tabs');
|
|
200
|
+
expect(codeblock).to.equal(undefined);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it('should return the codeblock', () => {
|
|
204
|
+
const codeblock = getCodeblock(
|
|
205
|
+
[
|
|
206
|
+
'<codeblock storageKey="package-manager">',
|
|
207
|
+
'',
|
|
208
|
+
'```bash npm',
|
|
209
|
+
'npm install @mui/material @emotion/react @emotion/styled',
|
|
210
|
+
'# `@emotion/react` and `@emotion/styled` are peer dependencies',
|
|
211
|
+
'```',
|
|
212
|
+
'',
|
|
213
|
+
'```sh yarn',
|
|
214
|
+
'yarn add @mui/material @emotion/react @emotion/styled',
|
|
215
|
+
'# `@emotion/react` and `@emotion/styled` are peer dependencies',
|
|
216
|
+
'```',
|
|
217
|
+
'',
|
|
218
|
+
'</codeblock>',
|
|
219
|
+
].join('\n'),
|
|
220
|
+
);
|
|
221
|
+
expect(codeblock).to.deep.equal({
|
|
222
|
+
type: 'codeblock',
|
|
223
|
+
storageKey: 'package-manager',
|
|
224
|
+
data: [
|
|
225
|
+
{
|
|
226
|
+
language: 'bash',
|
|
227
|
+
tab: 'npm',
|
|
228
|
+
code: [
|
|
229
|
+
'npm install @mui/material @emotion/react @emotion/styled',
|
|
230
|
+
'# `@emotion/react` and `@emotion/styled` are peer dependencies',
|
|
231
|
+
].join('\n'),
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
language: 'sh',
|
|
235
|
+
tab: 'yarn',
|
|
236
|
+
code: [
|
|
237
|
+
'yarn add @mui/material @emotion/react @emotion/styled',
|
|
238
|
+
'# `@emotion/react` and `@emotion/styled` are peer dependencies',
|
|
239
|
+
].join('\n'),
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('renderMarkdown', () => {
|
|
247
|
+
it('should render markdown lists correctly', () => {
|
|
248
|
+
expect(
|
|
249
|
+
renderMarkdown(
|
|
250
|
+
[
|
|
251
|
+
'The track presentation:',
|
|
252
|
+
'- `normal` the track will render a bar representing the slider value.',
|
|
253
|
+
'- `inverted` the track will render a bar representing the remaining slider value.',
|
|
254
|
+
'- `false` the track will render without a bar.',
|
|
255
|
+
].join('\n'),
|
|
256
|
+
),
|
|
257
|
+
).to.equal(
|
|
258
|
+
[
|
|
259
|
+
'<p>The track presentation:</p>',
|
|
260
|
+
'<ul>',
|
|
261
|
+
'<li><code>normal</code> the track will render a bar representing the slider value.</li>',
|
|
262
|
+
'<li><code>inverted</code> the track will render a bar representing the remaining slider value.</li>',
|
|
263
|
+
'<li><code>false</code> the track will render without a bar.</li>',
|
|
264
|
+
'</ul>',
|
|
265
|
+
'',
|
|
266
|
+
].join('\n'),
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('should render inline descriptions correctly', () => {
|
|
271
|
+
expect(
|
|
272
|
+
renderMarkdown(
|
|
273
|
+
'Allows to control whether the dropdown is open. This is a controlled counterpart of `defaultOpen`.',
|
|
274
|
+
),
|
|
275
|
+
).to.equal(
|
|
276
|
+
'Allows to control whether the dropdown is open. This is a controlled counterpart of <code>defaultOpen</code>.',
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe('createRender', () => {
|
|
282
|
+
it('should collect headers correctly', () => {
|
|
283
|
+
const context = { toc: [], headingHashes: {} };
|
|
284
|
+
const render = createRender(context);
|
|
285
|
+
|
|
286
|
+
expect(
|
|
287
|
+
render(
|
|
288
|
+
[
|
|
289
|
+
'# Accordion',
|
|
290
|
+
'## Basic features 🧪',
|
|
291
|
+
'## Using `slots` and `slotProps`',
|
|
292
|
+
'### Specific example',
|
|
293
|
+
].join('\n'),
|
|
294
|
+
),
|
|
295
|
+
).to.equal(
|
|
296
|
+
[
|
|
297
|
+
`<h1>Accordion</h1>`,
|
|
298
|
+
`<h2 id="basic-features">Basic features 🧪<a aria-labelledby="basic-features" class="anchor-link" href="#basic-features" tabindex="-1"><svg><use xlink:href="#anchor-link-icon" /></svg></a><button title="Post a comment" class="comment-link" data-feedback-hash="basic-features"><svg><use xlink:href="#comment-link-icon" /></svg></button></h2>`,
|
|
299
|
+
`<h2 id="using-slots-and-slotprops">Using <code>slots</code> and <code>slotProps</code><a aria-labelledby="using-slots-and-slotprops" class="anchor-link" href="#using-slots-and-slotprops" tabindex="-1"><svg><use xlink:href="#anchor-link-icon" /></svg></a><button title="Post a comment" class="comment-link" data-feedback-hash="using-slots-and-slotprops"><svg><use xlink:href="#comment-link-icon" /></svg></button></h2>`,
|
|
300
|
+
`<h3 id="specific-example">Specific example<a aria-labelledby="specific-example" class="anchor-link" href="#specific-example" tabindex="-1"><svg><use xlink:href="#anchor-link-icon" /></svg></a><button title="Post a comment" class="comment-link" data-feedback-hash="specific-example"><svg><use xlink:href="#comment-link-icon" /></svg></button></h3>`,
|
|
301
|
+
].join(''),
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
expect(context.toc).to.deep.equal([
|
|
305
|
+
{
|
|
306
|
+
children: [],
|
|
307
|
+
hash: 'basic-features',
|
|
308
|
+
level: 2,
|
|
309
|
+
text: 'Basic features 🧪',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
children: [
|
|
313
|
+
{
|
|
314
|
+
hash: 'specific-example',
|
|
315
|
+
level: 3,
|
|
316
|
+
text: 'Specific example',
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
hash: 'using-slots-and-slotprops',
|
|
320
|
+
level: 2,
|
|
321
|
+
text: 'Using slots and slotProps',
|
|
322
|
+
},
|
|
323
|
+
]);
|
|
324
|
+
});
|
|
325
|
+
});
|
|
326
|
+
});
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
/* eslint-disable no-irregular-whitespace */
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const kebabCase = require('lodash/kebabCase');
|
|
5
|
+
const {
|
|
6
|
+
createRender,
|
|
7
|
+
getContents,
|
|
8
|
+
getDescription,
|
|
9
|
+
getCodeblock,
|
|
10
|
+
getHeaders,
|
|
11
|
+
getTitle,
|
|
12
|
+
} = require('./parseMarkdown');
|
|
13
|
+
|
|
14
|
+
const BaseUIReexportedComponents = ['ClickAwayListener', 'NoSsr', 'Portal', 'TextareaAutosize'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} productId
|
|
18
|
+
* @example 'material'
|
|
19
|
+
* @param {string} componentPkg
|
|
20
|
+
* @example 'mui-base'
|
|
21
|
+
* @param {string} component
|
|
22
|
+
* @example 'Button'
|
|
23
|
+
* @returns {string}
|
|
24
|
+
*/
|
|
25
|
+
function resolveComponentApiUrl(productId, componentPkg, component) {
|
|
26
|
+
if (!productId) {
|
|
27
|
+
return `/api/${kebabCase(component)}/`;
|
|
28
|
+
}
|
|
29
|
+
if (productId === 'x-date-pickers') {
|
|
30
|
+
return `/x/api/date-pickers/${kebabCase(component)}/`;
|
|
31
|
+
}
|
|
32
|
+
if (productId === 'x-charts') {
|
|
33
|
+
return `/x/api/charts/${kebabCase(component)}/`;
|
|
34
|
+
}
|
|
35
|
+
if (productId === 'x-tree-view') {
|
|
36
|
+
return `/x/api/tree-view/${kebabCase(component)}/`;
|
|
37
|
+
}
|
|
38
|
+
if (componentPkg === 'mui-base' || BaseUIReexportedComponents.indexOf(component) >= 0) {
|
|
39
|
+
return `/base-ui/react-${kebabCase(component)}/components-api/#${kebabCase(component)}`;
|
|
40
|
+
}
|
|
41
|
+
return `/${productId}/api/${kebabCase(component)}/`;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {object} config
|
|
46
|
+
* @param {Array<{ markdown: string, filename: string, userLanguage: string }>} config.translations - Mapping of locale to its markdown
|
|
47
|
+
* @param {string} config.fileRelativeContext - posix filename relative to repository root directory
|
|
48
|
+
* @param {object} config.options - provided to the webpack loader
|
|
49
|
+
*/
|
|
50
|
+
function prepareMarkdown(config) {
|
|
51
|
+
const { fileRelativeContext, translations, componentPackageMapping = {}, options } = config;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @type {Record<string, { rendered: Array<string | { component: string } | { demo:string }> }>}
|
|
55
|
+
*/
|
|
56
|
+
const docs = {};
|
|
57
|
+
const headingHashes = {};
|
|
58
|
+
|
|
59
|
+
translations
|
|
60
|
+
// Process the English markdown before the other locales.
|
|
61
|
+
// English ToC anchor links are used in all languages
|
|
62
|
+
.sort((a) => (a.userLanguage === 'en' ? -1 : 1))
|
|
63
|
+
.forEach((translation) => {
|
|
64
|
+
const { filename, markdown, userLanguage } = translation;
|
|
65
|
+
const headers = getHeaders(markdown);
|
|
66
|
+
const location = headers.filename || `/${fileRelativeContext}/${filename}`;
|
|
67
|
+
const markdownH1 = getTitle(markdown);
|
|
68
|
+
const title = headers.title || markdownH1;
|
|
69
|
+
const description = headers.description || getDescription(markdown);
|
|
70
|
+
|
|
71
|
+
if (title == null || title === '') {
|
|
72
|
+
throw new Error(`docs-infra: Missing title in the page: ${location}\n`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (title.length > 70) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
[
|
|
78
|
+
`docs-infra: The title "${title}" is too long (${title.length} characters).`,
|
|
79
|
+
'It needs to have fewer than 70 characters—ideally less than 60. For more details, see:',
|
|
80
|
+
'https://developers.google.com/search/docs/advanced/appearance/title-link',
|
|
81
|
+
'',
|
|
82
|
+
].join('\n'),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (description == null || description === '') {
|
|
87
|
+
throw new Error(`docs-infra: Missing description in the page: ${location}\n`);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (description.length > 170) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
[
|
|
93
|
+
`docs-infra: The description "${description}" is too long (${description.length} characters).`,
|
|
94
|
+
'It needs to have fewer than 170 characters—ideally less than 160. For more details, see:',
|
|
95
|
+
'https://ahrefs.com/blog/meta-description/#4-be-concise',
|
|
96
|
+
'',
|
|
97
|
+
].join('\n'),
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const contents = getContents(markdown);
|
|
102
|
+
|
|
103
|
+
if (headers.unstyled) {
|
|
104
|
+
contents.push(`
|
|
105
|
+
## Unstyled
|
|
106
|
+
|
|
107
|
+
Use the [Base UI ${markdownH1}](${headers.unstyled}) for complete ownership of the component's design, with no Material UI or Joy UI styles to override.
|
|
108
|
+
This unstyled version of the component is the ideal choice for heavy customization with a smaller bundle size.
|
|
109
|
+
`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (headers.components.length > 0) {
|
|
113
|
+
contents.push(`
|
|
114
|
+
## API
|
|
115
|
+
|
|
116
|
+
See the documentation below for a complete reference to all of the props and classes available to the components mentioned here.
|
|
117
|
+
|
|
118
|
+
${headers.components
|
|
119
|
+
.map((component) => {
|
|
120
|
+
const componentPkgMap = componentPackageMapping[headers.productId];
|
|
121
|
+
const componentPkg = componentPkgMap ? componentPkgMap[component] : null;
|
|
122
|
+
return `- [\`<${component} />\`](${resolveComponentApiUrl(
|
|
123
|
+
headers.productId,
|
|
124
|
+
componentPkg,
|
|
125
|
+
component,
|
|
126
|
+
)})`;
|
|
127
|
+
})
|
|
128
|
+
.join('\n')}
|
|
129
|
+
${headers.hooks
|
|
130
|
+
.map((hook) => {
|
|
131
|
+
const componentPkgMap = componentPackageMapping[headers.productId];
|
|
132
|
+
const componentPkg = componentPkgMap ? componentPkgMap[hook] : null;
|
|
133
|
+
return `- [\`${hook}\`](${resolveComponentApiUrl(headers.productId, componentPkg, hook)})`;
|
|
134
|
+
})
|
|
135
|
+
.join('\n')}
|
|
136
|
+
`);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const toc = [];
|
|
140
|
+
const render = createRender({
|
|
141
|
+
headingHashes,
|
|
142
|
+
toc,
|
|
143
|
+
userLanguage,
|
|
144
|
+
location,
|
|
145
|
+
options,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const rendered = contents.map((content) => {
|
|
149
|
+
if (/^"(demo|component)": "(.*)"/.test(content)) {
|
|
150
|
+
try {
|
|
151
|
+
return JSON.parse(`{${content}}`);
|
|
152
|
+
} catch (err) {
|
|
153
|
+
console.error('JSON.parse fails with: ', `{${content}}`);
|
|
154
|
+
console.error(err);
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const codeblock = getCodeblock(content);
|
|
160
|
+
|
|
161
|
+
if (codeblock) {
|
|
162
|
+
return codeblock;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return render(content);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
// fragment link symbol
|
|
169
|
+
rendered.unshift(
|
|
170
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
171
|
+
<symbol id="comment-link-icon" viewBox="0 0 24 24">
|
|
172
|
+
<path d="M22.8481 4C22.8481 2.9 21.9481 2 20.8481 2H4.84814C3.74814 2 2.84814 2.9 2.84814 4V16C2.84814 17.1 3.74814 18 4.84814 18H18.8481L22.8481 22V4ZM16.8481 11H13.8481V14C13.8481 14.55 13.3981 15 12.8481 15C12.2981 15 11.8481 14.55 11.8481 14V11H8.84814C8.29814 11 7.84814 10.55 7.84814 10C7.84814 9.45 8.29814 9 8.84814 9H11.8481V6C11.8481 5.45 12.2981 5 12.8481 5C13.3981 5 13.8481 5.45 13.8481 6V9H16.8481C17.3981 9 17.8481 9.45 17.8481 10C17.8481 10.55 17.3981 11 16.8481 11Z" />
|
|
173
|
+
</symbol>
|
|
174
|
+
</svg>`,
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
rendered.unshift(
|
|
178
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
179
|
+
<symbol id="anchor-link-icon" viewBox="0 0 12 6">
|
|
180
|
+
<path d="M8.9176 0.083252H7.1676C6.84677 0.083252 6.58427 0.345752 6.58427 0.666585C6.58427 0.987419 6.84677 1.24992 7.1676 1.24992H8.9176C9.8801 1.24992 10.6676 2.03742 10.6676 2.99992C10.6676 3.96242 9.8801 4.74992 8.9176 4.74992H7.1676C6.84677 4.74992 6.58427 5.01242 6.58427 5.33325C6.58427 5.65409 6.84677 5.91659 7.1676 5.91659H8.9176C10.5276 5.91659 11.8343 4.60992 11.8343 2.99992C11.8343 1.38992 10.5276 0.083252 8.9176 0.083252ZM3.6676 2.99992C3.6676 3.32075 3.9301 3.58325 4.25094 3.58325H7.75094C8.07177 3.58325 8.33427 3.32075 8.33427 2.99992C8.33427 2.67909 8.07177 2.41659 7.75094 2.41659H4.25094C3.9301 2.41659 3.6676 2.67909 3.6676 2.99992ZM4.83427 4.74992H3.08427C2.12177 4.74992 1.33427 3.96242 1.33427 2.99992C1.33427 2.03742 2.12177 1.24992 3.08427 1.24992H4.83427C5.1551 1.24992 5.4176 0.987419 5.4176 0.666585C5.4176 0.345752 5.1551 0.083252 4.83427 0.083252H3.08427C1.47427 0.083252 0.167603 1.38992 0.167603 2.99992C0.167603 4.60992 1.47427 5.91659 3.08427 5.91659H4.83427C5.1551 5.91659 5.4176 5.65409 5.4176 5.33325C5.4176 5.01242 5.1551 4.74992 4.83427 4.74992Z" />
|
|
181
|
+
</symbol>
|
|
182
|
+
</svg>`,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
rendered.unshift(
|
|
186
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
187
|
+
<symbol id="copy-icon" viewBox="0 0 24 24">
|
|
188
|
+
<path d="M15 20H5V7c0-.55-.45-1-1-1s-1 .45-1 1v13c0 1.1.9 2 2 2h10c.55 0 1-.45 1-1s-.45-1-1-1zm5-4V4c0-1.1-.9-2-2-2H9c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h9c1.1 0 2-.9 2-2zm-2 0H9V4h9v12z" />
|
|
189
|
+
+</symbol>
|
|
190
|
+
</svg>`,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
rendered.unshift(`
|
|
194
|
+
<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
195
|
+
<symbol id="copied-icon" viewBox="0 0 24 24">
|
|
196
|
+
<path d="M20 2H8c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm-8.24 11.28L9.69 11.2c-.38-.39-.38-1.01 0-1.4.39-.39 1.02-.39 1.41 0l1.36 1.37 4.42-4.46c.39-.39 1.02-.39 1.41 0 .38.39.38 1.01 0 1.4l-5.13 5.17c-.37.4-1.01.4-1.4 0zM3 6c-.55 0-1 .45-1 1v13c0 1.1.9 2 2 2h13c.55 0 1-.45 1-1s-.45-1-1-1H5c-.55 0-1-.45-1-1V7c0-.55-.45-1-1-1z" />
|
|
197
|
+
</symbol>
|
|
198
|
+
</svg>`);
|
|
199
|
+
|
|
200
|
+
// icons for callout (info, success, warning, error)
|
|
201
|
+
|
|
202
|
+
rendered.unshift(
|
|
203
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
204
|
+
<symbol id="info-icon" viewBox="0 0 20 20">
|
|
205
|
+
<path d="M9.996 14c.21 0 .39-.072.535-.216a.72.72 0 0 0 .219-.534v-3.5a.728.728 0 0 0-.214-.534.72.72 0 0 0-.532-.216.734.734 0 0 0-.535.216.72.72 0 0 0-.219.534v3.5c0 .213.071.39.214.534a.72.72 0 0 0 .532.216Zm0-6.5c.21 0 .39-.071.535-.214a.714.714 0 0 0 .219-.532.736.736 0 0 0-.214-.535.714.714 0 0 0-.532-.219.736.736 0 0 0-.535.214.714.714 0 0 0-.219.532c0 .21.071.39.214.535.143.146.32.219.532.219Zm.01 10.5a7.81 7.81 0 0 1-3.11-.625 8.065 8.065 0 0 1-2.552-1.719 8.066 8.066 0 0 1-1.719-2.551A7.818 7.818 0 0 1 2 9.99c0-1.104.208-2.14.625-3.105a8.066 8.066 0 0 1 4.27-4.26A7.818 7.818 0 0 1 10.009 2a7.75 7.75 0 0 1 3.106.625 8.083 8.083 0 0 1 4.26 4.265A7.77 7.77 0 0 1 18 9.994a7.81 7.81 0 0 1-.625 3.11 8.066 8.066 0 0 1-1.719 2.552 8.083 8.083 0 0 1-2.546 1.719 7.77 7.77 0 0 1-3.104.625Z"/>
|
|
206
|
+
</symbol>
|
|
207
|
+
</svg>`,
|
|
208
|
+
);
|
|
209
|
+
rendered.unshift(
|
|
210
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
211
|
+
<symbol id="success-icon" viewBox="0 0 20 20">
|
|
212
|
+
<path d="m8.938 10.875-1.25-1.23a.718.718 0 0 0-.521-.228.718.718 0 0 0-.521.229.73.73 0 0 0 0 1.062l1.77 1.771c.153.153.327.23.521.23a.718.718 0 0 0 .521-.23l3.896-3.896a.73.73 0 0 0 0-1.062.718.718 0 0 0-.52-.23.718.718 0 0 0-.521.23l-3.376 3.354ZM10 18a7.796 7.796 0 0 1-3.104-.625 8.065 8.065 0 0 1-2.552-1.719 8.064 8.064 0 0 1-1.719-2.552A7.797 7.797 0 0 1 2 10c0-1.111.208-2.15.625-3.115a8.064 8.064 0 0 1 4.27-4.26A7.797 7.797 0 0 1 10 2c1.111 0 2.15.208 3.115.625a8.096 8.096 0 0 1 4.26 4.26C17.792 7.851 18 8.89 18 10a7.797 7.797 0 0 1-.625 3.104 8.066 8.066 0 0 1-4.26 4.271A7.774 7.774 0 0 1 10 18Z"/>
|
|
213
|
+
</symbol>
|
|
214
|
+
</svg>`,
|
|
215
|
+
);
|
|
216
|
+
rendered.unshift(
|
|
217
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
218
|
+
<symbol id="warning-icon" viewBox="0 0 20 20">
|
|
219
|
+
<path d="M2.33 17a.735.735 0 0 1-.665-.375.631.631 0 0 1-.094-.375.898.898 0 0 1 .115-.396L9.353 3.062a.621.621 0 0 1 .281-.27.85.85 0 0 1 .729 0 .622.622 0 0 1 .281.27l7.667 12.792c.07.125.108.257.114.396a.63.63 0 0 1-.093.375.842.842 0 0 1-.271.27.728.728 0 0 1-.394.105H2.33Zm7.664-2.5c.211 0 .39-.072.536-.214a.714.714 0 0 0 .218-.532.736.736 0 0 0-.214-.535.714.714 0 0 0-.531-.22.736.736 0 0 0-.536.215.714.714 0 0 0-.219.531c0 .212.072.39.215.536.143.146.32.219.531.219Zm0-2.5c.211 0 .39-.072.536-.216a.72.72 0 0 0 .218-.534v-2.5a.728.728 0 0 0-.214-.534.72.72 0 0 0-.531-.216.734.734 0 0 0-.536.216.72.72 0 0 0-.219.534v2.5c0 .212.072.39.215.534a.72.72 0 0 0 .531.216Z"/>
|
|
220
|
+
</symbol>
|
|
221
|
+
</svg>`,
|
|
222
|
+
);
|
|
223
|
+
rendered.unshift(
|
|
224
|
+
`<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
|
|
225
|
+
<symbol id="error-icon" viewBox="0 0 20 20">
|
|
226
|
+
<path fill-rule="evenodd" d="M2 7.4v5.2a2 2 0 0 0 .586 1.414l3.4 3.4A2 2 0 0 0 7.4 18h5.2a2 2 0 0 0 1.414-.586l3.4-3.4A2 2 0 0 0 18 12.6V7.4a2 2 0 0 0-.586-1.414l-3.4-3.4A2 2 0 0 0 12.6 2H7.4a2 2 0 0 0-1.414.586l-3.4 3.4A2 2 0 0 0 2 7.4Zm11.03-.43a.75.75 0 0 1 0 1.06L11.06 10l1.97 1.97a.75.75 0 1 1-1.06 1.06L10 11.06l-1.97 1.97a.75.75 0 0 1-1.06-1.06L8.94 10 6.97 8.03a.75.75 0 0 1 1.06-1.06L10 8.94l1.97-1.97a.75.75 0 0 1 1.06 0Z" clip-rule="evenodd"/>
|
|
227
|
+
</symbol>
|
|
228
|
+
</svg>`,
|
|
229
|
+
);
|
|
230
|
+
docs[userLanguage] = {
|
|
231
|
+
description,
|
|
232
|
+
location,
|
|
233
|
+
rendered,
|
|
234
|
+
toc,
|
|
235
|
+
title,
|
|
236
|
+
headers,
|
|
237
|
+
};
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
if (docs.en.headers.card === 'true') {
|
|
241
|
+
const slug = docs.en.location.replace(/(.*)\/(.*)\.md/, '$2');
|
|
242
|
+
const exists = fs.existsSync(
|
|
243
|
+
path.resolve(config.options.workspaceRoot, `docs/public/static/blog/${slug}/card.png`),
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
if (!exists) {
|
|
247
|
+
throw new Error(
|
|
248
|
+
[
|
|
249
|
+
`MUI: the card image for the blog post "${slug}" is missing.`,
|
|
250
|
+
`Add a docs/public/static/blog/${slug}/card.png file and then restart Next.js or else remove card: true from the headers.`,
|
|
251
|
+
].join('\n'),
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return { docs };
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
module.exports = prepareMarkdown;
|