@@ -6,6 +6,7 @@ import MudClient from "../client";
66import ReactDOMServer from "react-dom/server" ;
77import DOMPurify from 'dompurify' ;
88import { setInputText } from '../InputStore' ;
9+ import TurndownService from 'turndown' ; // <-- Import TurndownService
910
1011interface Props {
1112 client : MudClient ;
@@ -26,6 +27,8 @@ class Output extends React.Component<Props, State> {
2627 static MAX_OUTPUT_LENGTH = 7500 ; // Maximum number of messages to display in the output
2728 static LOCAL_STORAGE_KEY = "outputLog" ; // Key for saving output in LocalStorage
2829 messageKey : number = 0 ;
30+ // Add a TurndownService instance (can be reused)
31+ turndownService = new TurndownService ( { headingStyle : 'atx' , emDelimiter : '*' } ) ;
2932
3033 constructor ( props : Props ) {
3134 super ( props ) ;
@@ -258,8 +261,20 @@ scrollToBottom = () => { const output = this.outputRef.current; if (output) {
258261 if ( buttonInClone ) {
259262 buttonInClone . remove ( ) ;
260263 }
261- // Get text content from the clone, which now excludes the button text
262- const textToCopy = clonedBlockquote . textContent || '' ;
264+
265+ let textToCopy : string ;
266+ const contentType = blockquote . dataset . contentType ; // Check for data-content-type
267+
268+ // Check if the content type is markdown
269+ if ( contentType === 'text/markdown' ) {
270+ // Get the inner HTML of the clone (without the button)
271+ const htmlContent = clonedBlockquote . innerHTML ;
272+ // Convert HTML to Markdown using Turndown
273+ textToCopy = this . turndownService . turndown ( htmlContent ) ;
274+ } else {
275+ // Default behavior: Get text content from the clone
276+ textToCopy = clonedBlockquote . textContent || '' ;
277+ }
263278
264279 navigator . clipboard . writeText ( textToCopy . trim ( ) )
265280 . then ( ( ) => {
0 commit comments