From 58ca14f26e22852c1ab2c8262ca05ce07d056021 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Fri, 3 Feb 2023 19:55:07 +0100 Subject: [PATCH] generalized to all jxr shortcuts (without parameters) --- index.html | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index aed0e8e..987f63b 100644 --- a/index.html +++ b/index.html @@ -2316,10 +2316,19 @@ consider pick then apply, i.e changeColorLastId() but for next Id */ +let jxrshortcuts = [ /(\d)s (.*)/, /qs ([^\s]+)/, / sa ([^\s]+) (.*)/, /obsv ([^\s]+)/, /observe ([^\s]+)/, /lg ([^\s]+) ([^\s]+)/, /lg ([^\s]+)/] +// could add color per found group function jxrhighlight(){ + // could be run after each note is created instead [...document.querySelectorAll("[value]")] .filter( el => (el.getAttribute("value").match(/^jxr /))) - .map( el => el.setAttribute("troika-text", {colorRanges: {0: 0x0099ff, 3: 0xffffff}}) ) + .map( el => { + let code = el.getAttribute("value") + let foundRanges = {0: 0x0099ff, 3: 0xffffff} + jxrshortcuts.filter( pattern => code.match(pattern) ) + .map( fp => foundRanges[code.search(fp)] = 0xff0000 ) + el.setAttribute("troika-text", {colorRanges: foundRanges}) + }) // see also generalization via https://shiki.matsu.io custom renderers }