Issue #11: gist et al. not working; kallithea/public/js/mode/meta_ext.js needs work or rewrite
Reported by: | Bradley Kuhn |
State: | resolved |
Created on: | 2014-07-16 19:36 |
Updated on: | 2014-11-13 22:04 |
Description
The JavaScript for handling extensions and mime types in gist and file editing is currently failing.
We have JavaScript function calls in:
kallithea/templates/admin/gists/*.html kallithea/templates/files/*.html
that fails because we don't have the corresponding implementation. These calls refer to material that would appear in a file that is currently has stubs (see below) in it, called:
kallithea/public/js/mode/meta_ext.js
meta_ext.js relates in some way to stuff we took from upstream CodeMirror, but it doesn't necessarily relate to CodeMirror. Whoever implements this probably should either (a) move the file elsewhere so it isn't confused with Codemirror, or (b) (if the implementer feeling ambitious) provide a solution that is fully upstreamable to the Codemirror project(NOTE: Codemirror is under a non-copyleft license, so if you do want to upstream the neighborly thing to do would be to use the MIT license for that portion and offer it upstream.).
The current meta_ext.js file is some stub data for mapping between file extensions (or patterns) and mime types (similar to /etc/mime.types). (BTW, The exact semantics of patterns that not are extensions seems a bit ambiguous and can probably be left out for now.)
It would be nice if we could auto-generate the list somehow from data that is licensed under a GPLv3-compatible license. (For instance, perhaps CodeMirror already has this data or should have it).
Doing some sort of auto-generation probably would make the who thing cleaner and/or easier to extend. (For example, '.markdown' should be handled as markdown, but only .md are currently.)
Note: we can probably assume that extensions unambiguously maps to at most one mime type. Other patterns might be more ambiguous. Each mime type might have several extensions but one is primary.
We figure to get this working, at least the following items have to be implemented from scratch:
getFilenameAndExt(filename) should be implemented and return a dict with 'filename' and 'ext'.
e.g.: getFilenameAndExt("x.txt") == {"filename": "x", "ext": "txt"}
getExtFromMimeType(mimetype) should be implemented and return the first of the extensions for the mimetype (default to '.txt').
e.g.: getExtFromMimeType("text/html") == ".html"
detectCodeMirrorMode(filename, mimetype) should be implemented and return code mirror mode names like "clike", "css", "javascript", "markdown" or "python". The extension of filename should be used if it is known, if not, the mimetype should be used.
e.g.: detectCodeMirrorMode("x.py", "text/plain") == "python".
(A more complete list of code mirror names can probably be found in codemirror and we must store/calculate it somehow, preferably in a way where this function can be implemented efficiently ... but this function is not performance critical.)
getMimeTypeFromExt(extension) should be implemented.
e.g.: getMimeTypeFromExt("txt") == "text/plain"
This should be tested by making sure all the fancy stuff in these templates/windows works. Templates and other stuff can of course also be tweaked if that is more convenient.
Attachments
Comments
Comment by Bradley Kuhn, on 2014-07-16 19:36
Comment by Bradley Kuhn, on 2014-07-16 19:37
Comment by Mads Kiilerich, on 2014-10-10 14:15
Fix pending on https://bitbucket.org/conservancy/kallithea/pull-request/49/update-codemirror-version-to-46-and-fix , waiting for review by Bradley
Comment by Mads Kiilerich, on 2014-11-13 22:04
pr 56 pushed