summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tools/yql_highlight/ut/test.template.html
blob: c82bbc2f502d7ff2634e416f4e5a0e1f5e6e5684 (plain) (blame)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html>

<head>
    <title>YQL Highlight Test</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css">
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }

        #main-container {
            display: flex;
            width: 100%;
            height: 100%;
        }

        #container {
            width: 33%;
            height: 100%;
        }

        #shiki-container {
            width: 33%;
            height: 100%;
            overflow: auto;
        }

        #highlightjs-container {
            width: 34%;
            height: 100%;
            overflow: auto;
        }

        #shiki-code,
        #highlightjs-code {
            margin: 0;
            font-family: monospace;
            font-size: 14px;
            line-height: 1.4;
            white-space: pre;
        }
    </style>
</head>

<body>
    <div id="main-container">
        <div id="container"></div>
        <div id="shiki-container">
            <pre id="shiki-code"></pre>
        </div>
        <div id="highlightjs-container">
            <pre><code id="highlightjs-code-yql" class="language-yql"></code></pre>
            <pre><code id="highlightjs-code-yqls" class="language-yqls"></code></pre>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
    <script>
        require.config({ paths: { 'vs': 'https://cdn.jsdelivr.net/npm/[email protected]/min/vs' } });
        require(['vs/editor/editor.main'], function () {
            const params = new URLSearchParams(window.location.search);

            const syntax = params.get('syntax') ?? 'yql';
            if (syntax != 'yql' && syntax != 'yqls') {
                alert(`Invalid query param syntax=${syntax}, expected yql or yqls`);
                return
            }

            const theme = params.get('theme') ?? 'light'
            if (theme != 'light' && theme != 'dark') {
                alert(`Invalid query param theme=${theme}, expected light or dark`);
                return
            }

            const tmlanguage = (syntax == 'yql')
                ? (/* {{YQL.tmLanguage.json}} */)
                    : (/* {{YQLs.tmLanguage.json}} */);

            const highlightjs = (syntax == 'yql')
                ? (/* {{YQL.highlightjs.json}} */)
                    : (/* {{YQLs.highlightjs.json}} */);

            /* {{monarch.patched.ts}} */

            shikiTheme = ((theme == 'light') ? 'github-light' : 'github-dark')
            shiki
                .getHighlighter({
                    themes: [shikiTheme],
                    langs: [{
                        id: syntax,
                        scopeName: `source.${syntax}`,
                        grammar: tmlanguage,
                        embeddedLangs: [
                            'python',
                            'javascript',
                        ],
                    }],
                })
                .then(highlighter => {
                    const code = value;
                    const html = highlighter.codeToHtml(code, {
                        lang: syntax,
                        theme: shikiTheme,
                    });
                    document.getElementById('shiki-code').innerHTML = html;
                });

            hljs.registerLanguage(syntax, function (hljs) { return highlightjs; });
            const codeElement = document.getElementById(`highlightjs-code-${syntax}`);
            codeElement.textContent = value;
            hljs.highlightElement(codeElement);
        });
    </script>
</body>

</html>