-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
9df4cbf
commit 861309f
Showing
9 changed files
with
987 additions
and
1,115 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
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,11 +1,15 @@ | ||
import * as React from 'react' | ||
import {MDXProvider} from '@mdx-js/tag' | ||
import MdxComponents from '../mdx' | ||
|
||
export interface Props { | ||
children: React.ReactNode | ||
} | ||
|
||
const Layout = ({children}: Props) => ( | ||
<div css={{padding: '3% 6%'}}>{children}</div> | ||
<MDXProvider components={MdxComponents}> | ||
<div css={{padding: '3% 6%'}}>{children}</div> | ||
</MDXProvider> | ||
) | ||
|
||
export default Layout |
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,61 @@ | ||
import * as React from 'react' | ||
import {css} from '@emotion/core' | ||
import Highlight, {defaultProps} from 'prism-react-renderer' | ||
|
||
interface Props { | ||
codeString: string | ||
language: string | ||
} | ||
|
||
interface InnerProps { | ||
className: string | ||
style: Object | ||
tokens: Array<Array<unknown>> | ||
getLineProps: (Object: {line: unknown[]; key: any}) => Object | ||
getTokenProps: (Object: {token: unknown; key: any}) => Object | ||
} | ||
|
||
export default function Code({codeString, language}: Props) { | ||
return ( | ||
<Highlight | ||
{...defaultProps} | ||
code={codeString} | ||
language={language} | ||
// to be able to use normal CSS Prism themes | ||
// https://www.npmjs.com/package/prism-react-renderer#faq | ||
theme={undefined} | ||
> | ||
{({ | ||
className, | ||
style, | ||
tokens, | ||
getLineProps, | ||
getTokenProps, | ||
}: InnerProps) => ( | ||
<pre className={className} style={style}> | ||
<code> | ||
{tokens.map((line, i) => ( | ||
<div {...getLineProps({line, key: i})}> | ||
<span | ||
css={css` | ||
display: inline-block; | ||
width: 1.5em; | ||
text-align: right; | ||
margin-right: 1rem; | ||
user-select: none; | ||
opacity: 0.3; | ||
`} | ||
> | ||
{i + 1} | ||
</span> | ||
{line.map((token, key) => ( | ||
<span {...getTokenProps({token, key})} /> | ||
))} | ||
</div> | ||
))} | ||
</code> | ||
</pre> | ||
)} | ||
</Highlight> | ||
) | ||
} |
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,16 @@ | ||
import * as React from 'react' | ||
import {preToCodeBlock} from 'mdx-utils' | ||
import Code from './Code' | ||
|
||
export default { | ||
pre: (preProps: Object) => { | ||
const props = preToCodeBlock(preProps) | ||
// if there's a codeString and some props, we passed the test | ||
if (props) { | ||
return <Code {...props} /> | ||
} else { | ||
// it's possible to have a pre without a code in it | ||
return <pre {...preProps} /> | ||
} | ||
}, | ||
} |
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
Oops, something went wrong.