@@ -21,24 +21,24 @@ marked.use(
2121
2222export function processNestedCodeBlocks ( content : string ) {
2323 if ( content . split ( '```' ) . length < 3 ) {
24- return { processedContent : content , fences : [ ] } ;
24+ return { processedContent : content , langtags : [ ] } ;
2525 }
2626
2727 const lines = content . split ( '\n' ) ;
2828 const stack : string [ ] = [ ] ;
2929 let result = '' ;
3030 let currentBlock : string [ ] = [ ] ;
31- const fences : string [ ] = [ ] ;
31+ const langtags : string [ ] = [ ] ;
3232
3333 for ( const line of lines ) {
3434 const strippedLine = line . trim ( ) ;
3535 if ( strippedLine . startsWith ( '```' ) ) {
3636 const lang = strippedLine . slice ( 3 ) ;
37+ langtags . push ( lang ) ;
3738 if ( stack . length === 0 ) {
3839 const remainingContent = lines . slice ( lines . indexOf ( line ) + 1 ) . join ( '\n' ) ;
3940 if ( remainingContent . includes ( '```' ) && remainingContent . split ( '```' ) . length > 2 ) {
4041 stack . push ( lang ) ;
41- fences . push ( lang ) ;
4242 result += '~~~' + lang + '\n' ;
4343 } else {
4444 result += line + '\n' ;
@@ -64,7 +64,7 @@ export function processNestedCodeBlocks(content: string) {
6464
6565 return {
6666 processedContent : result . trim ( ) ,
67- fences
67+ langtags
6868 } ;
6969}
7070
@@ -82,7 +82,7 @@ export function transformThinkingTags(content: string) {
8282
8383export function parseMarkdownContent ( content : string ) {
8484 const processedContent = transformThinkingTags ( content ) ;
85- const { processedContent : transformedContent , fences } = processNestedCodeBlocks ( processedContent ) ;
85+ const { processedContent : transformedContent , langtags } = processNestedCodeBlocks ( processedContent ) ;
8686
8787 let parsedResult = marked . parse ( transformedContent , {
8888 async : false ,
@@ -91,13 +91,12 @@ export function parseMarkdownContent(content: string) {
9191 parsedResult = parsedResult . replace (
9292 / < p r e > < c o d e (?: \s + c l a s s = " ( [ ^ " ] + ) " ) ? > ( [ ^ ] * ?) < \/ c o d e > < \/ p r e > / g,
9393 ( _ , classes = "" , code ) => {
94- const langtag = ( ( classes || "" ) . split ( " " ) [ 1 ] || "Code" ) . replace ( "language-" , "" ) ;
95- const args = fences ?. shift ( ) || "" ;
96-
94+ const langtag_fallback = ( ( classes || "" ) . split ( " " ) [ 1 ] || "Code" ) . replace ( "language-" , "" ) ;
95+ const langtag = langtags ?. shift ( ) || langtag_fallback ;
9796 const emoji = getCodeBlockEmoji ( langtag ) ;
9897 return `
9998 <details>
100- <summary>${ emoji } ${ args || langtag } </summary>
99+ <summary>${ emoji } ${ langtag } </summary>
101100 <pre><code class="${ classes } ">${ code } </code></pre>
102101 </details>
103102 ` ;
@@ -120,13 +119,13 @@ function isPath(langtag: string): boolean {
120119}
121120
122121function isTool ( langtag : string ) : boolean {
123- return [ "ipython" , "shell" ] . includes ( langtag . split ( " " ) [ 0 ] ) ;
122+ return [ "ipython" , "shell" , "tmux" ] . includes ( langtag . split ( " " ) [ 0 ] . toLowerCase ( ) ) ;
124123}
125124
126125function isOutput ( langtag : string ) : boolean {
127126 return [ "stdout" , "stderr" , "result" ] . includes ( langtag . toLowerCase ( ) ) ;
128127}
129128
130129function isWrite ( langtag : string ) : boolean {
131- return [ "save" , "patch" , "append" ] . includes ( langtag . toLowerCase ( ) ) ;
130+ return [ "save" , "patch" , "append" ] . includes ( langtag . split ( " " ) [ 0 ] . toLowerCase ( ) ) ;
132131}
0 commit comments