{
- // This ensures the language definitions are loaded
Promise.all([
//@ts-ignore
import("prismjs/components/prism-json"),
@@ -434,16 +473,23 @@ function HighlightCode({
]).then(() => setIsLoaded(true));
}, []);
+ const containerClasses = cn(
+ "px-3 py-3 scrollbar-thin scrollbar-track-transparent scrollbar-thumb-charcoal-600",
+ !isWrapped && "overflow-x-auto",
+ isWrapped && "overflow-y-auto",
+ className
+ );
+
+ const preClasses = cn(
+ "relative mr-2 font-mono leading-relaxed",
+ preClassName,
+ isWrapped && "[&_span]:whitespace-pre-wrap [&_span]:break-words"
+ );
+
if (!isLoaded) {
return (
-
-
{code}
+
);
}
@@ -457,22 +503,8 @@ function HighlightCode({
getLineProps,
getTokenProps,
}) => (
-
-
+
+
{tokens
.map((line, index) => {
if (index === tokens.length - 1 && line.length === 1 && line[0].content === "\n") {
@@ -495,7 +527,8 @@ function HighlightCode({
{...lineProps}
className={cn(
"flex w-full justify-start transition-opacity duration-500",
- lineProps.className
+ lineProps.className,
+ isWrapped && "flex-wrap"
)}
style={{
opacity: shouldDim ? dimAmount : undefined,
@@ -504,9 +537,10 @@ function HighlightCode({
>
{showLineNumbers && (
);
}