From 649918abe5e954ab0c24f49d2f28679b65e2a1c7 Mon Sep 17 00:00:00 2001 From: Corwin Smith Date: Wed, 16 Nov 2022 21:37:01 -0700 Subject: [PATCH] inline code styles --- src/components/MDXComponents.tsx | 15 +++++----- src/components/UI/docs/Code.tsx | 37 +++++++++++++++++++++++++ src/components/UI/docs/index.tsx | 1 + src/utils/getProgrammingLanguageName.ts | 2 +- 4 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 src/components/UI/docs/Code.tsx create mode 100644 src/components/UI/docs/index.tsx diff --git a/src/components/MDXComponents.tsx b/src/components/MDXComponents.tsx index 27b2e65aa8..a3f898d2bc 100644 --- a/src/components/MDXComponents.tsx +++ b/src/components/MDXComponents.tsx @@ -1,7 +1,8 @@ import { Heading, Link, Stack, Text } from '@chakra-ui/react'; import NextLink from 'next/link'; import { PrismLight as SyntaxHighlighter } from 'react-syntax-highlighter'; -import { nightOwl } from 'react-syntax-highlighter/dist/cjs/styles/prism'; + +import { Code } from './UI/docs' import bash from 'react-syntax-highlighter/dist/cjs/languages/prism/bash'; import go from 'react-syntax-highlighter/dist/cjs/languages/prism/go'; @@ -26,8 +27,6 @@ SyntaxHighlighter.registerLanguage('sh', sh); SyntaxHighlighter.registerLanguage('solidity', solidity); SyntaxHighlighter.registerLanguage('swift', swift); -import { getProgrammingLanguageName } from '../utils'; - const MDXComponents = { // paragraphs p: ({ children }: any) => { @@ -87,10 +86,12 @@ const MDXComponents = {
{children}
); - } + }, // code - // code: (code: any) => { - // const language = getProgrammingLanguageName(code); + code: (code: any) => { + return ( + + ) // return !!code.inline ? ( // // ); - // } + } }; export default MDXComponents; diff --git a/src/components/UI/docs/Code.tsx b/src/components/UI/docs/Code.tsx new file mode 100644 index 0000000000..3ff8e8972a --- /dev/null +++ b/src/components/UI/docs/Code.tsx @@ -0,0 +1,37 @@ +// Libraries +import { Code as ChakraCode } from '@chakra-ui/react'; +import { FC } from 'react'; + +// Utils +import { getProgrammingLanguageName } from '../../../utils'; + + +interface Props { + code: any; +} + +export const Code: FC = ({ code }) => { + const language = getProgrammingLanguageName(code); + + return ( + !!code.inline ? + ( + + {code.children[0]} + + ) + : + ( +

test

+ ) + ); +}; diff --git a/src/components/UI/docs/index.tsx b/src/components/UI/docs/index.tsx new file mode 100644 index 0000000000..823cfaea66 --- /dev/null +++ b/src/components/UI/docs/index.tsx @@ -0,0 +1 @@ +export * from './Code'; \ No newline at end of file diff --git a/src/utils/getProgrammingLanguageName.ts b/src/utils/getProgrammingLanguageName.ts index 40f454f300..95e040c8bd 100644 --- a/src/utils/getProgrammingLanguageName.ts +++ b/src/utils/getProgrammingLanguageName.ts @@ -1,7 +1,7 @@ // WIP export const getProgrammingLanguageName = (code: any) => { // const hasLanguageNameProperty = Object.keys(code.node.properties).length > 0; - console.log({ code }); + // console.log({ code }); // return hasLanguageNameProperty ? code.node.properties.className[0].split('-')[1] : 'bash'; };