diff options
-rw-r--r-- | xP/public/xP.js | 29 |
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)) }, } |