@@ -76,45 +76,36 @@ function streamMessage(cssClass, text) {
7676 msg . classList . add ( "message" , cssClass ) ;
7777 chat . appendChild ( msg ) ;
7878
79- // Detecteer genummerde lijst zoals: 1. tekst 2. tekst 3. tekst
80- const numberedPattern = / (?: ^ | \s ) ( \d + ) \. \s + ( [ ^ 0 - 9 \. \n ] + ) / g;
81- let numberedMatches = [ ...text . matchAll ( numberedPattern ) ] ;
82-
83- // Detecteer bulletlijst zoals: - tekst of • tekst
84- const bulletPattern = / (?: ^ | \s ) [ \- • * ] \s + ( [ ^ \n ] + ) / g;
85- let bulletMatches = [ ...text . matchAll ( bulletPattern ) ] ;
86-
87- if ( numberedMatches . length >= 2 ) {
88- const list = document . createElement ( "ol" ) ;
89- numberedMatches . forEach ( match => {
90- const li = document . createElement ( "li" ) ;
91- li . textContent = match [ 2 ] . trim ( ) ;
92- list . appendChild ( li ) ;
93- } ) ;
94- msg . appendChild ( list ) ;
95- return ;
96- }
97-
98- if ( bulletMatches . length >= 2 ) {
99- const list = document . createElement ( "ul" ) ;
100- bulletMatches . forEach ( match => {
101- const li = document . createElement ( "li" ) ;
102- li . textContent = match [ 1 ] . trim ( ) ;
103- list . appendChild ( li ) ;
104- } ) ;
105- msg . appendChild ( list ) ;
106- return ;
79+ const lines = text . split ( "\n" ) . filter ( line => line . trim ( ) !== "" ) ;
80+
81+ const isNumberedList = lines . length > 1 && lines . every ( line => / ^ \d + \. \s + / . test ( line . trim ( ) ) ) ;
82+ const isBulletedList = lines . length > 1 && lines . every ( line => / ^ [ - * • ] \s + / . test ( line . trim ( ) ) ) ;
83+
84+ if ( isNumberedList || isBulletedList ) {
85+ const listElement = document . createElement ( isNumberedList ? "ol" : "ul" ) ;
86+ msg . appendChild ( listElement ) ;
87+ let i = 0 ;
88+
89+ const interval = setInterval ( ( ) => {
90+ if ( i < lines . length ) {
91+ const li = document . createElement ( "li" ) ;
92+ li . textContent = lines [ i ] . replace ( / ^ ( \d + \. \s + | [ - * • ] \s + ) / , "" ) . trim ( ) ;
93+ listElement . appendChild ( li ) ;
94+ chat . scrollTop = chat . scrollHeight ;
95+ i ++ ;
96+ } else {
97+ clearInterval ( interval ) ;
98+ }
99+ } , 200 ) ;
100+ } else {
101+ let index = 0 ;
102+ const interval = setInterval ( ( ) => {
103+ if ( index < text . length ) {
104+ msg . textContent += text . charAt ( index ++ ) ;
105+ chat . scrollTop = chat . scrollHeight ;
106+ } else {
107+ clearInterval ( interval ) ;
108+ }
109+ } , 15 ) ;
107110 }
108-
109- // Geen lijst → toon als streaming tekst
110- let index = 0 ;
111- msg . textContent = "" ;
112- const interval = setInterval ( ( ) => {
113- if ( index < text . length ) {
114- msg . textContent += text . charAt ( index ++ ) ;
115- chat . scrollTop = chat . scrollHeight ;
116- } else {
117- clearInterval ( interval ) ;
118- }
119- } , 15 ) ;
120111}
0 commit comments