Skip to content
Snippets Groups Projects
Unverified Commit 0d31349c authored by Sebastian Höffner's avatar Sebastian Höffner
Browse files

Adding syntax highlighting to the web interface.

parent 0e777ca3
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,45 @@
<html>
<head>
<title>OpenCCG Webinterface</title>
<!-- Script and style adapted from https://stackoverflow.com/a/7220510,
written by user123444555621 -->
<script>
function syntaxHighlight(json) {
if (typeof json != 'string') {
json = JSON.stringify(json, undefined, 2);
}
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
} else if (/true|false/.test(match)) {
cls = 'boolean';
} else if (/null/.test(match)) {
cls = 'null';
}
return '<span class="' + cls + '">' + match + '</span>';
});
}
function init_syntax() {
var pre = document.getElementById('response');
pre.innerHTML = syntaxHighlight(pre.innerHTML);
}
window.onload = init_syntax;
</script>
<style>
pre {outline: 1px solid #ccc; padding: 5px; margin: 5px; }
.string { color: forestgreen; }
.number { color: darkgoldenrod; }
.boolean { color: blue; }
.null { color: magenta; }
.key { color: maroon; }
</style>
</head>
<body>
OpenCCG Webinterface
......@@ -9,12 +48,10 @@
<input type="text" name="sentence" value="{{ sentence or '' }}" style="width: 300px" />
<input type="submit" value="Go!" />
</form>
{% if response %}
<div>
<pre>
<pre id="response">
{{ response }}
</pre>
</div>
{% endif %}
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment