@mui/internal-markdown 1.0.0 → 1.0.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-markdown",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
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",
@@ -13,7 +13,7 @@
13
13
  "repository": {
14
14
  "type": "git",
15
15
  "url": "https://github.com/mui/material-ui.git",
16
- "directory": "packages/docs-utils"
16
+ "directory": "packages/markdown"
17
17
  },
18
18
  "dependencies": {
19
19
  "@babel/runtime": "^7.23.9",
@@ -22,7 +22,7 @@
22
22
  "prismjs": "^1.29.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@types/chai": "^4.3.11",
25
+ "@types/chai": "^4.3.12",
26
26
  "chai": "^4.4.1"
27
27
  },
28
28
  "publishConfig": {
package/parseMarkdown.js CHANGED
@@ -188,6 +188,7 @@ function getContents(markdown) {
188
188
  .replace(headerRegExp, '') // Remove header information
189
189
  .split(/^{{("(?:demo|component)":.*)}}$/gm) // Split markdown into an array, separating demos
190
190
  .flatMap((text) => text.split(/^(<codeblock.*?<\/codeblock>)$/gmsu))
191
+ .flatMap((text) => text.split(/^(<featureList.*?<\/featureList>)$/gmsu))
191
192
  .filter((content) => !emptyRegExp.test(content)); // Remove empty lines
192
193
  return rep;
193
194
  }
@@ -212,23 +213,37 @@ function getDescription(markdown) {
212
213
  }
213
214
 
214
215
  function getCodeblock(content) {
215
- if (content.startsWith('<codeblock')) {
216
- const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
217
- const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
218
- ([, language, tab, code]) => ({ language, tab, code }),
219
- );
220
-
221
- const blocksData = blocks.filter(
222
- (block) => block.tab !== undefined && !emptyRegExp.test(block.code),
223
- );
216
+ if (!content.startsWith('<codeblock')) {
217
+ return undefined;
218
+ }
219
+ const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
220
+ const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
221
+ ([, language, tab, code]) => ({ language, tab, code }),
222
+ );
223
+
224
+ const blocksData = blocks.filter(
225
+ (block) => block.tab !== undefined && !emptyRegExp.test(block.code),
226
+ );
227
+
228
+ return {
229
+ type: 'codeblock',
230
+ data: blocksData,
231
+ storageKey,
232
+ };
233
+ }
224
234
 
225
- return {
226
- type: 'codeblock',
227
- data: blocksData,
228
- storageKey,
229
- };
235
+ function getFeatureList(content) {
236
+ if (!content.startsWith('<featureList')) {
237
+ return undefined;
230
238
  }
231
- return undefined;
239
+ const lines = content
240
+ .split('\n')
241
+ .filter((line) => line.startsWith('- '))
242
+ .map((line) => line.slice(2));
243
+
244
+ return ['<ul class="feature-list">', ...lines.map((line) => `<li>${line}</li>`), '</ul>'].join(
245
+ '',
246
+ );
232
247
  }
233
248
 
234
249
  /**
@@ -395,6 +410,7 @@ function createRender(context) {
395
410
  renderer.code = (code, infostring, escaped) => {
396
411
  // https://github.com/markedjs/marked/blob/30e90e5175700890e6feb1836c57b9404c854466/src/Renderer.js#L15
397
412
  const lang = (infostring || '').match(/\S*/)[0];
413
+ const title = (infostring || '').match(/title="([^"]*)"/)?.[1];
398
414
  const out = prism(code, lang);
399
415
  if (out != null && out !== code) {
400
416
  escaped = true;
@@ -407,7 +423,7 @@ function createRender(context) {
407
423
  return `<pre><code>${escaped ? code : escape(code, true)}</code></pre>\n`;
408
424
  }
409
425
 
410
- return `<div class="MuiCode-root"><pre><code class="language-${escape(lang, true)}">${
426
+ return `<div class="MuiCode-root">${title ? `<div class="MuiCode-title">${title}</div>` : ''}<pre><code class="language-${escape(lang, true)}">${
411
427
  escaped ? code : escape(code, true)
412
428
  }</code></pre>${[
413
429
  '<button data-ga-event-category="code" data-ga-event-action="copy-click" aria-label="Copy the code" class="MuiCode-copy">',
@@ -475,6 +491,7 @@ module.exports = {
475
491
  getContents,
476
492
  getDescription,
477
493
  getCodeblock,
494
+ getFeatureList,
478
495
  getHeaders,
479
496
  getTitle,
480
497
  renderMarkdown,
@@ -7,6 +7,7 @@ const {
7
7
  getContents,
8
8
  getDescription,
9
9
  getCodeblock,
10
+ getFeatureList,
10
11
  getHeaders,
11
12
  getTitle,
12
13
  } = require('./parseMarkdown');
@@ -104,7 +105,7 @@ function prepareMarkdown(config) {
104
105
  contents.push(`
105
106
  ## Unstyled
106
107
 
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
+ 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
109
  This unstyled version of the component is the ideal choice for heavy customization with a smaller bundle size.
109
110
  `);
110
111
  }
@@ -155,13 +156,18 @@ ${headers.hooks
155
156
  return null;
156
157
  }
157
158
  }
158
-
159
159
  const codeblock = getCodeblock(content);
160
160
 
161
161
  if (codeblock) {
162
162
  return codeblock;
163
163
  }
164
164
 
165
+ const featureList = getFeatureList(content);
166
+
167
+ if (featureList) {
168
+ return featureList;
169
+ }
170
+
165
171
  return render(content);
166
172
  });
167
173