aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:13:31 +0200
committerHugo Hörnquist <hugo@lysator.liu.se>2022-07-07 21:14:09 +0200
commit2185a0a031e9fca82dfb554c2ece864d1efb9fb0 (patch)
tree3bffdfb7a799446a50330e9d5f06406492279a24
parentExtend javascript formatters to also take VEvent. (diff)
downloadcalp-2185a0a031e9fca82dfb554c2ece864d1efb9fb0.tar.gz
calp-2185a0a031e9fca82dfb554c2ece864d1efb9fb0.tar.xz
JS user addition for parsing Microsoft Teams links.
-rw-r--r--static/user/user-additions.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/static/user/user-additions.js b/static/user/user-additions.js
index 5f5357eb..7291f232 100644
--- a/static/user/user-additions.js
+++ b/static/user/user-additions.js
@@ -1,5 +1,39 @@
window.formatters.set('description', (el, ev, d) => {
- if (/<\/?\w+( +\w+(=["']?\w+["']?)?)* *\/?>/.exec(d)) {
+ if (ev.getProperty('X-MICROSOFT-SKYPETEAMSMEETINGURL')) {
+ /* parse Microsoft Teams meeting entries */
+ /* Replace lines with propper <hr> tags */
+ let rx1 = /^_+$/gm
+ /* Merge URL:s into a tags */
+ let rx2 = /(?<pipe>^|[|])\s*(?<name>[^|<\n]*)<(?<url>[^>]*)>/gm
+
+ let rxs = [`(?<line>${rx1.source})`,
+ `(?<link>${rx2.source})`,
+ ].join('|')
+ let rx = new RegExp(`(${rxs})`, 'gm')
+
+ let children = []
+ let idx = 0
+ for (let match of d.matchAll(rx)) {
+ children.push(d.substring(idx, match.index))
+
+ if (match.groups.line) {
+ children.push(document.createElement('hr'))
+ children.push(document.createElement('br'))
+ } else if (match.groups.link) {
+ if (match.groups.pipe === '|') {
+ children.push('| ');
+ }
+ let a = document.createElement('a')
+ a.textContent = match.groups.name || match.groups.url
+ a.href = match.groups.url
+ children.push(a)
+ }
+
+ idx = match.index + match[0].length
+ }
+ children.push(d.substring(idx));
+ el.replaceChildren(...children);
+ } else if (/<\/?\w+( +\w+(=["']?\w+["']?)?)* *\/?>/.exec(d)) {
/* Assume that the text is HTML if it contains something which looks
like an HTML tag */
let parser = new DOMParser();