aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2024-02-18 16:41:53 +0100
committerlonkaars <loek@pipeframe.xyz>2024-02-18 16:41:53 +0100
commit363f1f6561cf09965cbdd0e94225960a9c8ed81e (patch)
tree0cf3d71fb245856e3f9d23f1292f22a3bfc1a999
parent30b4fd827dbe50d56bbc66859f46968e08f89b30 (diff)
update tag parsing in Anki card template3.7.0
-rw-r--r--anki-card-template/card.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/anki-card-template/card.js b/anki-card-template/card.js
index a98e2fe..18d5eda 100644
--- a/anki-card-template/card.js
+++ b/anki-card-template/card.js
@@ -235,7 +235,13 @@ function parseReading(nodes) {
function parseTags(nodes) {
var out = "";
- for (var tag of nodes.map(n => n.data).join("").split(" "))
+ var tags = nodes.map(n => n.data).join(""); // original field content
+ tags = tags.replaceAll("::", " "); // treat subtags as normal tags
+ tags = tags.split(" "); // split on space (tags may not contain spaces)
+ tags = Array.from(new Set(tags)); // remove duplicates
+ tags = tags.sort(); // sort the tags
+ tags = tags.map(text => text.replaceAll("_", " ")); // display underscore as space
+ for (var tag of tags)
out += `<span class="tag" style="--tag-hue: ${calculateTagHue(tag)};"><span class="inner">${tag}</span></span>`;
return HTMLtoParseArr(out);
}