aboutsummaryrefslogtreecommitdiff
path: root/static/user/user-additions.js
blob: 59a6248d9189971af006b8b54d29b813487d8ab0 (plain)
1
2
3
4
5
6
7
8
9
10
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>');
    }
})