diff --git a/src/modules/blocks/AutoBlocksRenderer.tsx b/src/modules/blocks/AutoBlocksRenderer.tsx
index affac99b7..3dfd1dc2d 100644
--- a/src/modules/blocks/AutoBlocksRenderer.tsx
+++ b/src/modules/blocks/AutoBlocksRenderer.tsx
@@ -15,7 +15,7 @@ import { RenderPlainChatText } from '~/modules/blocks/plaintext/RenderPlainChatT
import { RenderCode, RenderCodeMemo } from './code/RenderCode';
import { RenderMarkdown, RenderMarkdownMemo } from './markdown/RenderMarkdown';
import { RenderTextDiff } from './textdiff/RenderTextDiff';
-import { heuristicIsBlockTextHTML, RenderHtmlResponse } from './html/RenderHtmlResponse';
+import { heuristicIsBlockPureHTML, RenderHtmlResponse } from './html/RenderHtmlResponse';
import { heuristicLegacyImageBlocks, heuristicMarkdownImageReferenceBlocks, RenderImageURL } from './image/RenderImageURL';
@@ -50,7 +50,7 @@ function parseBlocksFromText(text: string, disableParsing: boolean, forceTextDif
return [{ type: 'diffb', textDiffs: forceTextDiffs }];
// special case: this could be generated by a proxy that returns an HTML page instead of the API response
- if (heuristicIsBlockTextHTML(text))
+ if (heuristicIsBlockPureHTML(text))
return [{ type: 'htmlb', html: text }];
// special case: markdown image references (e.g. )
diff --git a/src/modules/blocks/code/RenderCode.tsx b/src/modules/blocks/code/RenderCode.tsx
index 25d100595..64109f3a7 100644
--- a/src/modules/blocks/code/RenderCode.tsx
+++ b/src/modules/blocks/code/RenderCode.tsx
@@ -18,19 +18,23 @@ import type { CodeBlock } from '../blocks.types';
import { ButtonCodePen, isCodePenSupported } from './ButtonCodePen';
import { ButtonJsFiddle, isJSFiddleSupported } from './ButtonJSFiddle';
import { ButtonStackBlitz, isStackBlitzSupported } from './ButtonStackBlitz';
+import { OverlayButton, overlayButtonsActiveSx, overlayButtonsClassName, overlayButtonsSx } from '../OverlayButton';
import { RenderCodeHtmlIFrame } from './RenderCodeHtmlIFrame';
import { RenderCodeMermaid } from './RenderCodeMermaid';
-import { RenderCodePlantUML, usePlantUmlSvg } from './RenderCodePlantUML';
import { RenderCodeSVG } from './RenderCodeSVG';
import { RenderCodeSyntax } from './RenderCodeSyntax';
-import { heuristicIsBlockTextHTML } from '../html/RenderHtmlResponse';
+import { heuristicIsBlockPlantUML, RenderCodePlantUML, usePlantUmlSvg } from './RenderCodePlantUML';
+import { heuristicIsBlockPureHTML } from '../html/RenderHtmlResponse';
// style for line-numbers
import './RenderCode.css';
-import { OverlayButton, overlayButtonsActiveSx, overlayButtonsClassName, overlayButtonsSx } from '~/modules/blocks/OverlayButton';
+// RenderCode
+
+export const RenderCodeMemo = React.memo(RenderCode);
+
interface RenderCodeBaseProps {
codeBlock: CodeBlock,
fitScreen?: boolean,
@@ -40,12 +44,33 @@ interface RenderCodeBaseProps {
sx?: SxProps,
}
-interface RenderCodeImplProps extends RenderCodeBaseProps {
- highlightCode: (inferredCodeLanguage: string | null, blockCode: string, addLineNumbers: boolean) => string,
- inferCodeLanguage: (blockTitle: string, code: string) => string | null,
+export function RenderCode(props: RenderCodeBaseProps) {
+ return (
+ }>
+ <_DynamicPrism {...props} />
+
+ );
}
-function RenderCodeImpl(props: RenderCodeImplProps) {
+
+// Lazy loader of the heavy prism functions
+const _DynamicPrism = React.lazy(async () => {
+
+ // Dynamically import the code highlight functions
+ const { highlightCode, inferCodeLanguage } = await import('./codePrism');
+
+ return {
+ default: (props: RenderCodeBaseProps) => ,
+ };
+});
+
+
+//
+
+function RenderCodeImpl(props: RenderCodeBaseProps & {
+ highlightCode: (inferredCodeLanguage: string | null, blockCode: string, addLineNumbers: boolean) => string,
+ inferCodeLanguage: (blockTitle: string, code: string) => string | null,
+}) {
// state
const [fitScreen, setFitScreen] = React.useState(!!props.fitScreen);
@@ -67,33 +92,28 @@ function RenderCodeImpl(props: RenderCodeImplProps) {
optimizeLightweight,
} = props;
+
// heuristics for specialized rendering
- const isHTML = heuristicIsBlockTextHTML(blockCode);
- const renderHTML = isHTML && showHTML;
+ const isHTMLCode = heuristicIsBlockPureHTML(blockCode);
+ const renderHTML = isHTMLCode && showHTML;
- const isMermaid = blockTitle === 'mermaid' && blockComplete;
- const renderMermaid = isMermaid && showMermaid;
+ const isMermaidCode = blockTitle === 'mermaid' && blockComplete;
+ const renderMermaid = isMermaidCode && showMermaid;
- const isPlantUML =
- (blockCode.startsWith('@startuml') && blockCode.endsWith('@enduml'))
- || (blockCode.startsWith('@startmindmap') && blockCode.endsWith('@endmindmap'))
- || (blockCode.startsWith('@startsalt') && blockCode.endsWith('@endsalt'))
- || (blockCode.startsWith('@startwbs') && blockCode.endsWith('@endwbs'))
- || (blockCode.startsWith('@startgantt') && blockCode.endsWith('@endgantt'));
-
- let renderPlantUML = isPlantUML && showPlantUML;
+ const isPlantUMLCode = heuristicIsBlockPlantUML(blockCode);
+ let renderPlantUML = isPlantUMLCode && showPlantUML;
const { data: plantUmlSvgData, error: plantUmlError } = usePlantUmlSvg(renderPlantUML, blockCode);
renderPlantUML = renderPlantUML && (!!plantUmlSvgData || !!plantUmlError);
- const isSVG = (blockCode.startsWith('