diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-26 17:49:05 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-26 17:49:05 +0100 |
commit | cb8fdd17ba7539174f811f8e622c2969504bd135 (patch) | |
tree | 15dcb4ce080e63cd0d59bdb87ad1f5eb421c5593 /card/card.js | |
parent | 50ba879e537f2a465486d17975714a509461c8dc (diff) |
allow always visible furigana with {kanji}(reading)
Diffstat (limited to 'card/card.js')
-rw-r--r-- | card/card.js | 20 |
1 files changed, 16 insertions, 4 deletions
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]; |