diff options
author | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-15 01:36:07 +0100 |
---|---|---|
committer | Hugo Hörnquist <hugo@lysator.liu.se> | 2022-03-15 02:25:27 +0100 |
commit | bb7b8ee00bd2c7d26e82c2eb4a0571023e821d9f (patch) | |
tree | b142e1dc98835237d679ab83029f5c1371453113 /static/user | |
parent | Introduce concept of VEvent formatters in frontend. (diff) | |
download | calp-bb7b8ee00bd2c7d26e82c2eb4a0571023e821d9f.tar.gz calp-bb7b8ee00bd2c7d26e82c2eb4a0571023e821d9f.tar.xz |
Introduce user-additions in frontend.
Along with an initial example of their use.
Diffstat (limited to '')
-rw-r--r-- | static/user/.gitignore | 1 | ||||
-rw-r--r-- | static/user/user-additions.js | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/static/user/.gitignore b/static/user/.gitignore new file mode 100644 index 00000000..d4aa116a --- /dev/null +++ b/static/user/.gitignore @@ -0,0 +1 @@ +!*.js diff --git a/static/user/user-additions.js b/static/user/user-additions.js new file mode 100644 index 00000000..59a6248d --- /dev/null +++ b/static/user/user-additions.js @@ -0,0 +1,11 @@ +window.formatters.set('description', (el, d) => { + if (/<br\/?>/.exec(d)) { + /* Assume that the text is HTML iff in contains a <br/> tag */ + let parser = new DOMParser(); + let doc = parser.parseFromString(d, 'text/html'); + el.replaceChildren(doc.body); + } else { + /* Otherwise it should be plain(er) text, parse "all" links */ + el.innerHTML = d.replaceAll(/https?:\/\/\S+/g, '<a href="$&">$&</a>'); + } +}) |