aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-10 17:18:08 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-10 17:18:22 +0200
commitd29e2cbfe82197319ab66ace6837bd3c1763dbad (patch)
tree8834c0a2a471347592cc75fa0fd9cafacca8af51
parent240fac4d90b3bcbeacc7d2ce00316a4d812459b0 (diff)
downloadxK-d29e2cbfe82197319ab66ace6837bd3c1763dbad.tar.gz
xK-d29e2cbfe82197319ab66ace6837bd3c1763dbad.tar.xz
xK-d29e2cbfe82197319ab66ace6837bd3c1763dbad.zip
xP: detect links in the log
-rw-r--r--xP/public/xP.js29
1 files changed, 21 insertions, 8 deletions
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))
},
}