export file with correct file extension, if possible

This commit is contained in:
ansuz 2016-07-25 11:26:42 +02:00
parent 5e71a5473c
commit efd190beca
2 changed files with 51 additions and 32 deletions

View File

@ -102,19 +102,6 @@ define([
editor.setOption('readOnly', !bool);
};
var exportText = module.exportText = function () {
var text = editor.getValue();
Cryptpad.prompt(Messages.exportPrompt,
document.title, function (filename) {
if (filename === null) { return; }
var blob = new Blob([text], {
type: 'text/plain;charset=utf-8'
});
saveAs(blob, filename);
});
};
var userList = {}; // List of pretty name of all users (mapped with their server ID)
var toolbarList; // List of users still connected to the channel (server IDs)
var addToUserList = function(data) {
@ -246,6 +233,22 @@ define([
}
};
var exportText = module.exportText = function () {
var text = editor.getValue();
var ext = Modes.extensionOf(module.highlightMode);
var title = Cryptpad.fixFileName(suggestName()) + ext;
Cryptpad.prompt(Messages.exportPrompt, title, function (filename) {
if (filename === null) { return; }
var blob = new Blob([text], {
type: 'text/plain;charset=utf-8'
});
saveAs(blob, filename);
});
};
var onInit = config.onInit = function (info) {
//Cryptpad.warn("Initializing realtime session...");
var $bar = $('#pad-iframe')[0].contentWindow.$('#cme_toolbox');
@ -279,7 +282,7 @@ define([
var mode = mime && mime.mode || null;
if (Modes.some(function (o) { return o.mode === mode; })) {
if (Modes.list.some(function (o) { return o.mode === mode; })) {
setMode(mode);
$bar.find('#language-mode').val(mode);
} else {
@ -337,7 +340,7 @@ define([
/* Let the user select different syntax highlighting modes */
var syntaxDropdown = '<select title="syntax highlighting" id="language-mode">\n' +
Modes.map(function (o) {
Modes.list.map(function (o) {
var selected = o.mode === lastLanguage? ' selected="selected"' : '';
return '<option value="' + o.mode + '"'+selected+'>' + o.language + '</option>';
}).join('\n') +

View File

@ -1,10 +1,13 @@
define(function () {
return [
"apl apl",
var Modes = {};
// mode language (extension)
var list = Modes.list = [
"apl apl .apl",
"asciiarmor asciiarmor",
"asn.1 asn.1",
"asterisk asterisk",
"brainfuck brainfuck",
"brainfuck brainfuck .b",
"clike clike",
"clojure clojure",
"cmake cmake",
@ -12,7 +15,7 @@ define(function () {
"coffeescript coffeescript",
"commonlisp commonlisp",
"crystal crystal",
"css css",
"css css .css",
"cypher cypher",
"d d",
"dart dart",
@ -24,36 +27,36 @@ define(function () {
"ebnf ebnf",
"ecl ecl",
"eiffel eiffel",
"elm elm",
"elm elm .elm",
"erlang erlang",
"factor factor",
"fcl fcl",
"forth forth",
"fortran fortran",
"gas gas",
"gfm gfm",
"gfm gfm .md",
"gherkin gherkin",
"go go",
"groovy groovy",
"haml haml",
"handlebars handlebars",
"haskell haskell",
"haskell haskell .hs",
"haskell-literate haskell-literate",
"haxe haxe",
"htmlembedded htmlembedded",
"htmlmixed htmlmixed",
"htmlmixed htmlmixed .html",
"http http",
"idl idl",
"index.html index.html",
"jade jade",
"javascript javascript",
"javascript javascript .js",
"jinja2 jinja2",
"jsx jsx",
"jsx jsx .jsx",
"julia julia",
"livescript livescript",
"loadmode.js loadmode.js",
"lua lua",
"markdown markdown",
"markdown markdown .md",
"mathematica mathematica",
"meta.js meta.js",
"mirc mirc",
@ -74,7 +77,7 @@ define(function () {
"properties properties",
"protobuf protobuf",
"puppet puppet",
"python python",
"python python .py",
"q q",
"r r",
"rpm rpm",
@ -82,8 +85,8 @@ define(function () {
"ruby ruby",
"rust rust",
"sass sass",
"scheme scheme",
"shell shell",
"scheme scheme .scm",
"shell shell .sh",
"sieve sieve",
"slim slim",
"smalltalk smalltalk",
@ -97,7 +100,7 @@ define(function () {
"stylus stylus",
"swift swift",
"tcl tcl",
"text text",
"text text .txt",
"textile textile",
"tiddlywiki tiddlywiki",
"tiki tiki",
@ -117,14 +120,27 @@ define(function () {
"xml xml",
//"xwiki xwiki21",
"xquery xquery",
"yaml yaml",
"yaml yaml .yaml",
"yaml-frontmatter yaml-frontmatter",
"z80 z80"
].map(function (line) {
var kv = line.split(/\s/);
return {
language: kv[0].replace(/_/g, ' '),
mode: kv[1]
mode: kv[1],
ext: kv[2],
};
});
var extensionOf = Modes.extensionOf = function (mode) {
var ext = '';
list.some(function (o) {
if (o.mode !== mode) { return; }
ext = o.ext || '';
return true;
});
return ext;
};
return Modes;
});