-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #556 from primer/release-10.9.0
Minor Release Tracking PR 10.9.0
- Loading branch information
Showing
70 changed files
with
6,826 additions
and
4,756 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,27 @@ | ||
import remark from 'remark' | ||
import parents from 'unist-util-parents' | ||
import select from 'unist-util-select' | ||
import findBefore from 'unist-util-find-before' | ||
import parseCodeBlocks from 'code-blocks/lib/fromString' | ||
import htmlToReact from 'html-to-react' | ||
import parsePairs from 'parse-pairs' | ||
import React from 'react' | ||
import ReactDOMServer from 'react-dom/server' | ||
import {Octicon} from '../Octicon' | ||
|
||
const htmlParser = new htmlToReact.Parser() | ||
|
||
const railsOcticonToReact = (html) => { | ||
// <%= octicon "tools" %> to <Octicon name="tools" /> | ||
const octre = /<%= octicon[\(\s]["']([a-z\-]+)["'][^%]*%>/gi | ||
html = html.replace(octre, (match, name) => { | ||
return ReactDOMServer.renderToStaticMarkup(<Octicon name={name} />) | ||
}) | ||
return html | ||
} | ||
|
||
const parseBlockAttrs = (node, file) => { | ||
const pairs = node.lang.replace(/^html\s*/, '') | ||
const attrs = pairs.length ? parsePairs(pairs) : {} | ||
attrs.title = attrs.title | ||
|| getPreviousHeading(node) | ||
|| `story @ ${file}:${node.position.start.line}` | ||
node.block = attrs | ||
return node | ||
} | ||
|
||
const nodeToStory = (node, file) => { | ||
const html = railsOcticonToReact(node.value) | ||
const {title} = node.block | ||
const blockToStory = block => { | ||
return { | ||
title, | ||
story: () => htmlParser.parse(html), | ||
html, | ||
file, | ||
node, | ||
title: block.title, | ||
story: () => htmlParser.parse(block.value), | ||
block, | ||
} | ||
} | ||
|
||
const getPreviousHeading = node => { | ||
const heading = findBefore(node.parent, node, 'heading') | ||
return (heading && !heading.used) | ||
? (heading.used = true, heading.children.map(c => c.value).join('')) | ||
: undefined | ||
} | ||
|
||
export default req => { | ||
return req.keys() | ||
.filter(file => !file.match(/node_modules/)) | ||
.reduce((stories, file) => { | ||
const content = req(file) | ||
const ast = parents(remark.parse(content)) | ||
const path = file.replace(/^\.\//, '') | ||
return stories.concat( | ||
select(ast, 'code[lang^=html]') | ||
.map(parseBlockAttrs) | ||
.filter(({block}) => block.story !== "false") | ||
.map(node => nodeToStory(node, path)) | ||
) | ||
}, []) | ||
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) | ||
}, []) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ progress { | |
|
||
template, /* 1 */ | ||
[hidden] { | ||
display: none; | ||
display: none !important; | ||
} | ||
|
||
/* Links | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.