Finish mode stuff

This commit is contained in:
Shadowfacts 2016-09-30 19:14:03 -04:00
parent 809a612697
commit b62ac18656
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
4 changed files with 428 additions and 271 deletions

View File

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

421
languages.js Normal file
View File

@ -0,0 +1,421 @@
let languages = {
"Brainfuck": {
file: "brainfuck",
mime: "text/x-brainfuck",
extensions: ["b", "bf"]
},
"C": {
file: "clike",
mime: "text/x-csrc",
extensions: ["c", "cats", "h", "idc", "w"]
},
"C++": {
file: "clike",
mime: "text/x-c++src",
extensions: ["cpp", "c++", "cc", "cp", "cxx", "h++", "hh", "hpp", "hxx", "inc", "inl", "ipp", "tcc", "tpp"]
},
"Java": {
file: "clike",
mime: "text/x-java",
extensions: ["java"]
},
"C#": {
file: "clike",
mime: "text/x-csharp",
extensions: ["cs", "cake", "cshtml", "csx"]
},
"Objective-C": {
file: "clike",
mime: "text/x-objectivec",
extensions: ["m"]
},
"Scala": {
file: "clike",
mime: "text/x-scala",
extensions: ["scala", "sbt", "sc"]
},
"Vertex Shader": {
file: "clike",
mime: "text/x-vertex",
extensions: ["frag", "fp", "frg", "fs", "fshader"]
},
"Fragment Shader": {
file: "clike",
mime: "x-shader/x-fragment",
extensions: ["vert", "vrx", "vshader"]
},
"Squirrel": {
file: "clike",
mime: "text/x-squirrel",
extensions: ["nut"]
},
"Kotlin": {
file: "clike",
mime: "text/x-kotlin",
extensions: ["kt", "ktm", "kts"]
},
"Ceylon": {
file: "clike",
mime: "text/x-ceylon",
extensions: ["ceylon"]
},
"Clojure": {
file: "clojure",
mime: "text/x-clojure",
extensions: ["clj", "boot", "cl2", "cljc", "cljs", "cljscm", "cljx", "hic"]
},
"CMake": {
file: "cmake",
mime: "text/x-cmake",
extensions: ["cmake"]
},
"CoffeeScript": {
file: "coffeescript",
mime: "text/x-coffeescript",
extensions: ["coffee", "_coffee", "cake", "cjsx", "cson", "iced"]
},
"Common Lisp": {
file: "commonlisp",
mime: "text/x-common-lisp",
extensions: ["lisp", "asd", "cl", "l", "lsp", "ny", "podsl", "sexp"]
},
"Crystal": {
file: "crystal",
mime: "text/x-crystal",
extensions: ["cr"]
},
"CSS": {
file: "css",
mime: "text/x-css",
extensions: ["css"]
},
"SCSS": {
file: "css",
mime: "text/x-scss",
extensions: ["scss"]
},
"Less": {
file: "css",
mime: "text/x-less",
extensions: ["less"]
},
"Python": {
file: "python",
mime: "text/x-python",
extensions: ["py", "bzl", "gyp", "lmi", "pyde", "pyp", "pyt", "pyw", "rpy", "tac", "wsgi", "xpy"]
},
"Cython": {
file: "python",
mime: "text/x-cython",
extensions: ["pyx", "pxd", "pxi"]
},
"D": {
file: "d",
mime: "text/x-d",
extensions: ["d", "di"]
},
"Dart": {
file: "dart",
mime: "text/x-dart",
extensions: ["dart"]
},
"Django": {
file: "django",
mime: "text/x-django",
extensions: ["mustache", "jinja"]
},
"Dockerfile": {
file: "dockerfile",
mime: "text/x-dockerfile",
extensions: ["dockerfile"]
},
"Elm": {
file: "elm",
mime: "text/x-elm",
extensions: ["elm"]
},
"Erlang": {
file: "erlang",
mime: "text/x-erlang",
extensions: ["erl", "es", "escript", "hrl", "xrl", "yrl"]
},
"FORTRAN": {
file: "fortran",
mime: "text/x-fortran",
extensions: ["f90", "f", "f03", "f08", "f77", "f95", "for", "fpp"]
},
"OCaml": {
file: "mllike",
mime: "text/x-ocaml",
extensions: ["ml", "eliom", "eliomi", "ml4", "mli", "mll", "mly"]
},
"F#": {
file: "mllike",
mime: "text/x-fsharp",
extensions: ["fsharp"]
},
"Go": {
file: "go",
mime: "text/x-go",
extensions: ["go"]
},
"Groovy": {
file: "groovy",
mime: "text/x-groovy",
extensions: ["groovy", "grt", "gtpl", "gvy"]
},
"HAML": {
file: "haml",
mime: "text/x-haml",
extensions: ["haml"]
},
"Handlebars": {
file: "handlebars",
mime: "text/x-handlebars-template",
extensions: ["handlebars", "hbs"]
},
"Haskell": {
file: "haskell",
mime: "text/x-haskell",
extensions: ["hs", "hsc"]
},
"Haxe": {
file: "haxe",
mime: "text/x-haxe",
extensions: ["hx", "hxsl"]
},
"Hxml": {
file: "haxe",
mime: "text/x-hxml",
extensions: ["hxml"]
},
"EJS": {
file: "htmlembedded",
mime: "text/x-ejs",
extensions: ["ejs"]
},
"ASP.NET": {
file: "htmlembedded",
mime: "text/x-aspx",
extensions: ["asp", "aspx"]
},
"Java Server Pages": {
file: "htmlembedded",
mime: "text/x-jsp",
extensions: ["jsp"]
},
"ERB": {
file: "htmlembedded",
mime: "text/x-erb",
extensions: ["erb"]
},
"HTML": {
file: ["xml", "htmlmixed"],
mime: "text/html",
extensions: ["html", "htm", "inc", "st", "xht", "xhtml"]
},
"IDL": {
file: "idl",
mime: "text/x-idl",
extensions: ["pro", "dlm"]
},
"JavaScript": {
file: "javascript",
mime: "text/javascript",
extensions: ["js", "es", "es6"]
},
"TypeScript": {
file: "javascript",
mime: "application/typescript",
extensions: ["ts", "tsx"]
},
"Julia": {
file: "julia",
mime: "text/x-julia",
extensions: ["jl"]
},
"LiveScript": {
file: "livescript",
mime: "text/x-livescript",
extensions: ["ls"]
},
"Lua": {
file: "lua",
mime: "text/x-lua",
extensions: ["lua", "nse", "pd_lua", "rbxs", "wlua"]
},
"Markdown": {
file: "markdown",
mime: "text/x-markdown",
extensions: ["md", "markdown", "mkd", "mkdn", "mkdown"]
},
"Mathematica": {
file: "mathematica",
mime: "text/x-mathematica",
extensions: ["cdf", "ma", "mt"]
},
"NSIS": {
file: "nsis",
mime: "text/x-nsis",
extensions: ["nsi", "nsh"]
},
"Oz": {
file: "oz",
mime: "text/x-oz",
extensions: ["oz"]
},
"Pascal": {
file: "pascal",
mime: "text/x-pascal",
extensions: ["pas", "dfm", "dpr", "inc", "lpr", "pp"]
},
"Perl": {
file: "perl",
mime: "text/x-perl",
extensions: ["pl", "al", "cgi", "fcgi", "perl", "ph", "plx", "pm", "pod", "psgi", "t"]
},
"PHP": {
file: "php",
mime: "application/x-httpd-php",
extensions: ["php"]
},
"PowerShell": {
file: "powershell",
mime: "application/x-powershell",
extensions: ["ps1", "psd1", "psm1"]
},
"INI": {
file: "properties",
mime: "text/x-ini",
extensions: ["properties", "ini"]
},
"Protocol Buffer": {
file: "protobuf",
mime: "text/x-protobuf",
extensions: ["proto"]
},
"R": {
file: "r",
mime: "text/x-rsrc",
extensions: ["r", "rd", "rsx"]
},
"Ruby": {
file: "ruby",
mime: "text/x-ruby",
extensions: ["rb", "ruby", "rake", "gemspec"]
},
"Rust": {
file: "rust",
mime: "text/x-rustsrc",
extensions: ["rs"]
},
"SAS": {
file: "sas",
mime: "text/x-sas",
extensions: ["sas"]
},
"Sass": {
file: "sass",
mime: "text/x-sass",
extensions: ["sass"]
},
"Scheme": {
file: "scheme",
mime: "text/x-scheme",
extensions: ["scm", "sld", "sls", "sps", "ss"]
},
"Shell": {
file: "shell",
mime: "text/x-sh",
extensions: ["sh", "bash", "command", "zsh"]
},
"Slim": {
file: "slim",
mime: "application/x-slim",
extensions: ["slim"]
},
"Smalltalk": {
file: "smalltalk",
mime: "text/x-stsrc",
extensions: ["st", "cs"]
},
"Smarty": {
file: "smarty",
mime: "text/x-smarty",
extensions: ["tpl"]
},
"Stylus": {
file: "stylus",
mime: "text/x-styl",
extensions: ["styl"]
},
"SQL": {
file: "sql",
mime: "text/x-sql",
extensions: ["sql"]
},
"Swift": {
file: "swift",
mime: "text/x-swift",
extensions: ["swift"]
},
"TeX": {
file: "stex",
mime: "text/x-stex",
extensions: ["tex"]
},
"Tcl": {
file: "tcl",
mime: "text/x-tcl",
extensions: ["tcl", "adp", "tm"]
},
"Textile": {
file: "textile",
mime: "text/x-textile",
extensions: ["textile"]
},
"TOML": {
file: "toml",
mime: "text/x-toml",
extensions: ["toml"]
},
"Visual Basic": {
file: "vb",
mime: "text/x-vb",
extensions: ["vb", "vba", "vbhtml", "vbs"]
},
"XML": {
file: "xml",
mime: "application/xml",
extensions: ["xml", "ant", "fxml", "iml", "plist", "storyboard", "vbproj", "vcsettings"]
},
"XQuery": {
file: "xquery",
mime: "application/xquery",
extensions: ["xquery", "xq", "xql", "xqm", "xqy"]
},
"YAML": {
file: "yaml",
mime: "text/x-yaml",
extensions: ["yml", "yaml"]
},
"Jekyll (YAML front matter + GitHub flavored Markdown)": {
file: "yaml-frontmatter",
mime: "yaml-frontmatter"
}
};
function getLanguageByExtension(ext) {
ext = ext.toLowerCase();
for (var key in languages) {
let language = languages[key];
if (language.extensions) {
for (var i = 0; i < language.extensions.length; i++) {
if (language.extensions[i].toLowerCase() == ext) {
return language;
}
}
}
}
return null;
}

