Skip to content

Commit

Permalink
feat(rehype-docz): add mdx exports to Playground scope
Browse files Browse the repository at this point in the history
  • Loading branch information
rakannimer committed Dec 14, 2019
1 parent 9c564d0 commit d902e2a
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/rehype-docz/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import nodeToString from 'hast-util-to-string'
import { format } from 'docz-utils/lib/format'
import { componentName, sanitizeCode, removeTags } from 'docz-utils/lib/jsx'
import { getImportsVariables } from 'docz-utils/lib/imports'
import { getExportsVariables } from 'docz-utils/lib/exports'

const isPlayground = (name: string) => {
return name === 'Playground'
Expand Down Expand Up @@ -34,7 +35,13 @@ export interface PluginOpts {

export default () => (tree: any) => {
const importNodes = tree.children.filter((n: any) => n.type === 'import')
const scopes: string[] = flatten(importNodes.map(getImportsVariables))
const exportNodes = tree.children.filter((n: any) => n.type === 'export')
const importedScopes = flatten<string>(importNodes.map(getImportsVariables))
const exportedScopes = flatten<string>(exportNodes.map(getExportsVariables))
// filter added to avoid throwing if an unexpected type is exported
const scopes: string[] = [...importedScopes, ...exportedScopes].filter(
Boolean
)
const nodes = tree.children
.filter((node: any) => node.type === 'jsx')
.map(addComponentsProps(scopes))
Expand Down

0 comments on commit d902e2a

Please sign in to comment.