aboutsummaryrefslogtreecommitdiff
path: root/resources/assets/javascripts/lib/markup.js
blob: 89eb0a37122b8743d8c3248db693391f143190a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ------------------------------------------------------------------------
 * Javascript-spezifisches Markup
 * ------------------------------------------------------------------------ */

const Markup = {
    element: function (selector) {
        var elements;
        if (typeof selector === 'string' && document.getElementById(selector)) {
            elements = $('#' + selector);
        } else {
            elements = $(selector);
        }
        elements.each((index, element) => {
            $.each(Markup.callbacks, (index, func) => {
                if (index !== 'element' || typeof func === 'function') {
                    func(element);
                }
            });
        });
    },
    callbacks: {
        math_jax: function (element) {
            $('span.math-tex:not(:has(.MathJax)),.formatted-content:contains("[tex]")', element).each((index, block) => {
                STUDIP.loadChunk('mathjax').then((MathJax) => {
                    if (typeof MathJax.Hub.Typeset === "function") {
                        MathJax.Hub.Typeset(block);
                    }
                });
            });
        },
        codehighlight: function (element) {
            $('pre.usercode:not(.hljs)', element).each(function (index, block) {
                STUDIP.loadChunk('code-highlight').then((hljs) => {
                    hljs.highlightBlock(block);
                });
            });
        }
    }
};

export default Markup;