diff --git a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighter.tsx b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighter.tsx index 624a930241..6c28e4d1c9 100644 --- a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighter.tsx +++ b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighter.tsx @@ -38,7 +38,6 @@ export const FernSyntaxHighlighter = forwardRef< return highlightTokens(highlighter, code, language); } catch (e) { // TODO: sentry - // eslint-disable-next-line no-console console.error("Error occurred while highlighting tokens", e); return createRawTokens(code, language); } diff --git a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokens.tsx b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokens.tsx index 0a106150f3..7f8abf03ae 100644 --- a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokens.tsx +++ b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokens.tsx @@ -1,9 +1,15 @@ import { FernScrollArea } from "@fern-docs/components"; import { parseStringStyle, visit } from "@fern-docs/mdx"; import cn from "clsx"; -import { isEqual } from "es-toolkit/predicate"; import type { Element } from "hast"; -import { forwardRef, memo, useImperativeHandle, useMemo, useRef } from "react"; +import { + ComponentPropsWithoutRef, + forwardRef, + memo, + useImperativeHandle, + useMemo, + useRef, +} from "react"; import { HastToJSX } from "./HastToJsx"; import { HighlightedTokens } from "./fernShiki"; import { @@ -19,40 +25,20 @@ export interface ScrollToHandle { scrollHeight: number; } -export interface FernSyntaxHighlighterTokensProps { +export interface FernSyntaxHighlighterTokensProps + extends ComponentPropsWithoutRef<"pre"> { tokens: HighlightedTokens; fontSize?: "sm" | "base" | "lg"; highlightLines?: HighlightLine[]; highlightStyle?: "highlight" | "focus"; - - className?: string; - style?: React.CSSProperties; viewportRef?: React.RefObject; maxLines?: number; wordWrap?: boolean; } -export function fernSyntaxHighlighterTokenPropsAreEqual( - prevProps: FernSyntaxHighlighterTokensProps, - nextProps: FernSyntaxHighlighterTokensProps -): boolean { - return ( - isEqual(prevProps.highlightLines, nextProps.highlightLines) && - isEqual(prevProps.style, nextProps.style) && - prevProps.fontSize === nextProps.fontSize && - prevProps.highlightStyle === nextProps.highlightStyle && - prevProps.className === nextProps.className && - prevProps.maxLines === nextProps.maxLines && - prevProps.tokens === nextProps.tokens && - prevProps.wordWrap === nextProps.wordWrap - ); -} - export const FernSyntaxHighlighterTokens = memo( forwardRef((props, ref) => { const { - className, - style, fontSize = "base", highlightLines, highlightStyle, @@ -60,6 +46,7 @@ export const FernSyntaxHighlighterTokens = memo( tokens, maxLines, wordWrap, + ...preProps } = props; const scrollAreaRef = useRef(null); @@ -130,14 +117,16 @@ export const FernSyntaxHighlighterTokens = memo( return (
         
           
-            
- 0, - "word-wrap": wordWrap, - })} - > - {!plaintext && ( - - - - - )} - - {lines.map((line, lineNumber) => ( - - {!plaintext && ( - - )} - + + ))} + +
- - {gutterCli - ? lineNumber === 0 - ? "$" - : ">" - : lineNumber + 1} - - - + 0, + "word-wrap": wordWrap, + })} + > + {!plaintext && ( + + + + + )} + + {lines.map((line, lineNumber) => ( + + {!plaintext && ( + - - ))} - -
+ + {gutterCli + ? lineNumber === 0 + ? "$" + : ">" + : lineNumber + 1} +
- + )} +
+ +
); - }), - fernSyntaxHighlighterTokenPropsAreEqual + }) ); FernSyntaxHighlighterTokens.displayName = "FernSyntaxHighlighterTokens"; diff --git a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokensVirtualized.tsx b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokensVirtualized.tsx index eedd410600..5a3573a1ea 100644 --- a/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokensVirtualized.tsx +++ b/packages/fern-docs/syntax-highlighter/src/FernSyntaxHighlighterTokensVirtualized.tsx @@ -15,7 +15,6 @@ import { ItemProps, TableVirtuoso, TableVirtuosoHandle } from "react-virtuoso"; import { FernSyntaxHighlighterTokensProps, ScrollToHandle, - fernSyntaxHighlighterTokenPropsAreEqual, } from "./FernSyntaxHighlighterTokens"; import { HastToJSX } from "./HastToJsx"; import { flattenHighlightLines, getLineHeight, getMaxHeight } from "./utils"; @@ -46,25 +45,23 @@ const CodeBlockTable = forwardRef< "text-base": fontSize === "lg", })} > -
- 0, - "word-wrap": context?.wordWrap, - })} - {...props} - ref={ref} - > - {!plaintext && ( - - - - - )} - {children} -
-
+ 0, + "word-wrap": context?.wordWrap, + })} + {...props} + ref={ref} + > + {!plaintext && ( + + + + + )} + {children} +
); }); @@ -227,8 +224,7 @@ export const FernSyntaxHighlighterTokensVirtualized = memo( /> ); - }), - fernSyntaxHighlighterTokenPropsAreEqual + }) ); FernSyntaxHighlighterTokensVirtualized.displayName = diff --git a/packages/fern-docs/syntax-highlighter/src/index.scss b/packages/fern-docs/syntax-highlighter/src/index.scss index edd67c1baf..9a3b7d0fc8 100644 --- a/packages/fern-docs/syntax-highlighter/src/index.scss +++ b/packages/fern-docs/syntax-highlighter/src/index.scss @@ -14,18 +14,18 @@ @apply min-h-0 shrink; } + .code-block { + @apply py-3 font-mono; + } + .code-block, .code-block.text-sm, .code-block.text-xs, .code-block.text-base { - @apply font-mono leading-relaxed; - } - - .code-block-inner { - @apply py-3; + @apply leading-relaxed; } - .code-block.text-xs > .code-block-inner { + .code-block.text-xs { @apply py-2; }