From bb7b8ee00bd2c7d26e82c2eb4a0571023e821d9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 15 Mar 2022 01:36:07 +0100 Subject: Introduce user-additions in frontend. Along with an initial example of their use. --- static/user/user-additions.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 static/user/user-additions.js (limited to 'static/user/user-additions.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 (//.exec(d)) { + /* Assume that the text is HTML iff in contains a
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, '$&'); + } +}) -- cgit v1.2.3