generalized to all jxr shortcuts (without parameters)

code-generation
Fabien Benetou 2 years ago
parent 273acff847
commit 58ca14f26e
  1. 11
      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(){ function jxrhighlight(){
// could be run after each note is created instead
[...document.querySelectorAll("[value]")] [...document.querySelectorAll("[value]")]
.filter( el => (el.getAttribute("value").match(/^jxr /))) .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 // see also generalization via https://shiki.matsu.io custom renderers
} }

Loading…
Cancel
Save