Skip to content

Commit

Permalink
[docs-infra] Add a feature list "component" (#41484)
Browse files Browse the repository at this point in the history
Co-authored-by: alexandre <[email protected]>
  • Loading branch information
danilo-leal and alexfauquette authored Mar 15, 2024
1 parent 4b591ff commit 7d3b5a5
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 16 deletions.
1 change: 1 addition & 0 deletions docs/data/docs-infra/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const pages: readonly MuiPage[] = [
children: [
{ pathname: '/experiments/docs/callouts' },
{ pathname: '/experiments/docs/codeblock' },
{ pathname: '/experiments/docs/custom-components' },
{ pathname: '/experiments/docs/demos' },
{ pathname: '/experiments/docs/data-grid-premium', title: 'API DataGridPremium' },
],
Expand Down
7 changes: 7 additions & 0 deletions docs/pages/experiments/docs/custom-components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import * as React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';
import * as pageProps from './custom-components.md?muiMarkdown';

export default function Page() {
return <MarkdownDocs {...pageProps} />;
}
19 changes: 19 additions & 0 deletions docs/pages/experiments/docs/custom-components.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Custom components

<p class="description">They're either custom markdown components or passed through directly via "components".</p>

## Header chips

{{"component": "modules/components/ComponentLinkHeader.js"}}

## Feature list

Available through the custom `<featureList>` tag.

<featureList>
- Manages modal stacking when one-at-a-time just isn't enough.
- Creates a backdrop, for disabling interaction below the modal.est
- It disables scrolling of the page content while open.
- It properly manages focus; moving to the modal content, and keeping it there until the modal is closed.
- Adds the appropriate ARIA roles automatically.
</featureList>
22 changes: 22 additions & 0 deletions docs/src/modules/components/MarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,21 @@ const Root = styled('div')(
marginBottom: theme.spacing(1),
},
},
'& .feature-list': {
padding: 0,
listStyle: 'none',
'& li': {
marginBottom: 6,
display: 'flex',
alignItems: 'center',
gap: 12,
'::before': {
content: `url('/static/branding/pricing/yes-light.svg')`,
width: '18px',
height: '18px',
},
},
},
'& .MuiCode-title': {
padding: theme.spacing(1.5),
display: 'flex',
Expand Down Expand Up @@ -777,6 +792,13 @@ const Root = styled('div')(
backgroundColor: `var(--muidocs-palette-primaryDark-800, ${darkTheme.palette.primaryDark[800]})`,
},
},
'& .feature-list': {
'& li': {
'::before': {
content: `url('/static/branding/pricing/yes-dark.svg')`,
},
},
},
},
}),
);
Expand Down
46 changes: 31 additions & 15 deletions packages/markdown/parseMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function getContents(markdown) {
.replace(headerRegExp, '') // Remove header information
.split(/^{{("(?:demo|component)":.*)}}$/gm) // Split markdown into an array, separating demos
.flatMap((text) => text.split(/^(<codeblock.*?<\/codeblock>)$/gmsu))
.flatMap((text) => text.split(/^(<featureList.*?<\/featureList>)$/gmsu))
.filter((content) => !emptyRegExp.test(content)); // Remove empty lines
return rep;
}
Expand All @@ -212,23 +213,37 @@ function getDescription(markdown) {
}

function getCodeblock(content) {
if (content.startsWith('<codeblock')) {
const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
([, language, tab, code]) => ({ language, tab, code }),
);

const blocksData = blocks.filter(
(block) => block.tab !== undefined && !emptyRegExp.test(block.code),
);
if (!content.startsWith('<codeblock')) {
return undefined;
}
const storageKey = content.match(/^<codeblock [^>]*storageKey=["|'](\S*)["|'].*>/m)?.[1];
const blocks = [...content.matchAll(/^```(\S*) (\S*)\n(.*?)\n```/gmsu)].map(
([, language, tab, code]) => ({ language, tab, code }),
);

const blocksData = blocks.filter(
(block) => block.tab !== undefined && !emptyRegExp.test(block.code),
);

return {
type: 'codeblock',
data: blocksData,
storageKey,
};
}

return {
type: 'codeblock',
data: blocksData,
storageKey,
};
function getFeatureList(content) {
if (!content.startsWith('<featureList')) {
return undefined;
}
return undefined;
const lines = content
.split('\n')
.filter((line) => line.startsWith('- '))
.map((line) => line.slice(2));

return ['<ul class="feature-list">', ...lines.map((line) => `<li>${line}</li>`), '</ul>'].join(
'',
);
}

/**
Expand Down Expand Up @@ -476,6 +491,7 @@ module.exports = {
getContents,
getDescription,
getCodeblock,
getFeatureList,
getHeaders,
getTitle,
renderMarkdown,
Expand Down
8 changes: 7 additions & 1 deletion packages/markdown/prepareMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
getContents,
getDescription,
getCodeblock,
getFeatureList,
getHeaders,
getTitle,
} = require('./parseMarkdown');
Expand Down Expand Up @@ -155,13 +156,18 @@ ${headers.hooks
return null;
}
}

const codeblock = getCodeblock(content);

if (codeblock) {
return codeblock;
}

const featureList = getFeatureList(content);

if (featureList) {
return featureList;
}

return render(content);
});

Expand Down

0 comments on commit 7d3b5a5

Please sign in to comment.