diff --git a/docs/pages/_app.js b/docs/pages/_app.js
index 7d489bfd..0c3cab88 100644
--- a/docs/pages/_app.js
+++ b/docs/pages/_app.js
@@ -4,6 +4,7 @@ import {MDXProvider} from '@mdx-js/tag'
import Head from 'next/head'
import {BaseStyles, Box, Flex, Link, theme} from '@primer/components'
import {Header, CodeExample, PackageHeader, SideNav, IndexHero} from '../src/components'
+import getComponents from '../src/markdown'
import {rootPage} from '../src/utils'
import {CONTENT_MAX_WIDTH} from '../src/constants'
@@ -27,23 +28,8 @@ export default class MyApp extends App {
const {Component, page} = this.props
const node = rootPage.first(node => node.path === pathname)
- const {meta = {}, outline: getOutline = () => []} = node || {}
-
- const components = {
- // render links with our component
- a: Link,
- // render the outline for
tags with exactly the text "{:toc}"
- p: ({children, ...rest}) => {
- if (children === '{:toc}') {
- return
- } else {
- return
{children}
- }
- },
- // render code blocks with our wrapper around mdx-live
- code: CodeExample,
- pre: props => props.children
- }
+ const {meta = {}} = node || {}
+ const components = getComponents(node)
return (
@@ -52,9 +38,7 @@ export default class MyApp extends App {
Primer CSS{meta.title ? ` / ${meta.title}` : null}
-
+
{meta.hero ? : null}
@@ -81,31 +65,3 @@ export default class MyApp extends App {
)
}
}
-
-function TableOfContents({outline, ...rest}) {
- if (outline && outline.length) {
- return (
-
- Table of contents
-
-
- )
- }
- return null
-}
-
-function List({items, ...rest}) {
- if (items && items.length) {
- return (
-
- )
- }
- return null
-}
diff --git a/docs/src/CodeExample.js b/docs/src/CodeExample.js
index caa5ee38..f269f6cc 100644
--- a/docs/src/CodeExample.js
+++ b/docs/src/CodeExample.js
@@ -1,3 +1,4 @@
+import React from 'react'
import {withMDXLive} from 'mdx-live'
import HTMLtoJSX from 'html-2-jsx'
@@ -10,7 +11,7 @@ const LiveEditor = withMDXLive('pre')
LiveEditor.defaultProps = {
// match ```html and ```jsx fenced code blocks, with or without "."
- match: /\blanguage\-\.?(html|jsx)\b/
+ match: /\blanguage-\.?(html|jsx)\b/
}
export default function CodeExample(props) {
@@ -18,9 +19,7 @@ export default function CodeExample(props) {
// get children; we need to handle both and convert them to a single string
// that we can sanitize
const {unsafeInnerHTML, children, ...rest} = props
- const html = unsafeInnerHTML
- ? unsafeInnerHTML.__html
- : React.Children.toArray(children).join('\n')
+ const html = unsafeInnerHTML ? unsafeInnerHTML.__html : React.Children.toArray(children).join('\n')
const jsx = converter.convert(html)
return {jsx}
}
diff --git a/docs/src/Outline.js b/docs/src/Outline.js
new file mode 100644
index 00000000..ffb2face
--- /dev/null
+++ b/docs/src/Outline.js
@@ -0,0 +1,29 @@
+import {Box} from '@primer/components'
+
+export default function Outline({outline, ...rest}) {
+ if (outline && outline.length) {
+ return (
+
+ Table of contents
+
+
+ )
+ }
+ return null
+}
+
+export function OutlineList({items, ...rest}) {
+ if (items && items.length) {
+ return (
+
+ )
+ }
+ return null
+}
diff --git a/docs/src/markdown.js b/docs/src/markdown.js
new file mode 100644
index 00000000..6c07032d
--- /dev/null
+++ b/docs/src/markdown.js
@@ -0,0 +1,26 @@
+import {Heading, Link} from '@primer/components'
+import CodeExample from './CodeExample'
+import Outline from './Outline'
+
+export const H1 = props =>
+
+export default function getComponents(page = {}) {
+ const {outline: getOutline = () => []} = page
+
+ return {
+ h1: H1,
+ // render links with our component
+ a: Link,
+ // render the outline for tags with exactly the text "{:toc}"
+ p: ({children, ...rest}) => {
+ if (children === '{:toc}') {
+ return
+ } else {
+ return
{children}
+ }
+ },
+ // render code blocks with our wrapper around mdx-live
+ code: CodeExample,
+ pre: props => props.children
+ }
+}