1
1
mirror of https://github.com/primer/css.git synced 2024-12-12 10:47:14 +03:00
css/.storybook/lib/storiesFromMarkdown.js
2018-10-17 14:58:35 -07:00

28 lines
741 B
JavaScript

import parseCodeBlocks from 'code-blocks/lib/fromString'
import htmlToReact from 'html-to-react'
const htmlParser = new htmlToReact.Parser()
const blockToStory = block => {
return {
title: block.title,
story: () => htmlParser.parse(block.value),
block,
}
}
export default function storiesFromMarkdown(req) {
return req.keys().reduce((stories, file) => {
const markdown = req(file)
const path = file.replace(/^\.\//, '')
const blocks = parseCodeBlocks(markdown, path)
.filter(block => {
// read: ```html *
// skip: ```html * story="false"
return block.lang === 'html' && block.info.story !== 'false'
})
.map(blockToStory)
return stories.concat(blocks)
}, [])
}