From 4c548717618c424f40ede632cb3a8c0f2b515352 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 18 Oct 2019 11:23:03 +0800 Subject: [PATCH 1/2] MDX: Handle `` name starting with number --- .../__snapshots__/mdx-compiler-plugin.test.js.snap | 14 +++++++++++++- .../src/mdx/__testfixtures__/story-definitions.mdx | 4 ++++ addons/docs/src/mdx/mdx-compiler-plugin.js | 4 ++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap b/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap index 9644bb08c6a..76cfd8a7409 100644 --- a/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap +++ b/addons/docs/src/mdx/__snapshots__/mdx-compiler-plugin.test.js.snap @@ -511,6 +511,9 @@ function MDXContent({ components, ...props }) { + + + ); } @@ -532,12 +535,21 @@ wPunctuation.story = {}; wPunctuation.story.name = 'w/punctuation'; wPunctuation.story.parameters = { mdxSource: '' }; -const componentMeta = { title: 'Button', includeStories: ['one', 'helloStory', 'wPunctuation'] }; +export const _1FineDay = () => ; +_1FineDay.story = {}; +_1FineDay.story.name = '1 fine day'; +_1FineDay.story.parameters = { mdxSource: '' }; + +const componentMeta = { + title: 'Button', + includeStories: ['one', 'helloStory', 'wPunctuation', '_1FineDay'], +}; const mdxStoryNameToId = { one: 'button--one', 'hello story': 'button--hello-story', 'w/punctuation': 'button--w-punctuation', + '1 fine day': 'button--1-fine-day', }; componentMeta.parameters = componentMeta.parameters || {}; diff --git a/addons/docs/src/mdx/__testfixtures__/story-definitions.mdx b/addons/docs/src/mdx/__testfixtures__/story-definitions.mdx index 74dc5db7a0d..b50bb0df7e2 100644 --- a/addons/docs/src/mdx/__testfixtures__/story-definitions.mdx +++ b/addons/docs/src/mdx/__testfixtures__/story-definitions.mdx @@ -16,3 +16,7 @@ import { Story, Meta } from '@storybook/addon-docs/blocks'; + + + + diff --git a/addons/docs/src/mdx/mdx-compiler-plugin.js b/addons/docs/src/mdx/mdx-compiler-plugin.js index e21ef8fdd58..1e0fa1dfbc4 100644 --- a/addons/docs/src/mdx/mdx-compiler-plugin.js +++ b/addons/docs/src/mdx/mdx-compiler-plugin.js @@ -19,12 +19,16 @@ function getAttr(elt, what) { } const isReserved = name => RESERVED.exec(name); +const startsWithNumber = name => /^\d/.exec(name); const sanitizeName = name => { let key = camelCase(name); if (isReserved(key)) { key = `${key}Story`; } + if (startsWithNumber(key)) { + key = `_${key}`; + } return key; }; From 766f0133feb2114b1e24cb506142292993d5523d Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Fri, 18 Oct 2019 11:27:30 +0800 Subject: [PATCH 2/2] Update mdx-compiler-plugin.js --- addons/docs/src/mdx/mdx-compiler-plugin.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/docs/src/mdx/mdx-compiler-plugin.js b/addons/docs/src/mdx/mdx-compiler-plugin.js index 1e0fa1dfbc4..e72c5c548ad 100644 --- a/addons/docs/src/mdx/mdx-compiler-plugin.js +++ b/addons/docs/src/mdx/mdx-compiler-plugin.js @@ -23,11 +23,10 @@ const startsWithNumber = name => /^\d/.exec(name); const sanitizeName = name => { let key = camelCase(name); - if (isReserved(key)) { - key = `${key}Story`; - } if (startsWithNumber(key)) { key = `_${key}`; + } else if (isReserved(key)) { + key = `${key}Story`; } return key; };