aboutsummaryrefslogtreecommitdiff
path: root/static
diff options
context:
space:
mode:
Diffstat (limited to 'static')
-rw-r--r--static/formatters.ts6
-rw-r--r--static/user/.gitignore1
-rw-r--r--static/user/user-additions.js11
3 files changed, 18 insertions, 0 deletions
diff --git a/static/formatters.ts b/static/formatters.ts
index 38c71e5e..828a0e8b 100644
--- a/static/formatters.ts
+++ b/static/formatters.ts
@@ -4,6 +4,12 @@ export {
import { makeElement } from './lib'
+declare global {
+ interface Window {
+ formatters : Map<string, (e : HTMLElement, s : any) => void>;
+ }
+}
+
let formatters : Map<string, (e : HTMLElement, s : any) => void>;
formatters = window.formatters = new Map();
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>');
+ }
+})