diff --git a/frontend/app/element/markdown.less b/frontend/app/element/markdown.less index c41b9bedc..df7b1e36d 100644 --- a/frontend/app/element/markdown.less +++ b/frontend/app/element/markdown.less @@ -7,6 +7,7 @@ overflow: hidden; height: 100%; width: 100%; + .content { height: 100%; width: 100%; @@ -17,6 +18,10 @@ font-size: 14px; overflow-wrap: break-word; + &.non-scrollable { + overflow: hidden; + } + .heading { &:first-of-type { margin-top: 0 !important; diff --git a/frontend/app/element/markdown.tsx b/frontend/app/element/markdown.tsx index 1f1d64689..ad7a64611 100644 --- a/frontend/app/element/markdown.tsx +++ b/frontend/app/element/markdown.tsx @@ -178,9 +178,19 @@ type MarkdownProps = { className?: string; onClickExecute?: (cmd: string) => void; resolveOpts?: MarkdownResolveOpts; + scrollable?: boolean; }; -const Markdown = ({ text, textAtom, showTocAtom, style, className, resolveOpts, onClickExecute }: MarkdownProps) => { +const Markdown = ({ + text, + textAtom, + showTocAtom, + style, + className, + resolveOpts, + scrollable = true, + onClickExecute, +}: MarkdownProps) => { const textAtomValue = useAtomValueSafe(textAtom); const tocRef = useRef([]); const showToc = useAtomValueSafe(showTocAtom) ?? false; @@ -240,8 +250,8 @@ const Markdown = ({ text, textAtom, showTocAtom, style, className, resolveOpts, text = textAtomValue ?? text; - return ( -
+ const ScrollableMarkdown = () => { + return ( + ); + }; + + const NonScrollableMarkdown = () => { + return ( +
+ + rehypeSanitize({ + ...defaultSchema, + attributes: { + ...defaultSchema.attributes, + span: [ + ...(defaultSchema.attributes?.span || []), + // Allow all class names starting with `hljs-`. + ["className", /^hljs-./], + // Alternatively, to allow only certain class names: + // ['className', 'hljs-number', 'hljs-title', 'hljs-variable'] + ], + }, + tagNames: [...(defaultSchema.tagNames || []), "span"], + }), + () => rehypeSlug({ prefix: idPrefix }), + ]} + components={markdownComponents} + > + {text} + +
+ ); + }; + + return ( +
+ {scrollable ? : } {toc && (
diff --git a/frontend/app/view/waveai/waveai.tsx b/frontend/app/view/waveai/waveai.tsx index 222a075a0..401995486 100644 --- a/frontend/app/view/waveai/waveai.tsx +++ b/frontend/app/view/waveai/waveai.tsx @@ -14,7 +14,6 @@ import { atom, Atom, PrimitiveAtom, useAtomValue, useSetAtom, WritableAtom } fro import type { OverlayScrollbars } from "overlayscrollbars"; import { OverlayScrollbarsComponent, OverlayScrollbarsComponentRef } from "overlayscrollbars-react"; import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react"; -import tinycolor from "tinycolor2"; import "./waveai.less"; interface ChatMessageType { @@ -263,11 +262,8 @@ function makeWaveAiViewModel(blockId): WaveAiModel { const ChatItem = ({ chatItem }: ChatItemProps) => { const { isAssistant, text, isError } = chatItem; - const senderClassName = isAssistant ? "chat-msg-assistant" : "chat-msg-user"; - const msgClassName = `chat-msg ${senderClassName}`; const cssVar = "--panel-bg-color"; const panelBgColor = getComputedStyle(document.documentElement).getPropertyValue(cssVar).trim(); - const color = tinycolor(panelBgColor); const renderError = (err: string): React.JSX.Element =>
{err}
; @@ -284,7 +280,7 @@ const ChatItem = ({ chatItem }: ChatItemProps) => {
- +
) : ( @@ -299,7 +295,7 @@ const ChatItem = ({ chatItem }: ChatItemProps) => { return ( <>
- +
);