@@ -5,7 +5,7 @@ import { getSafeLocalStorage } from "../../local-storage.ts";
55import type { AssistantIdentity } from "../assistant-identity.ts" ;
66import type { EmbedSandboxMode } from "../embed-sandbox.ts" ;
77import { icons } from "../icons.ts" ;
8- import { toSanitizedMarkdownHtml } from "../markdown.ts" ;
8+ import { toSanitizedMarkdownHtml , toStreamingPlainTextHtml } from "../markdown.ts" ;
99import { openExternalUrlSafe } from "../open-external-url.ts" ;
1010import type { SidebarContent } from "../sidebar-content.ts" ;
1111import { detectTextDirection } from "../text-direction.ts" ;
@@ -1813,11 +1813,7 @@ function renderGroupedMessage(
18131813 < pre class ="chat-json-content "> < code > ${ jsonResult . pretty } </ code > </ pre >
18141814 </ details > `
18151815 : markdown
1816- ? html `< div class ="chat-text " dir ="${ detectTextDirection ( markdown ) } ">
1817- ${ unsafeHTML (
1818- toSanitizedMarkdownHtml ( markdown , markdownRenderOptions ) ,
1819- ) }
1820- </ div > `
1816+ ? renderMarkdownText ( markdown , opts . isStreaming , markdownRenderOptions )
18211817 : nothing }
18221818 ${ hasToolCards
18231819 ? singleToolCard && ! markdown && ! hasImages
@@ -1880,9 +1876,7 @@ function renderGroupedMessage(
18801876 < pre class ="chat-json-content "> < code > ${ jsonResult . pretty } </ code > </ pre >
18811877 </ details > `
18821878 : markdown
1883- ? html `< div class ="chat-text " dir ="${ detectTextDirection ( markdown ) } ">
1884- ${ unsafeHTML ( toSanitizedMarkdownHtml ( markdown , markdownRenderOptions ) ) }
1885- </ div > `
1879+ ? renderMarkdownText ( markdown , opts . isStreaming , markdownRenderOptions )
18861880 : nothing }
18871881 ${ hasToolCards
18881882 ? renderInlineToolCards ( toolCards , {
@@ -1910,3 +1904,22 @@ function renderGroupedMessage(
19101904 </ div >
19111905 ` ;
19121906}
1907+
1908+ function renderMarkdownText (
1909+ markdown : string ,
1910+ isStreaming : boolean ,
1911+ markdownRenderOptions ?: { codeBlockChrome : "copy" | "none" } ,
1912+ ) {
1913+ if ( isStreaming ) {
1914+ return html `
1915+ < div class ="chat-text " dir ="${ detectTextDirection ( markdown ) } ">
1916+ ${ unsafeHTML ( toStreamingPlainTextHtml ( markdown ) ) }
1917+ </ div >
1918+ ` ;
1919+ }
1920+ return html `
1921+ < div class ="chat-text " dir ="${ detectTextDirection ( markdown ) } ">
1922+ ${ unsafeHTML ( toSanitizedMarkdownHtml ( markdown , markdownRenderOptions ) ) }
1923+ </ div >
1924+ ` ;
1925+ }
0 commit comments