Mercurial Hosting > lang
comparison src/site.js @ 34:0fb3488a017d
show_text
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Mon, 04 Aug 2025 23:06:19 -0600 |
| parents | 1e7d855afde3 |
| children | d72b1dff01c9 |
comparison
equal
deleted
inserted
replaced
| 33:7d9462ea03e3 | 34:0fb3488a017d |
|---|---|
| 129 let divs = document.querySelectorAll('[markdown]'); | 129 let divs = document.querySelectorAll('[markdown]'); |
| 130 for( let div of divs ) { | 130 for( let div of divs ) { |
| 131 let text = div.textContent; | 131 let text = div.textContent; |
| 132 text = text.replace(/\{([^|}]+)\|([^|}]+)\}/g, '<ruby>$1<rt>$2</rt></ruby>'); | 132 text = text.replace(/\{([^|}]+)\|([^|}]+)\}/g, '<ruby>$1<rt>$2</rt></ruby>'); |
| 133 text = converter.render(text); | 133 text = converter.render(text); |
| 134 if( lang && div.getAttribute('role')==='assistant' ) { | 134 div.innerHTML = text; |
| 135 div.removeAttribute('markdown'); | |
| 136 let parent = div.parentNode; | |
| 137 if( parent.getAttribute('role')==='assistant' ) { | |
| 135 mdDiv.innerHTML = text; | 138 mdDiv.innerHTML = text; |
| 136 let rts = mdDiv.querySelectorAll('rt'); | 139 let rts = mdDiv.querySelectorAll('rt'); |
| 137 for( let rt of rts ) { | 140 for( let rt of rts ) { |
| 138 rt.remove(); | 141 rt.remove(); |
| 139 } | 142 } |
| 140 //console.log(mdDiv.textContent); | 143 //console.log(mdDiv.textContent); |
| 141 text += `\n<p><audio controls preload=none src="/tts.mp3?lang=${lang}&voice=${voice}&text=${encodeURIComponent(mdDiv.textContent)}"></audio></p>\n`; | 144 parent.querySelector('audio').src = `/tts.mp3?lang=${lang}&voice=${voice}&text=${encodeURIComponent(mdDiv.textContent)}`; |
| 142 } | 145 } |
| 143 div.innerHTML = text; | |
| 144 div.removeAttribute('markdown'); | |
| 145 } | 146 } |
| 146 } | 147 } |
