forked from ethereum/go-ethereum
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from ethereum/markdown-styling
Markdown styling
- Loading branch information
Showing
13 changed files
with
3,704 additions
and
3,345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,77 @@ | ||
// Libraries | ||
import { Code as ChakraCode, Stack, Text } from '@chakra-ui/react'; | ||
import { FC } from 'react'; | ||
import { Code as ChakraCode, Stack, Text, useColorMode } from '@chakra-ui/react'; | ||
import { nightOwl, prism } from 'react-syntax-highlighter/dist/cjs/styles/prism'; | ||
import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter'; | ||
|
||
// Constants, utilities | ||
import { CLASSNAME_PREFIX } from '../../../constants'; | ||
import { getProgrammingLanguageName } from '../../../utils'; | ||
|
||
// Programming lang syntax highlighters | ||
import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash'; | ||
import go from 'react-syntax-highlighter/dist/cjs/languages/prism/go'; | ||
import graphql from 'react-syntax-highlighter/dist/cjs/languages/prism/graphql'; | ||
import java from 'react-syntax-highlighter/dist/cjs/languages/prism/java'; | ||
import javascript from 'react-syntax-highlighter/dist/cjs/languages/prism/javascript'; | ||
import json from 'react-syntax-highlighter/dist/cjs/languages/prism/json'; | ||
import python from 'react-syntax-highlighter/dist/cjs/languages/prism/python'; | ||
import sh from 'react-syntax-highlighter/dist/cjs/languages/prism/shell-session'; | ||
import solidity from 'react-syntax-highlighter/dist/cjs/languages/prism/solidity'; | ||
import swift from 'react-syntax-highlighter/dist/cjs/languages/prism/swift'; | ||
|
||
// syntax highlighting languages supported | ||
SyntaxHighlighter.registerLanguage('bash', bash); | ||
SyntaxHighlighter.registerLanguage('terminal', bash); | ||
SyntaxHighlighter.registerLanguage('go', go); | ||
SyntaxHighlighter.registerLanguage('graphql', graphql); | ||
SyntaxHighlighter.registerLanguage('java', java); | ||
SyntaxHighlighter.registerLanguage('javascript', javascript); | ||
SyntaxHighlighter.registerLanguage('json', json); | ||
SyntaxHighlighter.registerLanguage('python', python); | ||
SyntaxHighlighter.registerLanguage('sh', sh); | ||
SyntaxHighlighter.registerLanguage('solidity', solidity); | ||
SyntaxHighlighter.registerLanguage('swift', swift); | ||
|
||
interface Props { | ||
code: any; | ||
className: string; | ||
children: string[]; | ||
inline?: boolean; | ||
} | ||
|
||
export const Code: FC<Props> = ({ code }) => { | ||
return ( | ||
!!code.inline ? | ||
( | ||
<Text | ||
as='span' | ||
background='code-bg' | ||
textStyle='inline-code-snippet' | ||
pb={2} | ||
mb={-2} | ||
> | ||
{code.children[0]} | ||
</Text> | ||
) | ||
: | ||
( | ||
<Stack> | ||
<ChakraCode | ||
overflow='auto' | ||
p={6} | ||
background='code-bg-contrast' | ||
textStyle='code-block' | ||
color='code-text' | ||
> | ||
{code.children[0]} | ||
</ChakraCode> | ||
</Stack> | ||
) | ||
); | ||
export const Code: React.FC<Props> = ({ className, children, inline }) => { | ||
const { colorMode } = useColorMode(); | ||
const isDark = colorMode === 'dark'; | ||
const isTerminal = className?.includes('terminal'); | ||
const [content] = children; | ||
if (inline) | ||
return ( | ||
<Text | ||
as='span' | ||
px={1} | ||
color='primary' | ||
bg='code-bg' | ||
borderRadius='0.25em' | ||
textStyle='inline-code-snippet' | ||
> | ||
{content} | ||
</Text> | ||
); | ||
if (isTerminal) | ||
return ( | ||
<Stack> | ||
<ChakraCode overflow='auto' p={6} background='terminal-bg' color='terminal-text'> | ||
{content} | ||
</ChakraCode> | ||
</Stack> | ||
); | ||
if (className?.startsWith(CLASSNAME_PREFIX)) | ||
return ( | ||
<SyntaxHighlighter | ||
language={getProgrammingLanguageName(className)} | ||
style={isDark ? nightOwl : prism} | ||
customStyle={{ borderRadius: '0.5rem', padding: '1rem' }} | ||
> | ||
{content} | ||
</SyntaxHighlighter> | ||
); | ||
return <Stack>{content}</Stack>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const fonts = { | ||
// set base fonts as fallback | ||
heading: '"JetBrains Mono", monospace', | ||
button: '"JetBrains Mono", monospace', | ||
code: '"JetBrains Mono", monospace', | ||
body: '"Inter", sans-serif' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './colors'; | ||
export * from './config'; | ||
export * from './fonts'; | ||
export * from './shadows'; | ||
export * from './sizes'; | ||
export * from './textStyles'; |
Oops, something went wrong.