mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-07 07:21:17 +08:00
make source-language configurable
This commit is contained in:
parent
659bfa3a9f
commit
b7c44a13a1
@ -93,7 +93,7 @@ export const getSourceProps = (
|
||||
docsContext: DocsContextProps,
|
||||
sourceContext: SourceContextProps
|
||||
): PureSourceProps => {
|
||||
const { id: currentId } = docsContext;
|
||||
const { id: currentId, parameters = {} } = docsContext;
|
||||
|
||||
const codeProps = props as CodeProps;
|
||||
const singleProps = props as SingleSourceProps;
|
||||
@ -112,8 +112,13 @@ export const getSourceProps = (
|
||||
})
|
||||
.join('\n\n');
|
||||
}
|
||||
|
||||
const { docs: docsParameters = {} } = parameters;
|
||||
const { source: sourceParameters = {} } = docsParameters;
|
||||
const { language: docsLanguage = null } = sourceParameters;
|
||||
|
||||
return source
|
||||
? { code: source, language: props.language || 'jsx', dark: props.dark || false }
|
||||
? { code: source, language: props.language || docsLanguage || 'jsx', dark: props.dark || false }
|
||||
: { error: SourceError.SOURCE_UNAVAILABLE };
|
||||
};
|
||||
|
||||
|
@ -8,6 +8,7 @@ export const parameters = {
|
||||
extractComponentDescription,
|
||||
source: {
|
||||
type: SourceType.DYNAMIC,
|
||||
language: 'html',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -214,7 +214,7 @@ Storybook Docs displays a story’s source code using the `Source` block. The sn
|
||||
|
||||
In DocsPage, the `Source` block appears automatically within each story’s [Canvas](#canvas) block.
|
||||
|
||||
To customize the source snippet that’s displayed for a story, set the `docs.source.code` parameter:
|
||||
To customize the source snippet that’s displayed for a story, set the `docs.source.code` and optionally the `docs.source.language` parameters:
|
||||
|
||||
<!-- prettier-ignore-start -->
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user