keepnote
keepnote copied to clipboard
Enhancement: Open attached file with any extension in keepnote if plaintext
When I attach file to node with extension .txt Keepnote is able to open in in
itself. But when the same file has extension e.g. ".js" Keepnote opens this
attached file in predefined text editor. It would be nice if keepnote could
open attached plain text files, e.g source codes in itself.
Original issue reported on code.google.com by [email protected] on 24 Oct 2014 at 1:34
The only way I could get this to work is to modify "/usr/share/pyshared/keepnote/notebook/init.py". At line 300:
def guess_file_mimetype(filename, default="application/octet-stream"): """Guess the mimetype of a file by its filename""" content_type = mimetypes.guess_type(filename)[0] if content_type is None: return default else: return content_type
I modified it to this:
def guess_file_mimetype(filename, default="text/plain"): """Guess the mimetype of a file by its filename""" content_type = mimetypes.guess_type(filename)[0] if content_type is None: return default else: return content_type
This is, of course, a hack but it works for my use cases. For my notebooks that already had issues with files that were unreadable, in my case those that end in '.nmap' or '.xml', I used a little bash from the notebook root dir:
find ./ -name node.xml -exec sed -i 's/application/octet-stream/text/plain/g' {} ;
This will change all files (including some that shouldn't be) into plain text and viewable in KeepNote. You can replace the "application/octet-stream" with any mime type you'd like to convert a node for. The only other option that seemed to work from "the beginning" of creation of a notebook was to modify /etc/mime.types and add the necessary extensions to "text/plain" or whatever suits best.