From 5b70dd621e9a307e5c8ce9f0c816042038c4e666 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Mon, 6 Jun 2022 19:00:35 +0200 Subject: [PATCH] word/finder: common method to format caption names --- word/finder.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/word/finder.js b/word/finder.js index 5dcc9e3..9f56a2c 100644 --- a/word/finder.js +++ b/word/finder.js @@ -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(/\((.+)\)/, '$1'); + for (let alias of aliases) { + html += ` (${alias})`; + } + 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(/\/(.*)/, ' ($1)'); put(figitem, 'figcaption', { - innerHTML: html, + innerHTML: this.namehtml(title), }); } if (level <= 1 && subs.length >= 2) { -- 2.30.0