Skip to content

Commit

Permalink
fix(docz): props markdown compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jul 12, 2019
1 parent a4b8eb9 commit 99ba83c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/docz/src/components/Props.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react'
import { createElement, SFC, ComponentType, useMemo } from 'react'
import { first, get } from 'lodash/fp'
import { assoc, first, get, mapValues } from 'lodash/fp'
import capitalize from 'capitalize'
import marksy from 'marksy'

Expand Down Expand Up @@ -124,18 +124,20 @@ export const Props: SFC<PropsProps> = ({
const firstDefinition = first(value)
const definition = value.find((i: any) => i.displayName === componentName)

const compileMarkdown = useMemo(
const compile = useMemo(
() => marksy({ createElement, elements: components }),
[components]
)

const props = useMemo(() => {
const props = get('props', definition || firstDefinition)
return Object.entries(props).reduce((obj, [key, value]) => {
if (key !== 'description') return obj
return { ...obj, description: compileMarkdown(value).tree }
}, props)
}, [compileMarkdown, definition || firstDefinition])
const parseDescs = mapValues((prop: any) => {
const desc = get('description', prop)
return !desc ? prop : assoc('description', compile(desc).tree, prop)
})

return parseDescs(props)
}, [compile, definition || firstDefinition])

if (!props) return null
if (!PropsComponent) return null
Expand Down

0 comments on commit 99ba83c

Please sign in to comment.