@@ -105,7 +105,7 @@ let runTextToSpeech = function (text, anchors) {
105105} ;
106106
107107let renderPinyinForDefinition = function ( pinyin , container ) {
108- const syllables = pinyin . split ( ' ' ) ;
108+ const syllables = getSyllables ( pinyin ) ;
109109 for ( const syllable of syllables ) {
110110 let syllableElement = document . createElement ( 'span' ) ;
111111 // TODO: could just do this with CSS (.tonewhatever under .canto: no color coding)
@@ -122,7 +122,7 @@ function modifyHeaderTones(definitionList, word) {
122122 }
123123 // TODO just send the pinyin on the word set....
124124 const wordHolders = document . getElementsByClassName ( `${ word } -header` ) ;
125- const syllables = definitionList [ 0 ] . pinyin . split ( ' ' ) ;
125+ const syllables = getSyllables ( definitionList [ 0 ] . pinyin ) ;
126126 for ( const wordHolder of wordHolders ) {
127127 const elementsToModify = wordHolder . querySelectorAll ( '.word-header-character' ) ;
128128 if ( syllables . length !== elementsToModify . length ) {
@@ -587,11 +587,21 @@ let renderCharacterHeader = function (character, container) {
587587 } ) ;
588588 container . appendChild ( characterHolder ) ;
589589}
590+
591+ function getSyllables ( pinyin ) {
592+ // some CEDICT entries include a " - ", so like:
593+ // yi1 mu2 - yi1 yang4 rather than yi1 mu2 yi1 yang4
594+ // arguably that should be a data fix, but I guess
595+ // it looks slightly better for display that way.
596+ // but for tone color coding, we just want to have each
597+ // syllable pronunciation by itself.
598+ return pinyin . replace ( ' - ' , ' ' ) . split ( ' ' ) ;
599+ }
590600let renderWordHeaderByCharacter = function ( word , container ) {
591601 const definitionList = definitions [ word ] ;
592602 let syllables = null ;
593603 if ( definitionList && definitionList [ 0 ] . pinyin ) {
594- syllables = definitionList [ 0 ] . pinyin . split ( ' ' ) ;
604+ syllables = getSyllables ( definitionList [ 0 ] . pinyin ) ;
595605 if ( syllables . length !== word . length ) {
596606 syllables = null ;
597607 }
0 commit comments