Mercurial Hosting > lang
comparison src/site.js @ 31:1e7d855afde3
voices
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 03 Aug 2025 17:05:38 -0600 |
parents | 505185272dd7 |
children | 0fb3488a017d |
comparison
equal
deleted
inserted
replaced
30:d48f48e1b790 | 31:1e7d855afde3 |
---|---|
122 | 122 |
123 // requires markdown-it | 123 // requires markdown-it |
124 | 124 |
125 let mdDiv = document.createElement('div'); | 125 let mdDiv = document.createElement('div'); |
126 | 126 |
127 function handleMarkdown(lang) { | 127 function handleMarkdown(lang,voice) { |
128 let converter = window.markdownit({html: true}); | 128 let converter = window.markdownit({html: true}); |
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>'); |
136 let rts = mdDiv.querySelectorAll('rt'); | 136 let rts = mdDiv.querySelectorAll('rt'); |
137 for( let rt of rts ) { | 137 for( let rt of rts ) { |
138 rt.remove(); | 138 rt.remove(); |
139 } | 139 } |
140 //console.log(mdDiv.textContent); | 140 //console.log(mdDiv.textContent); |
141 text += `\n<p><audio controls preload=none src="/tts.mp3?lang=${lang}&text=${encodeURIComponent(mdDiv.textContent)}"></audio></p>\n`; | 141 text += `\n<p><audio controls preload=none src="/tts.mp3?lang=${lang}&voice=${voice}&text=${encodeURIComponent(mdDiv.textContent)}"></audio></p>\n`; |
142 } | 142 } |
143 div.innerHTML = text; | 143 div.innerHTML = text; |
144 div.removeAttribute('markdown'); | 144 div.removeAttribute('markdown'); |
145 } | 145 } |
146 } | 146 } |