From 23daec1b60a43f74de0b2c96647d597b9c3271d6 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 27 Dec 2022 12:33:35 +0100 Subject: parse \n into
, minify css, and parse elements with parse class --- card/card.html | 2 +- card/card.js | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'card') 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 @@
-[俺](おれ)の[目](め)の[前](まえ)に{全}(ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\*escape\* (test) +[俺](おれ)の[目](め)の[前](まえ)に{全}(ぜん)[裸](はだか)のアリスが*[立](た)っていた*。\n\*escape\* (test)
立つ【た・つ】 To stand 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 = "
"; // newline + out += escaped; i++; continue; + } // parse *test* into test 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"); } } -- cgit v1.2.3