Skip to content

Commit

Permalink
chore: handle parsing code blocks inside sections
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Oct 14, 2020
1 parent 6499557 commit 71992f2
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/components/Tutorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,35 @@ const parseFileInfoFromConfig = (configElement) => {

const parseFileInfoFromChildren = (children) => {
return children
.flatMap((child) => Children.toArray(child.props.children))
.filter((child) => isCodeBlock(child) && !isShellCommand(child))
.reduce((map, child) => {
const { fileName, language } = parseCodeBlockProps(child);
.flatMap((child) => {
switch (child.props.mdxType) {
case 'TutorialStep':
return findCodeBlocksInTutorialStep(child);
case 'TutorialSection':
return findCodeBlocksInTutorialSection(child);
default:
return [];
}
})
.reduce((map, codeBlock) => {
const { fileName, language } = parseCodeBlockProps(codeBlock);

return map.has(fileName)
? map
: map.set(fileName, { code: '', language });
}, new Map());
};

const findCodeBlocksInTutorialStep = (stepElement) => {
return Children.toArray(stepElement.props.children).filter(
(child) => isCodeBlock(child) && !isShellCommand(child)
);
};

const findCodeBlocksInTutorialSection = (sectionElement) => {
return Children.toArray(sectionElement.props.children).flatMap(
findCodeBlocksInTutorialStep
);
};

export default Tutorial;

0 comments on commit 71992f2

Please sign in to comment.