Fix syntax-highlighting

This commit is contained in:
Shadowfacts 2016-09-29 11:43:31 -04:00
parent 64da38254d
commit 0ade2dcfbc
No known key found for this signature in database
GPG Key ID: A7A3BA2CFC135F32
2 changed files with 11 additions and 6 deletions

View File

@ -9,7 +9,6 @@
<body>
<script src="codemirror/codemirror.js"></script>
<script src="codemirror/mode/javascript/javascript.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="main.js"></script>
</body>

16
main.js
View File

@ -13,19 +13,25 @@ let extensions = {
let file = window.location.hash.substring(1);
$.get({
url: `https://raw.githubusercontent.com/${file}`,
success: (data) => {
success: (code) => {
let parts = file.split(".");
let fileExtension = parts[parts.length - 1];
let extension = extensions.hasOwnProperty(fileExtension) ? extensions[fileExtension] : fileExtension;
setup(data, extension);
let mode = extensions.hasOwnProperty(fileExtension) ? extensions[fileExtension] : fileExtension;
$.get({
url: `/codemirror/mode/${mode}/${mode}.js`,
success: (data) => {
eval(data);
setup(code, mode);
}
});
}
});
// setup
function setup(data, extension) {
function setup(data, mode) {
editor = new CodeMirror(document.body, {
value: data,
mode: extension,
mode: mode,
readOnly: true,
autofocus: true,
extraKeys: {