diff --git a/apps/frontend/components/shared/pt.blocks/CodeSnippet.tsx b/apps/frontend/components/shared/pt.blocks/CodeSnippet.tsx index 8fbb4c5b0..a57ba22a5 100644 --- a/apps/frontend/components/shared/pt.blocks/CodeSnippet.tsx +++ b/apps/frontend/components/shared/pt.blocks/CodeSnippet.tsx @@ -3,17 +3,11 @@ import theme from "@/styles/codeSnippetTheme"; import type { CodeBlockProps } from "@/types/object.types"; import clsx from "clsx"; import { cx } from "cva"; -import { Inconsolata } from "next/font/google"; +import { GeistMono } from "geist/font/mono"; import { Highlight, Prism } from "prism-react-renderer"; -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import Icon from "../Icon"; -const inconsolata = Inconsolata({ - subsets: ["latin"], - weight: "400", - variable: "--inconsolata", -}); - export function CodeSnippet(props: { code: CodeBlockProps }) { const [copied, setCopied] = useState(false); const [isHighlighted, setIsHighlighted] = useState(false); @@ -32,6 +26,19 @@ export function CodeSnippet(props: { code: CodeBlockProps }) { }, 1200); }; + const getLineNumWidth = useMemo(() => { + return ( + 0.5 + // Start with a base value + props.code?.code + ?.trim() + .split(/\r\n|\r|\n/) // Split by newlines + .length // Get number of lines + .toString().length * // Get number of digits + // Reduce by 30% + 0.7 + ); + }, [props.code?.code]); + useEffect(() => { (async () => { if (prismLanguageId) { @@ -49,14 +56,14 @@ export function CodeSnippet(props: { code: CodeBlockProps }) { return (
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: