(feat) display only available lanaguages
This commit is contained in:
parent
888743f4de
commit
22a7dc5fd5
|
@ -12,6 +12,8 @@ let proxy = URL.createObjectURL(new Blob([`
|
||||||
require(["vs/editor/editor.main"], function () {
|
require(["vs/editor/editor.main"], function () {
|
||||||
|
|
||||||
let init_lang = 'python';
|
let init_lang = 'python';
|
||||||
|
/** @type {string[]} */
|
||||||
|
const supported_langs = get_langs();
|
||||||
|
|
||||||
let editor = monaco.editor.create(document.getElementById('container'), {
|
let editor = monaco.editor.create(document.getElementById('container'), {
|
||||||
value: '# put code here',
|
value: '# put code here',
|
||||||
|
@ -24,6 +26,8 @@ require(["vs/editor/editor.main"], function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
monaco.languages.getLanguages().forEach(x => {
|
monaco.languages.getLanguages().forEach(x => {
|
||||||
|
if (supported_langs.indexOf(x.id) === -1) return
|
||||||
|
|
||||||
let el = document.createElement('option');
|
let el = document.createElement('option');
|
||||||
el.id = x.id;
|
el.id = x.id;
|
||||||
el.innerText = x.id;
|
el.innerText = x.id;
|
||||||
|
@ -34,7 +38,8 @@ require(["vs/editor/editor.main"], function () {
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('lang').onchange = (e) => {
|
document.getElementById('lang').onchange = (e) => {
|
||||||
monaco.editor.setModelLanguage(editor.getModel(), e.target.value)
|
e = e.target;
|
||||||
|
monaco.editor.setModelLanguage(editor.getModel(), e.options[e.selectedIndex].id)
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('run').onclick = (e) => {
|
document.getElementById('run').onclick = (e) => {
|
||||||
|
|
|
@ -12,8 +12,10 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Sandy</h1>
|
<h1>Sandy</h1>
|
||||||
|
|
||||||
{% block body %}{% endblock %}
|
{% block body %}{% endblock %}
|
||||||
|
|
||||||
|
<script>function get_langs() { return '{{ self.state.langs.join(",") }}'.split(',') }</script>
|
||||||
<script src="https://unpkg.com/monaco-editor@0.8.3/min/vs/loader.js"></script>
|
<script src="https://unpkg.com/monaco-editor@0.8.3/min/vs/loader.js"></script>
|
||||||
{% block script %}{% endblock %}
|
{% block script %}{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
|
Loading…
Reference in New Issue