Skip to content

Commit

Permalink
chore(docz-core): remove <Playground> from output code
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jun 30, 2018
1 parent 34911b4 commit 777b8bf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/docz-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"remark-slug": "^5.0.0",
"resolve": "^1.8.1",
"signale": "^1.2.1",
"strip-indent": "^2.0.0",
"to-vfile": "^5.0.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"ulid": "^2.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/docz-core/src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare module 'chokidar'
declare module '@sindresorhus/slugify'
declare module 'humanize-string'
declare module 'unified'
declare module 'strip-indent'
declare module 'unist-util-is'
declare module 'unist-util-visit'
declare module 'unist-util-find'
Expand Down
9 changes: 8 additions & 1 deletion packages/docz-core/src/utils/plugin-hast.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import is from 'unist-util-is'
import nodeToString from 'hast-util-to-string'
import strip from 'strip-indent'

import { format } from '../utils/format'

Expand All @@ -8,6 +9,11 @@ const componentName = (value: any) => {
return match && match[1]
}

const removePlayground = (code: string) =>
code
.replace(/^(\<Playground\>)|(\<Playground.+\>)$/g, '')
.replace(/\<\/Playground\>/g, '')

const isPlayground = (name: string) => name === 'Playground'

const addCodeProp = async (node: any) => {
Expand All @@ -17,10 +23,11 @@ const addCodeProp = async (node: any) => {
if (isPlayground(name)) {
const formatted = await format(nodeToString(node))
const code = formatted.slice(1, Infinity)
const child = strip(removePlayground(code)).trim()

const codeComponent = `components && (
<components.pre className="react-prism language-jsx">
<code>{\`${code}\`}</code>
<code>{\`${child}\`}</code>
</components.pre>
)`

Expand Down

0 comments on commit 777b8bf

Please sign in to comment.