From d29e2cbfe82197319ab66ace6837bd3c1763dbad Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Sat, 10 Sep 2022 17:18:08 +0200 Subject: xP: detect links in the log --- xP/public/xP.js | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'xP/public') diff --git a/xP/public/xP.js b/xP/public/xP.js index a9fc96c..8820b69 100644 --- a/xP/public/xP.js +++ b/xP/public/xP.js @@ -277,6 +277,12 @@ for (let i = 0; i < 24; i++) { // ---- UI --------------------------------------------------------------------- +let linkRE = [ + /https?:\/\//, + /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/, + /[^\[\](){}<>"'\s,.:]/, +].map(r => r.source).join('') + let Toolbar = { toggleAutoscroll: () => { bufferAutoscroll = !bufferAutoscroll @@ -349,13 +355,7 @@ let Content = { }, linkify: (text, attrs) => { - let re = new RegExp([ - /https?:\/\//, - /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/, - /[^\[\](){}<>"'\s,.:]/, - ].map(r => r.source).join(''), 'g') - - let a = [], end = 0, match + let re = new RegExp(linkRE, 'g'), a = [], end = 0, match while ((match = re.exec(text)) !== null) { if (end < match.index) a.push(m('span', attrs, text.substring(end, match.index))) @@ -480,8 +480,21 @@ let Log = { vnode.dom.scrollTop = vnode.dom.scrollHeight }, + linkify: text => { + let re = new RegExp(linkRE, 'g'), a = [], end = 0, match + while ((match = re.exec(text)) !== null) { + if (end < match.index) + a.push(text.substring(end, match.index)) + a.push(m('a[target=_blank]', {href: match[0]}, match[0])) + end = re.lastIndex + } + if (end < text.length) + a.push(text.substring(end)) + return a + }, + view: vnode => { - return m(".log", {}, bufferLog) + return m(".log", {}, Log.linkify(bufferLog)) }, } -- cgit v1.2.3-70-g09d2