admin: add support for template field and Jinja2 highlighting

This commit is contained in:
Jens Langhammer 2020-02-17 17:48:53 +01:00
parent a08bdfdbcd
commit 205183445c
1 changed files with 15 additions and 2 deletions

View File

@ -20,6 +20,7 @@
<link rel="stylesheet" href="{% static 'codemirror/lib/codemirror.css' %}"> <link rel="stylesheet" href="{% static 'codemirror/lib/codemirror.css' %}">
<link rel="stylesheet" href="{% static 'codemirror/theme/monokai.css' %}"> <link rel="stylesheet" href="{% static 'codemirror/theme/monokai.css' %}">
<script src="{% static 'codemirror/mode/yaml/yaml.js' %}"></script> <script src="{% static 'codemirror/mode/yaml/yaml.js' %}"></script>
<script src="{% static 'codemirror/mode/jinja2/jinja2.js' %}"></script>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
@ -36,14 +37,26 @@
{% block beneath_form %} {% block beneath_form %}
{% endblock %} {% endblock %}
<script> <script>
let attributes = document.getElementsByName('attributes'); const attributes = document.getElementsByName('attributes');
if (attributes.length > 0) { if (attributes.length > 0) {
let myCodeMirror = CodeMirror.fromTextArea(attributes[0], { // https://github.com/codemirror/CodeMirror/issues/5092
attributes[0].removeAttribute("required");
const attributesCM = CodeMirror.fromTextArea(attributes[0], {
mode: 'yaml', mode: 'yaml',
theme: 'monokai', theme: 'monokai',
lineNumbers: true, lineNumbers: true,
}); });
} }
const templates = document.getElementsByName('template');
if (templates.length > 0) {
// https://github.com/codemirror/CodeMirror/issues/5092
templates[0].removeAttribute("required");
const templateCM = CodeMirror.fromTextArea(templates[0], {
mode: 'jinja2',
theme: 'monokai',
lineNumbers: true,
});
}
</script> </script>
</div> </div>
{% endblock %} {% endblock %}