Skip to content

Commit edcbe3a

Browse files
committed
docs(storybook): add customStyle to SyntaxHighlighter to fix hack of moving code blocks around
1 parent 03c1c03 commit edcbe3a

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

storyhelpers/storybook-readme/register.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import React, { useEffect, useState } from 'react';
99
import ReactMarkdown from 'react-markdown';
1010
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter';
1111
import {
12-
vs,
13-
vscDarkPlus,
12+
vs as lightTheme,
13+
vscDarkPlus as darkTheme,
1414
} from 'react-syntax-highlighter/dist/esm/styles/prism';
1515
import remarkGfm from 'remark-gfm';
1616

@@ -50,18 +50,23 @@ const Readme = () => {
5050
const match = /language-(\w+)/.exec(className || '');
5151
return !inline && match ? (
5252
<SyntaxHighlighter
53-
className="storybook-readme-syntax-highlighter"
53+
{...props}
5454
children={String(children).replace(/\n$/, '')}
55-
style={{
56-
...(useDarkMode ? vscDarkPlus : vs),
57-
'pre[class*="language-"]': { display: 'none' },
55+
style={useDarkMode ? darkTheme : lightTheme}
56+
customStyle={{
57+
background: 'none',
58+
border: 0,
59+
padding: 0,
60+
margin: 0,
61+
fontSize: 'inherit',
62+
lineHeight: 'inherit',
5863
}}
5964
language={match[1]}
6065
PreTag={'div'}
61-
{...props}
66+
useInlineStyles={true}
6267
/>
6368
) : (
64-
<code className={className} {...props}>
69+
<code {...props} className={className}>
6570
{children}
6671
</code>
6772
);
@@ -83,7 +88,7 @@ const Readme = () => {
8388
);
8489
};
8590

86-
addons.register(ADDON_ID, api => {
91+
addons.register(ADDON_ID, () => {
8792
addons.add(PANEL_ID, {
8893
type: types.PANEL,
8994
title: 'Readme',

0 commit comments

Comments
 (0)