From 382f9a4691dee04673e461b3eda0d52c1aefda3b Mon Sep 17 00:00:00 2001 From: harish-sethuraman Date: Mon, 15 Nov 2021 22:25:47 +0530 Subject: [PATCH] dry run prettier --- beta/plugins/remark-header-custom-ids.js | 16 +- .../components/MDX/CodeBlock/CodeBlock.tsx | 173 +++++++++--------- beta/src/components/MDX/MDXComponents.tsx | 4 +- 3 files changed, 95 insertions(+), 98 deletions(-) diff --git a/beta/plugins/remark-header-custom-ids.js b/beta/plugins/remark-header-custom-ids.js index e446fec1b..bf51e98e0 100644 --- a/beta/plugins/remark-header-custom-ids.js +++ b/beta/plugins/remark-header-custom-ids.js @@ -36,27 +36,27 @@ module.exports = ({ // A bit weird: this is to support MDX 2 comments in expressions, // while we’re still on MDX 1, which doesn’t support them. if (!tail || tail.type !== 'text' || tail.value !== '/}') { - return + return; } - tail = children[children.length - 2] + tail = children[children.length - 2]; if (!tail && tail.type !== 'emphasis') { - return + return; } - const id = toString(tail) + const id = toString(tail); - tail = children[children.length - 3] + tail = children[children.length - 3]; if (!tail || tail.type !== 'text' || !tail.value.endsWith('{/')) { - return + return; } // Remove the emphasis and trailing `/}` - children.splice(children.length - 2, 2) + children.splice(children.length - 2, 2); // Remove the `{/` - tail.value = tail.value.replace(/[ \t]*\{\/$/, '') + tail.value = tail.value.replace(/[ \t]*\{\/$/, ''); const data = patch(node, 'data', {}); diff --git a/beta/src/components/MDX/CodeBlock/CodeBlock.tsx b/beta/src/components/MDX/CodeBlock/CodeBlock.tsx index 97d488e63..68cb7e42c 100644 --- a/beta/src/components/MDX/CodeBlock/CodeBlock.tsx +++ b/beta/src/components/MDX/CodeBlock/CodeBlock.tsx @@ -21,98 +21,93 @@ interface InlineHiglight { endColumn: number; } -const CodeBlock = React.forwardRef(function CodeBlock - ( - { - children, - className = 'language-js', - metastring, - noMargin, - noMarkers, - }: { - children: string; - className?: string; - metastring: string; - noMargin?: boolean; - noMarkers?: boolean; - }, - ref?: React.Ref - ) { - const getDecoratedLineInfo = () => { - if (!metastring) { - return []; - } +const CodeBlock = React.forwardRef(function CodeBlock( + { + children, + className = 'language-js', + metastring, + noMargin, + noMarkers, + }: { + children: string; + className?: string; + metastring: string; + noMargin?: boolean; + noMarkers?: boolean; + }, + ref?: React.Ref +) { + const getDecoratedLineInfo = () => { + if (!metastring) { + return []; + } - const linesToHighlight = getHighlightLines(metastring); - const highlightedLineConfig = linesToHighlight.map((line) => { - return { - className: 'bg-github-highlight dark:bg-opacity-10', - line, - }; - }); + const linesToHighlight = getHighlightLines(metastring); + const highlightedLineConfig = linesToHighlight.map((line) => { + return { + className: 'bg-github-highlight dark:bg-opacity-10', + line, + }; + }); - const inlineHighlightLines = getInlineHighlights(metastring, children); - const inlineHighlightConfig = inlineHighlightLines.map( - (line: InlineHiglight) => ({ - ...line, - elementAttributes: {'data-step': `${line.step}`}, - className: cn( - 'code-step bg-opacity-10 relative rounded-md p-1 ml-2', - { - 'pl-3 before:content-[attr(data-step)] before:block before:w-4 before:h-4 before:absolute before:top-1 before:-left-2 before:rounded-full before:text-white before:text-center before:text-xs before:leading-4': - !noMarkers, - 'bg-blue-40 before:bg-blue-40': line.step === 1, - 'bg-yellow-40 before:bg-yellow-40': line.step === 2, - 'bg-green-40 before:bg-green-40': line.step === 3, - 'bg-purple-40 before:bg-purple-40': line.step === 4, - } - ), - }) - ); - - return highlightedLineConfig.concat(inlineHighlightConfig); - }; - - // e.g. "language-js" - const language = className.substring(9); - const filename = '/index.' + language; - const decorators = getDecoratedLineInfo(); - return ( -
- - - - - - - -
+ const inlineHighlightLines = getInlineHighlights(metastring, children); + const inlineHighlightConfig = inlineHighlightLines.map( + (line: InlineHiglight) => ({ + ...line, + elementAttributes: {'data-step': `${line.step}`}, + className: cn('code-step bg-opacity-10 relative rounded-md p-1 ml-2', { + 'pl-3 before:content-[attr(data-step)] before:block before:w-4 before:h-4 before:absolute before:top-1 before:-left-2 before:rounded-full before:text-white before:text-center before:text-xs before:leading-4': + !noMarkers, + 'bg-blue-40 before:bg-blue-40': line.step === 1, + 'bg-yellow-40 before:bg-yellow-40': line.step === 2, + 'bg-green-40 before:bg-green-40': line.step === 3, + 'bg-purple-40 before:bg-purple-40': line.step === 4, + }), + }) ); - } -); + + return highlightedLineConfig.concat(inlineHighlightConfig); + }; + + // e.g. "language-js" + const language = className.substring(9); + const filename = '/index.' + language; + const decorators = getDecoratedLineInfo(); + return ( +
+ + + + + + + +
+ ); +}); export default CodeBlock; diff --git a/beta/src/components/MDX/MDXComponents.tsx b/beta/src/components/MDX/MDXComponents.tsx index 611db2b07..91941c0de 100644 --- a/beta/src/components/MDX/MDXComponents.tsx +++ b/beta/src/components/MDX/MDXComponents.tsx @@ -244,7 +244,9 @@ function IllustrationBlock({ {sequential ? (
    {images.map((x: any, i: number) => ( -
  1. {x}
  2. +
  3. + {x} +
  4. ))}
) : (