Skip to content

Commit

Permalink
feat: create custom code block that renders a terminal for shell lang…
Browse files Browse the repository at this point in the history
…uages
  • Loading branch information
jerelmiller committed Oct 14, 2020
1 parent 9cc58b1 commit ca27f28
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/@newrelic/gatsby-theme-newrelic/components/CodeBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import CodeBlock from '@newrelic/gatsby-theme-newrelic/src/components/CodeBlock';
import Terminal from '../../../components/Terminal';
import { isShellLanguage } from '../../../utils/codeBlock';

const CustomCodeBlock = ({ language, children, ...props }) => {
return isShellLanguage(language) ? (
<Terminal>{children}</Terminal>
) : (
<CodeBlock language={language} {...props}>
{children}
</CodeBlock>
);
};

CustomCodeBlock.propTypes = CodeBlock.propTypes;

export default CustomCodeBlock;
4 changes: 3 additions & 1 deletion src/utils/codeBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export const isCodeBlock = (element) =>

export const isShellCommand = (element) =>
isCodeBlock(element) &&
SHELL_LANGUAGES.includes(
isShellLanguage(
element.props?.children?.props?.className?.replace('language-', '')
);

export const isShellLanguage = (language) => SHELL_LANGUAGES.includes(language);

0 comments on commit ca27f28

Please sign in to comment.