diff options
author | lonkaars <loek@pipeframe.xyz> | 2022-12-27 12:33:35 +0100 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2022-12-27 12:33:35 +0100 |
commit | 23daec1b60a43f74de0b2c96647d597b9c3271d6 (patch) | |
tree | ec0a9f7fa4b3e1d60afda42f6335287c200640ac /card | |
parent | 240bd18fd2d1894522d067287f0ecb3fd4e7cb46 (diff) |
parse \n into <br>, minify css, and parse elements with parse class
Diffstat (limited to 'card')
-rw-r--r-- | card/card.html | 2 | ||||
-rw-r--r-- | card/card.js | 19 |
2 files changed, 13 insertions, 8 deletions
diff --git a/card/card.html b/card/card.html index 9165bf1..908be68 100644 --- a/card/card.html +++ b/card/card.html @@ -9,7 +9,7 @@ <body> <div class="card back"> -<span class="sentence foreign">[俺](おれ)の[目](め)の[前](まえ)に{全}(ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\*escape\* (test)</span> +<span class="parse sentence foreign">[俺](おれ)の[目](め)の[前](まえ)に{全}(ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\n\*escape\* (<i>test</i>)</span> <hr class="split"> <span class="target-word-reading foreign">立つ【た・つ】</span> <span class="target-word-translation native">To stand</span> diff --git a/card/card.js b/card/card.js index e375e8a..347a44c 100644 --- a/card/card.js +++ b/card/card.js @@ -8,8 +8,12 @@ function parseSentence(input) { var reading = ""; // current kanji reading for (var i = 0; i < input.length; i++) { - // escape all characters preceded by \ - if (input[i] == "\\") { out += input[i+1]; i++; continue; } + // escape characters preceded by \ + if (input[i] == "\\") { + var escaped = input[i+1]; + if (escaped == "n") escaped = "<br>"; // newline + out += escaped; i++; continue; + } // parse *test* into <b>test</b> if (input[i] == "*") { bold = !bold; out += `<${bold ? "" : "/"}b>`; continue; } @@ -40,12 +44,13 @@ function parseSentence(input) { } function run() { - var sentences = document.getElementsByClassName("sentence"); + var input = document.getElementsByClassName("parse"); - for (var sentence of sentences) { - if (sentence.classList.contains("parsed")) continue; - sentence.innerHTML = parseSentence(sentence.innerText); - sentence.classList.add("parsed"); + for (var el of input) { + if (el.classList.contains("parsed")) continue; + el.innerHTML = parseSentence(el.innerHTML); + el.classList.remove("parse"); + el.classList.add("parsed"); } } |