aboutsummaryrefslogtreecommitdiff
path: root/anki-card-template
diff options
context:
space:
mode:
Diffstat (limited to 'anki-card-template')
-rw-r--r--anki-card-template/card.css1
-rw-r--r--anki-card-template/card.html6
-rw-r--r--anki-card-template/card.js26
3 files changed, 30 insertions, 3 deletions
diff --git a/anki-card-template/card.css b/anki-card-template/card.css
index fdf2bae..b9c13e4 100644
--- a/anki-card-template/card.css
+++ b/anki-card-template/card.css
@@ -224,6 +224,7 @@ body {
font-size: var(--subtile-font-size);
vertical-align: baseline;
}
+.subtile .script-japanese { font-style: normal; } /* italic japanese looks weird */
/* word note style */
#card #target-word-reading .kanji { position: relative; }
diff --git a/anki-card-template/card.html b/anki-card-template/card.html
index 103b47e..6d6c861 100644
--- a/anki-card-template/card.html
+++ b/anki-card-template/card.html
@@ -26,9 +26,9 @@
</div>
<hr id="separator">
<div id="back">
-<span id="target-word-reading" class="parse parse-format parse-reading parse-indicators foreign">見舞われる[0]【み・まわれる】(note)</span>
-<span id="target-word-translation" class="parse parse-format parse-definitions parse-indicators native">[verb] To experi\ence {crisis}, to undergo, to suffer</span>
-<span id="sentence-translation" class="parse parse-format native spoiler hidden">This village is now in danger of *extinction* because of _Vah Ruta_, the water divine beast.</span>
+<span id="target-word-reading" class="parse parse-format parse-reading parse-indicators parse-script foreign">見舞われる[0]【み・まわれる】(note)</span>
+<span id="target-word-translation" class="parse parse-format parse-definitions parse-indicators parse-script native">[verb] To experi\ence {crisis}, to undergo, to suffer {testテストtest}</span>
+<span id="sentence-translation" class="parse parse-format native spoiler parse-script hidden">This village is now in danger of *extinction* because of _Vah Ruta_, the water divine beast.</span>
<span id="tags" class="parse parse-tags">ゼルダの伝説 ブレス・オブ・ザ・ワイルド</span>
</div>
</div>
diff --git a/anki-card-template/card.js b/anki-card-template/card.js
index 422c28f..742184a 100644
--- a/anki-card-template/card.js
+++ b/anki-card-template/card.js
@@ -205,6 +205,31 @@ function parseDefinitions(nodes) {
return HTMLtoParseArr(out);
}
+function parseScript(nodes) {
+ for (var node of nodes) {
+ if (node.type == "html") continue;
+ if (node.data.length == 0) continue;
+
+ var lastScript = "unknown";
+ var input = node.data;
+ var out = "";
+ for (var i = 0; i < input.length; i++) {
+ var script = "unknown";
+ if (!charNotJapanese(input[i])) script = "japanese";
+ if (!charNotLatin(input[i])) script = "latin";
+
+ if (i == 0) out += `<span class="script-${script}">`;
+ else if (script != lastScript) out += `</span><span class="script-${script}">`;
+
+ out += input[i];
+ lastScript = script;
+ }
+ out += "</span>";
+ node.data = out;
+ }
+ return HTMLtoParseArr(nodes.map(n => n.data).join("")); // re-parse for newly created html
+}
+
HTMLElement.prototype.parse = function() {
if (this.classList.contains("parsed")) return; // ignore already parsed elements
var input = this.innerHTML; // get raw data from anki field
@@ -217,6 +242,7 @@ HTMLElement.prototype.parse = function() {
if (this.classList.contains("parse-indicators")) nodes = parseIndicators(nodes);
if (this.classList.contains("parse-tags")) nodes = parseTags(nodes);
if (this.classList.contains("parse-definitions")) nodes = parseDefinitions(nodes);
+ if (this.classList.contains("parse-script")) nodes = parseScript(nodes);
// join parsed text with unmodified html
var out = nodes.map(n => n.data).join("");