22import DOMPurify from "dompurify" ;
33import React from "react" ;
44import { BotIcon } from "./botIcon" ;
5+ import { DownloadIcon } from "./downloadIcon" ;
6+ import { downloadAsMarkdown } from "../utils/downloadMarkdown" ;
57import { IParseURL , parseUrl } from "../utils/parseUrl" ;
68import UrlCardList from "./urlCardList" ;
79
810interface CodeBlockProps {
911 language ?: string ;
1012 content : string ;
11- isLoading ?: boolean ;
1213}
1314
1415export const BotMessage : React . FC < CodeBlockProps > = ( { language, content } ) => {
@@ -18,6 +19,19 @@ export const BotMessage: React.FC<CodeBlockProps> = ({ language, content }) => {
1819 if ( sanitizedContent . includes ( "favicon" ) ) {
1920 parsedUrls = parseUrl ( sanitizedContent ) ;
2021 }
22+
23+ const handleDownload = ( ) => {
24+ console . log ( "Download button clicked" ) ;
25+ console . log ( "Content length:" , sanitizedContent . length ) ;
26+ console . log ( "Content preview:" , sanitizedContent . substring ( 0 , 100 ) ) ;
27+
28+ const timestamp = new Date ( ) . toISOString ( ) . slice ( 0 , 19 ) . replace ( / : / g, "-" ) ;
29+ const filename = `codebuddy-response-${ timestamp } ` ;
30+ console . log ( "Filename:" , filename ) ;
31+
32+ downloadAsMarkdown ( sanitizedContent , filename ) ;
33+ } ;
34+
2135 return (
2236 < >
2337 { content . includes ( "thinking" ) ? (
@@ -30,6 +44,9 @@ export const BotMessage: React.FC<CodeBlockProps> = ({ language, content }) => {
3044 < div className = "code-block" >
3145 < div className = "code-header" >
3246 < span className = "language-label" > { language } </ span >
47+ < div className = "header-buttons" >
48+ < DownloadIcon onClick = { handleDownload } />
49+ </ div >
3350 </ div >
3451 { parsedUrls . length > 0 ? (
3552 < div className = "doc-content" >
0 commit comments