aboutsummaryrefslogtreecommitdiff
path: root/xP
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2022-09-06 14:35:42 +0200
committerPřemysl Eric Janouch <p@janouch.name>2022-09-06 14:36:30 +0200
commitd2af6cf64c70e2a1b381e4edc058e7a530e86514 (patch)
treeaaf46c141cee5675c682306eaf154667a3de8d08 /xP
parentd7b0b447b7e254d4af37f09acfa258956d24a7e0 (diff)
downloadxK-d2af6cf64c70e2a1b381e4edc058e7a530e86514.tar.gz
xK-d2af6cf64c70e2a1b381e4edc058e7a530e86514.tar.xz
xK-d2af6cf64c70e2a1b381e4edc058e7a530e86514.zip
xP: convert links to link elements
Diffstat (limited to 'xP')
-rw-r--r--xP/public/xP.css10
-rw-r--r--xP/public/xP.js23
2 files changed, 25 insertions, 8 deletions
diff --git a/xP/public/xP.css b/xP/public/xP.css
index 3aaff10..8b67844 100644
--- a/xP/public/xP.css
+++ b/xP/public/xP.css
@@ -86,19 +86,19 @@ body {
padding: .1rem .3rem;
white-space: pre-wrap;
}
-.content span.b {
+.content .b {
font-weight: bold;
}
-.content span.i {
+.content .i {
font-style: italic;
}
-.content span.u {
+.content .u {
text-decoration: underline;
}
-.content span.s {
+.content .s {
text-decoration: line-through;
}
-.content span.m {
+.content .m {
font-family: monospace;
}
diff --git a/xP/public/xP.js b/xP/public/xP.js
index 13507d6..c0dba93 100644
--- a/xP/public/xP.js
+++ b/xP/public/xP.js
@@ -115,6 +115,24 @@ let BufferList = {
},
}
+function linkify(text, attrs, a) {
+ let re = new RegExp([
+ /https?:\/\//,
+ /([^\[\](){}<>"'\s]|\([^\[\](){}<>"'\s]*\))+/,
+ /[^\[\](){}<>"'\s,.:]/,
+ ].map(r => r.source).join(''), 'g')
+
+ let end = 0, match
+ while ((match = re.exec(text)) !== null) {
+ if (end < match.index)
+ a.push(m('span', attrs, text.substring(end, match.index)))
+ a.push(m('a', {href: match[0], ...attrs}, match[0]))
+ end = re.lastIndex
+ }
+ if (end < text.length)
+ a.push(m('span', attrs, text.substring(end)))
+}
+
let Content = {
view: vnode => {
let line = vnode.children[0]
@@ -139,11 +157,10 @@ let Content = {
line.items.forEach(item => {
switch (item.kind) {
case 'Text':
- // TODO: Detect and transform links.
- content.push(m('span', {
+ linkify(item.text, {
class: Array.from(classes.keys()).join(' '),
style: applyColor(fg, bg, inverse),
- }, item.text))
+ }, content)
break
case 'Reset':
classes.clear()