word/finder: common method to format caption names
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 6 Jun 2022 17:00:35 +0000 (19:00 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 11 Jul 2022 02:02:34 +0000 (04:02 +0200)
word/finder.js

index 5dcc9e3de93f079521c4be441f0345795ce99c78..9f56a2c28c553ff7f5690278c46ec6cc0937ae71 100644 (file)
@@ -1,4 +1,15 @@
 class WordFinder extends WordQuiz {
+       namehtml(name) {
+               //let wbr = new RegExp('\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)', 'g');
+               let aliases = name.split('/');
+               let html = aliases.shift();
+               html = html.replace(/\((.+)\)/, '<small>$1</small>');
+               for (let alias of aliases) {
+                       html += ` <small>(${alias})</small>`;
+               }
+               return html;
+       }
+
        add(catitem, rows) {
                rows.forEach(ref => {
                        const [title, level, imgid, subs] = this.data[ref];
@@ -8,9 +19,8 @@ class WordFinder extends WordQuiz {
                                put(figitem, 'img[src=$]', `/data/word/32/${imgid}.jpg`);
                        }
                        if (title) {
-                               let html = title.replace(/\/(.*)/, ' <small>($1)</small>');
                                put(figitem, 'figcaption', {
-                                       innerHTML: html,
+                                       innerHTML: this.namehtml(title),
                                });
                        }
                        if (level <= 1 && subs.length >= 2) {