diff --git a/client/src/plus/ai-help/index.scss b/client/src/plus/ai-help/index.scss index 4cdc4a69c807..55356d7ea96d 100644 --- a/client/src/plus/ai-help/index.scss +++ b/client/src/plus/ai-help/index.scss @@ -219,10 +219,11 @@ &.status-pending .ai-help-message-content, &.status-in-progress .ai-help-message-content { &.empty::after, - > :not(ol):not(ul):not(pre):last-child:after, + > :not(ol):not(ul):not(pre):not(div.code-example):last-child:after, > ol:last-child li:last-child:after, > pre:last-child code:after, - > ul:last-child li:last-child:after { + > ul:last-child li:last-child:after, + > div.code-example:last-child pre:last-child code:after { animation: blink 1s steps(5, start) infinite; content: "▋"; margin-left: 0.25rem; @@ -270,6 +271,10 @@ &:last-child { margin-bottom: 0; } + + &.example-header { + margin-bottom: 0; + } } ul, diff --git a/client/src/plus/ai-help/index.tsx b/client/src/plus/ai-help/index.tsx index 44bf164bdf31..9aba2c93dc24 100644 --- a/client/src/plus/ai-help/index.tsx +++ b/client/src/plus/ai-help/index.tsx @@ -1,4 +1,12 @@ -import { MutableRefObject, useEffect, useRef, useState } from "react"; +import Prism from "prismjs"; +import { + Children, + MutableRefObject, + ReactElement, + useEffect, + useRef, + useState, +} from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; @@ -220,6 +228,57 @@ export function AIHelpInner() { // eslint-disable-next-line jsx-a11y/anchor-has-content return ; }, + pre: ({ node, className, children, ...props }) => { + const code = Children.toArray(children) + .map( + (child) => + /language-(\w+)/.exec( + (child as ReactElement)?.props?.className || + "" + )?.[1] + ) + .find(Boolean); + + if (!code) { + return ( +
+                                  {children}
+                                
+ ); + } + return ( +
+

+ {code} +

+
+                                  {children}
+                                
+
+ ); + }, + code: ({ inline, className, children, ...props }) => { + const match = /language-(\w+)/.exec( + className || "" + ); + const lang = Prism.languages[match?.[1]]; + return !inline && lang ? ( + + ) : ( + + {children} + + ); + }, }} > {message.content.replace(SORRY_BACKEND, SORRY_FRONTEND)}