From a8cbe1cdf4b5a6e4273bca191481c34d2f71be50 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 14 Mar 2024 10:47:06 +0100 Subject: [PATCH] Implement option 3 --- .../experiments/docs/custom-components.md | 10 ++++ packages/markdown/parseMarkdown.js | 46 +++++++++++++------ packages/markdown/prepareMarkdown.js | 8 +++- 3 files changed, 48 insertions(+), 16 deletions(-) diff --git a/docs/pages/experiments/docs/custom-components.md b/docs/pages/experiments/docs/custom-components.md index c91e51a1e24d07..e2119d4cea13de 100644 --- a/docs/pages/experiments/docs/custom-components.md +++ b/docs/pages/experiments/docs/custom-components.md @@ -25,3 +25,13 @@ Easier to write and read, and potentially easier to violate the styles?
  • It properly manages focus; moving to the modal content, and keeping it there until the modal is closed.
  • Adds the appropriate ARIA roles automatically.
  • + +### Approach 3: Custom markdown + + +- 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. + diff --git a/packages/markdown/parseMarkdown.js b/packages/markdown/parseMarkdown.js index 15feaa6c6372bc..ba95ecd8f06dd7 100644 --- a/packages/markdown/parseMarkdown.js +++ b/packages/markdown/parseMarkdown.js @@ -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(/^()$/gmsu)) + .flatMap((text) => text.split(/^()$/gmsu)) .filter((content) => !emptyRegExp.test(content)); // Remove empty lines return rep; } @@ -212,23 +213,37 @@ function getDescription(markdown) { } function getCodeblock(content) { - if (content.startsWith(']*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(']*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(' line.startsWith('- ')) + .map((line) => line.slice(2)); + + return ['
      ', ...lines.map((line) => `
    • ${line}
    • `), '
    '].join( + '', + ); } /** @@ -475,6 +490,7 @@ module.exports = { getContents, getDescription, getCodeblock, + getFeatureList, getHeaders, getTitle, renderMarkdown, diff --git a/packages/markdown/prepareMarkdown.js b/packages/markdown/prepareMarkdown.js index c66fbfebfc21cc..caaa61d0fbbd97 100644 --- a/packages/markdown/prepareMarkdown.js +++ b/packages/markdown/prepareMarkdown.js @@ -7,6 +7,7 @@ const { getContents, getDescription, getCodeblock, + getFeatureList, getHeaders, getTitle, } = require('./parseMarkdown'); @@ -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); });