16
main.js
View File

@ -4,12 +4,6 @@ var incompleteMark;
var focused = false;
let invalids = [];
let extensions = {
js: "javascript",
kt: "kotlin",
md: "markdown"
};
// fetch file and setup
let file = window.location.hash.substring(1);
$.get({
@ -17,23 +11,23 @@ $.get({
success: (code) => {
let parts = file.split(".");
let fileExtension = parts[parts.length - 1];
let mode = extensions.hasOwnProperty(fileExtension) ? extensions[fileExtension] : fileExtension;
let lang = getLanguageByExtension(fileExtension);
$.get({
url: `/codemirror/mode/${mode}/${mode}.js`,
url: `/codemirror/mode/${lang.file}/${lang.file}.js`,
success: (data) => {
eval(data);
setup(code, mode);
setup(code, lang.mime);
}
});
}
});
// setup
function setup(data, mode) {
function setup(data, mime) {
let el = document.getElementById("editor");
el.value = data;
editor = CodeMirror.fromTextArea(el, {
mode: mode,
mode: mime,
readOnly: true,
autofocus: true,
extraKeys: {

259
modes.js
View File

@ -1,259 +0,0 @@
// let modes = {};
let languages = {
"Brainfuck": {
file: "brainfuck",
mime: "text/x-brainfuck"
},
"C": {
file: "clike",
mime: "text/x-csrc"
},
"C++": {
file: "clike",
mime: "text/x-c++src"
},
"Java": {
file: "clike",
mime: "text/x-java"
},
"C#": {
file: "clike",
mime: "text/x-csharp"
},
"Objective-C": {
file: "clike",
mime: "text/x-objectivec"
},
"Scala": {
file: "clike",
mime: "text/x-scala"
},
"Vertex Shader": {
file: "clike",
mime: "text/x-vertex"
},
"Fragment Shader": {
file: "clike",
mime: "x-shader/x-fragment"
},
"Squirrel": {
file: "clike",
mime: "text/x-squirrel"
},
"Kotlin": {
file: "clike",
mime: "text/x-kotlin"
},
"Ceylon": {
file: "clike",
mime: "text/x-ceylon"
},
"Clojure": {
file: "clojure",
mime: "text/x-clojure"
},
"CMake": {
file: "cmake",
mime: "text/x-cmake"
},
"CoffeeScript": {
file: "coffeescript",
mime: "text/x-coffeescript"
},
"Common Lisp": {
file: "commonlisp",
mime: "text/x-common-lisp"
},
"Crystal": {
file: "crystal",
mime: "text/x-crystal"
},
"CSS": {
file: "css",
mime: "text/x-css"
},
"SCSS": {
file: "css",
mime: "text/x-scss"
},
"Less": {
file: "css",
mime: "text/x-less"
},
"Python": {
file: "python",
mime: "text/x-python"
},
"Cython": {
file: "python",
mime: "text/x-cython"
},
"D": {
file: "d",
mime: "text/x-d"
},
"Dart": {
file: "dart",
mime: "text/x-dart"
},
"Django": {
file: "django",
mime: "text/x-django"
},
"Dockerfile": {
file: "dockerfile",
mime: "text/x-dockerfile"
},
"Elm": {
file: "elm",
mime: "text/x-elm"
},
"Erlang": {
file: "erlang",
mime: "text/x-erlang"
},
"FORTRAN": {
file: "fortran",
mime: "text/x-fortran"
},
"OCaml": {
file: "mllike",
mime: "text/x-ocaml"
},
"F#": {
file: "mllike",
mime: "text/x-fsharp"
},
"Go": {
file: "go",
mime: "text/x-go"
},
"Groovy": {
file: "groovy",
mime: "text/x-groovy"
},
"HAML": {
file: "haml",
mime: "text/x-haml"
},
"Handlebars": {
file: "handlebars",
mime: "text/x-handlebars-template"
},
"Haskell": {
file: "haskell",
mime: "text/x-haskell"
},
"Haxe": {
file: "haxe",
mime: "text/x-haxe"
},
"Hxml": {
file: "haxe",
mime: "text/x-hxml"
},
"EJS": {
file: "htmlembedded",
mime: "text/x-ejs"
},
"ASP.NET": {
file: "htmlembedded",
mime: "text/x-aspx"
},
"JSP": {
file: "htmlembedded",
mime: "text/x-jsp"
},
"ERB": {
file: "htmlembedded",
mime: "text/x-erb"
},
"HTML": {
file: ["xml", "htmlmixed"],
mime: "text/html"
},
"IDL": {
file: "idl",
mime: "text/x-idl"
},
"JavaScript": {
file: "javascipt",
mime: "text/javascript"
},
"TypeScript": {
file: "javascript",
mime: "application/typescript"
},
"Julia": {
file: "julia",
mime: "text/x-julia"
},
"LiveScript": {
file: "livescript",
mime: "text/x-livescript"
},
"Lua": {
file: "lua",
mime: "text/x-lua"
},
"Markdown": {
file: "markdown",
mime: "text/x-markdown"
},
"Mathematica": {
file: "mathematica",
mime: "text/x-mathematica"
},
"NSIS": {
file: "nsis",
mime: "text/x-nsis"
},
"Oz": {
file: "oz",
mime: "text/x-oz"
},
"Pascal": {
file: "pascal",
mime: "text/x-pascal"
},
"Perl": {
file: "perl",
mime: "text/x-perl"
},
"PHP": {
file: "php",
mime: "application/x-httpd-php"
},
"PowerShell": {
file: "powershell",
mime: "application/x-powershell"
},
"Properties": {
file: "proeprties",
mime: "text/x-properties"
},
"INI": {
file: "properties",
mime: "text/x-ini"
},
"ProtoBuf": {
file: "protobuf",
mime: "text/x-protobuf"
}
};
function createMode(extensions, file, mime) {
if (Array.isArray(extensions)) {
for (var i = 0; i < extensions.length; i++) {
modes[extensions[i]] = {
file: file,
mime: mime
};
}
} else if (typeof extensions == "string") {
modes[extensions] = {
file: file,
mime: mime
};
}
}