Skip to content

Commit b93f58e

Browse files
committed
Updating storiesFromMarkdown to read in rails octicons helper and replace with react component
1 parent 50313f1 commit b93f58e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

.storybook/lib/storiesFromMarkdown.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,23 @@ import select from 'unist-util-select'
44
import findBefore from 'unist-util-find-before'
55
import htmlToReact from 'html-to-react'
66
import parsePairs from 'parse-pairs'
7+
import React from 'react'
8+
import ReactDOMServer from 'react-dom/server'
9+
import {Octicon} from '../Octicon'
710

811
const htmlParser = new htmlToReact.Parser()
912

13+
const railsOcticonToReact = (html) => {
14+
// <%= octicon "tools" %> to <Octicon name="tools" />
15+
const octre = /<%= octicon ["']([a-z\-]+)["'] %>/gi
16+
html = html.replace(octre, (match, name) => {
17+
return ReactDOMServer.renderToStaticMarkup(<Octicon name={name} />)
18+
})
19+
return html
20+
}
21+
1022
const nodeToStory = (node, file) => {
11-
const html = node.value
23+
let html = railsOcticonToReact(node.value)
1224
const element = htmlParser.parse(html)
1325
const pairs = node.lang.replace(/^html\s*/, '')
1426
const attrs = pairs.length ? parsePairs(pairs) : {}

0 commit comments

Comments
 (0)