File tree Expand file tree Collapse file tree
components/chat/Messages/Markdown Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 import fileSaver from ' file-saver' ;
77 const { saveAs } = fileSaver ;
88
9- import { marked , type Token } from ' marked' ;
9+ import { type Token } from ' marked' ;
1010 import { copyToClipboard , unescapeHtml } from ' $lib/utils' ;
1111
1212 import { WEBUI_BASE_URL } from ' $lib/constants' ;
399399 <div class =" mb-1.5" slot =" content" >
400400 <svelte:self
401401 id ={` ${id }-${tokenIdx }-${detailIdx }-d ` }
402- tokens ={marked . lexer ( decode ( detailToken .text )) }
402+ tokens ={detailToken .tokens ?? [] }
403403 attributes ={detailToken ?.attributes }
404404 {done }
405405 {editCodeBlock }
447447 <div class =" mb-1.5" slot =" content" >
448448 <svelte:self
449449 id ={` ${id }-${tokenIdx }-d ` }
450- tokens ={marked . lexer ( decode ( token .text )) }
450+ tokens ={token .tokens ?? [] }
451451 attributes ={token ?.attributes }
452452 {done }
453453 {editCodeBlock }
Original file line number Diff line number Diff line change 1+ import { decode } from 'html-entities' ;
2+ import { type TokenizerThis } from 'marked' ;
3+
14// Helper function to find matching closing tag
25function findMatchingClosingTag ( src : string , openTag : string , closeTag : string ) : number {
36 let depth = 1 ;
@@ -26,7 +29,7 @@ function parseAttributes(tag: string): { [key: string]: string } {
2629 return attributes ;
2730}
2831
29- function detailsTokenizer ( src : string ) {
32+ function detailsTokenizer ( this : TokenizerThis , src : string ) {
3033 // Updated regex to capture attributes inside <details>
3134 const detailsRegex = / ^ < d e t a i l s ( \s + [ ^ > ] * ) ? > \n / ;
3235 const summaryRegex = / ^ < s u m m a r y > ( .* ?) < \/ s u m m a r y > \n / ;
@@ -49,11 +52,17 @@ function detailsTokenizer(src: string) {
4952 content = content . slice ( summaryMatch [ 0 ] . length ) . trim ( ) ;
5053 }
5154
55+ const tokens : any [ ] = [ ] ;
56+ if ( attributes ?. type !== 'tool_calls' ) {
57+ this . lexer . blockTokens ( decode ( content ) , tokens ) ;
58+ }
59+
5260 return {
5361 type : 'details' ,
5462 raw : fullMatch ,
5563 summary : summary ,
5664 text : content ,
65+ tokens,
5766 attributes : attributes // Include extracted attributes from <details>
5867 } ;
5968 }
@@ -89,6 +98,6 @@ function detailsExtension() {
8998
9099export default function ( options = { } ) {
91100 return {
92- extensions : [ detailsExtension ( options ) ]
101+ extensions : [ detailsExtension ( ) ]
93102 } ;
94103}
You can’t perform that action at this time.
0 commit comments