2018-12-14 09:29:46 +03:00
|
|
|
import React from 'react'
|
2018-12-14 08:39:47 +03:00
|
|
|
import {Heading, Link} from '@primer/components'
|
2019-04-03 08:37:38 +03:00
|
|
|
import {CodeExample} from '@primer/blueprints'
|
2018-12-14 08:39:47 +03:00
|
|
|
import Outline from './Outline'
|
|
|
|
|
|
|
|
export const H1 = props => <Heading fontSize={6} fontWeight="light" {...props} />
|
|
|
|
|
|
|
|
export default function getComponents(page = {}) {
|
|
|
|
const {outline: getOutline = () => []} = page
|
|
|
|
|
|
|
|
return {
|
|
|
|
h1: H1,
|
|
|
|
// render links with our component
|
|
|
|
a: Link,
|
2019-03-01 01:58:25 +03:00
|
|
|
// render code blocks with our wrapper around react-live
|
2019-01-17 01:56:16 +03:00
|
|
|
code: CodeExample,
|
2018-12-14 08:39:47 +03:00
|
|
|
// render the outline for <p> tags with exactly the text "{:toc}"
|
|
|
|
p: ({children, ...rest}) => {
|
|
|
|
if (children === '{:toc}') {
|
|
|
|
return <Outline outline={getOutline()} {...rest} />
|
|
|
|
} else {
|
|
|
|
return <p {...rest}>{children}</p>
|
|
|
|
}
|
|
|
|
},
|
2019-01-17 01:56:16 +03:00
|
|
|
// "unwrap" <pre> elements around <code> blocks
|
2018-12-14 08:39:47 +03:00
|
|
|
pre: props => props.children
|
|
|
|
}
|
|
|
|
}
|