diff options
Diffstat (limited to 'card')
-rw-r--r-- | card/card.css | 2 | ||||
-rw-r--r-- | card/card.html | 2 | ||||
-rw-r--r-- | card/card.js | 20 |
3 files changed, 18 insertions, 6 deletions
diff --git a/card/card.css b/card/card.css index d5ce6cf..7bb4598 100644 --- a/card/card.css +++ b/card/card.css @@ -23,7 +23,7 @@ hr { .card.front .target-word-translation, .card.front .sentence-translation, .card.front hr, -.card.front ruby rt { +.card.front ruby rt.hidden { display: none; } diff --git a/card/card.html b/card/card.html index f0bdb77..5712f6b 100644 --- a/card/card.html +++ b/card/card.html @@ -9,7 +9,7 @@ <body> <div class="card back"> -<span class="sentence">[俺](おれ)の[目](め)の[前](まえ)に[全](ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\*escape\* (test)</span> +<span class="sentence">[俺](おれ)の[目](め)の[前](まえ)に{全}(ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\*escape\* (test)</span> <hr class="split"> <span class="target-word-reading">立つ【た・つ】</span> <span class="target-word-translation">To stand</span> diff --git a/card/card.js b/card/card.js index e31564f..e375e8a 100644 --- a/card/card.js +++ b/card/card.js @@ -3,6 +3,7 @@ function parseSentence(input) { var mode = "normal"; // normal, kanji, reading var out = ""; // output html + var alwaysvisisble = false; // if furigana is always visible (on front of card) var kanji = ""; // current kanji var reading = ""; // current kanji reading @@ -13,10 +14,21 @@ function parseSentence(input) { if (input[i] == "*") { bold = !bold; out += `<${bold ? "" : "/"}b>`; continue; } // parse [kanji](reading) into ruby text - if (mode == "normal" && input[i] == "[") { kanji = ""; mode = "kanji"; continue; } - if (mode == "kanji" && input[i] == "]") { mode = "normal"; continue; } - if (mode == "normal" && kanji.length > 0 && input[i-1] == "]" && input[i] == "(") { reading = ""; mode = "reading"; continue; } - if (mode == "reading" && input[i] == ")") { mode = "normal"; out += `<ruby>${kanji}<rt>${reading}</rt></ruby>`; continue; } + // [kanji](reading) is only visible on card back + // {kanji}(reading) is always visible + if (mode == "normal" && input[i] == "[") // hidden reading kanji open + { kanji = ""; mode = "kanji"; alwaysvisisble = false; continue; } + if (mode == "normal" && input[i] == "{") // always visible reading kanji open + { kanji = ""; mode = "kanji"; alwaysvisisble = true; continue; } + if (mode == "kanji" && input[i] == "]") continue; // hidden reading kanji close + if (mode == "kanji" && input[i] == "}") continue; // always visible reading kanji close + if (mode == "kanji" && kanji.length > 0 && input[i] == "(") // reading open + { reading = ""; mode = "reading"; continue; } + if (mode == "reading" && input[i] == ")") { // reading close + mode = "normal"; + out += `<ruby>${kanji}<rt class="${alwaysvisisble ? 'visible' : 'hidden'}">${reading}</rt></ruby>`; + continue; + } // add current character to selected mode buffer if (mode == "normal") out += input[i]; |