Mercurial Hosting > lang
changeset 44:007856fd62c0
ruby fix
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 13 Aug 2025 08:50:33 +0900 |
parents | 5ecfdf43f72d |
children | fef7a5c65cfb |
files | courses/j1.txt src/site.js |
diffstat | 2 files changed, 35 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/courses/j1.txt Mon Aug 11 10:34:01 2025 +0900 +++ b/courses/j1.txt Wed Aug 13 08:50:33 2025 +0900 @@ -19,7 +19,12 @@ APPLIES TO ALL JAPANESE TEXT: Example sentences, grammar explanations, vocabulary lists, casual mentions - ANY Japanese characters in your response need ruby tags. -VERIFICATION STEP: Before sending, scan your ENTIRE response for any Japanese characters (hiragana, katakana, kanji) and ensure they all have ruby tags. +VERIFICATION STEP: Before sending, scan your ENTIRE response character by character. Every single hiragana, katakana, and kanji character MUST have ruby tags. No exceptions, even for simple particles like は or です. + +Double-check these common oversights: +- Particles: は, が, を, に, で, と +- Common words: です, ます, ません, ました +- Simple hiragana words: これ, それ, あれ, ここ, そこ, あそこ # Teaching Instructions @@ -49,5 +54,9 @@ NEVER say "That's correct!" or similar confirmations - just move to the next sentence. +CRITICAL REQUIREMENT: When writing Japanese, always use ruby markdown syntax {japanese|romaji} for pronunciation guidance. NEVER use plain romaji, whether in quotation marks or plain text, even when the user does. Always use Japanese characters with ruby markdown syntax, including when explaining, comparing, or referring to Japanese words within English explanations. +WRONG: "imasu", "desu", "neko" +CORRECT: "{います|imasu}", "{です|desu}", "{猫|neko}" + You can start.
--- a/src/site.js Mon Aug 11 10:34:01 2025 +0900 +++ b/src/site.js Wed Aug 13 08:50:33 2025 +0900 @@ -130,18 +130,37 @@ let mdDiv = document.createElement('div'); +function toRuby(node) { + let type = node.nodeType; + if( type === Node.ELEMENT_NODE ) { + let name = node.tagName; + if( name === "PRE" || name === "CODE" ) + return; + for( let child of node.childNodes ) { + toRuby(child); + } + } else if( type === Node.TEXT_NODE ) { + let text = node.nodeValue.replace(/\{([^{|}]+)\|([^{|}]+)\}/g, '<ruby>$1<rt>$2</rt></ruby>'); + if( text !== node.nodeValue ) { + mdDiv.innerHTML = text; + while(mdDiv.firstChild) { + node.parentNode.insertBefore(mdDiv.firstChild, node); + } + node.remove(); + } + } +} + function handleMarkdown(lang,voice) { - let converter = window.markdownit({html: true}); + let converter = window.markdownit(); let divs = document.querySelectorAll('[markdown]'); for( let div of divs ) { - let text = div.textContent; - text = text.replace(/\{([^{|}]+)\|([^{|}]+)\}/g, '<ruby>$1<rt>$2</rt></ruby>'); - text = converter.render(text); - div.innerHTML = text; + div.innerHTML = converter.render(div.textContent); + toRuby(div); div.removeAttribute('markdown'); let parent = div.parentNode; if( parent.getAttribute('role')==='assistant' ) { - mdDiv.innerHTML = text; + mdDiv.innerHTML = div.textContent; let rts = mdDiv.querySelectorAll('rt'); for( let rt of rts ) { rt.remove();