xP: detect links in the log
This commit is contained in:
parent
240fac4d90
commit
d29e2cbfe8
|
@ -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))
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue