Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
publish API to allow manipulating list of allowed mime types for #192
azivnerb09071eb9b71
diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.jsindex f344cd97c6..35391b4266 100644--- a/src/public/javascripts/services/frontend_script_api.js+++ b/src/public/javascripts/services/frontend_script_api.js@@ -5,6 +5,7 @@ import infoService from './info.js';import linkService from './link.js';import treeCache from './tree_cache.js';import noteDetailService from './note_detail.js';+import noteTypeService from './note_type.js';/*** This is the main frontend API interface for scripts. It's published in the local "api" object.@@ -204,6 +205,24 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null) {* @param {function} func - callback called on note change as user is typing (not necessarily tied to save event)*/this.onNoteChange = noteDetailService.onNoteChange;++ /**+ * @method+ * @returns {array} list of default code mime types+ */+ this.getDefaultCodeMimeTypes = noteTypeService.getDefaultCodeMimeTypes;++ /**+ * @method+ * @returns {array} list of currently used code mime types+ */+ this.getCodeMimeTypes = noteTypeService.getCodeMimeTypes;++ /**+ * @method+ * @param {array} types - list of mime types to be used+ */+ this.setCodeMimeTypes = noteTypeService.setCodeMimeTypes;}export default FrontendScriptApi;\ No newline at end of filediff --git a/src/public/javascripts/services/note_type.js b/src/public/javascripts/services/note_type.jsindex f5f3a96791..6a9d2c08b0 100644--- a/src/public/javascripts/services/note_type.js+++ b/src/public/javascripts/services/note_type.js@@ -7,6 +7,43 @@ const $executeScriptButton = $("#execute-script-button");const $toggleEditButton = $('#toggle-edit-button');const $renderButton = $('#render-button');+const DEFAULT_MIME_TYPES = [+ { mime: 'text/x-csrc', title: 'C' },+ { mime: 'text/x-c++src', title: 'C++' },+ { mime: 'text/x-csharp', title: 'C#' },+ { mime: 'text/x-clojure', title: 'Clojure' },+ { mime: 'text/css', title: 'CSS' },+ { mime: 'text/x-dockerfile', title: 'Dockerfile' },+ { mime: 'text/x-erlang', title: 'Erlang' },+ { mime: 'text/x-feature', title: 'Gherkin' },+ { mime: 'text/x-go', title: 'Go' },+ { mime: 'text/x-groovy', title: 'Groovy' },+ { mime: 'text/x-haskell', title: 'Haskell' },+ { mime: 'text/html', title: 'HTML' },+ { mime: 'message/http', title: 'HTTP' },+ { mime: 'text/x-java', title: 'Java' },+ { mime: 'application/javascript;env=frontend', title: 'JavaScript frontend' },+ { mime: 'application/javascript;env=backend', title: 'JavaScript backend' },+ { mime: 'application/json', title: 'JSON' },+ { mime: 'text/x-kotlin', title: 'Kotlin' },+ { mime: 'text/x-stex', title: 'LaTex' },+ { mime: 'text/x-lua', title: 'Lua' },+ { mime: 'text/x-markdown', title: 'Markdown' },+ { mime: 'text/x-objectivec', title: 'Objective C' },+ { mime: 'text/x-pascal', title: 'Pascal' },+ { mime: 'text/x-perl', title: 'Perl' },+ { mime: 'text/x-php', title: 'PHP' },+ { mime: 'text/x-python', title: 'Python' },+ { mime: 'text/x-ruby', title: 'Ruby' },+ { mime: 'text/x-rustsrc', title: 'Rust' },+ { mime: 'text/x-scala', title: 'Scala' },+ { mime: 'text/x-sh', title: 'Shell' },+ { mime: 'text/x-sql', title: 'SQL' },+ { mime: 'text/x-swift', title: 'Swift' },+ { mime: 'text/xml', title: 'XML' },+ { mime: 'text/x-yaml', title: 'YAML' }+];+const noteTypeModel = new NoteTypeModel();function NoteTypeModel() {@@ -15,42 +52,7 @@ function NoteTypeModel() {this.type = ko.observable('text');this.mime = ko.observable('');- this.codeMimeTypes = ko.observableArray([- { mime: 'text/x-csrc', title: 'C' },- { mime: 'text/x-c++src', title: 'C++' },- { mime: 'text/x-csharp', title: 'C#' },- { mime: 'text/x-clojure', title: 'Clojure' },- { mime: 'text/css', title: 'CSS' },- { mime: 'text/x-dockerfile', title: 'Dockerfile' },- { mime: 'text/x-erlang', title: 'Erlang' },- { mime: 'text/x-feature', title: 'Gherkin' },- { mime: 'text/x-go', title: 'Go' },- { mime: 'text/x-groovy', title: 'Groovy' },- { mime: 'text/x-haskell', title: 'Haskell' },- { mime: 'text/html', title: 'HTML' },- { mime: 'message/http', title: 'HTTP' },- { mime: 'text/x-java', title: 'Java' },- { mime: 'application/javascript;env=frontend', title: 'JavaScript frontend' },- { mime: 'application/javascript;env=backend', title: 'JavaScript backend' },- { mime: 'application/json', title: 'JSON' },- { mime: 'text/x-kotlin', title: 'Kotlin' },- { mime: 'text/x-stex', title: 'LaTex' },- { mime: 'text/x-lua', title: 'Lua' },- { mime: 'text/x-markdown', title: 'Markdown' },- { mime: 'text/x-objectivec', title: 'Objective C' },- { mime: 'text/x-pascal', title: 'Pascal' },- { mime: 'text/x-perl', title: 'Perl' },- { mime: 'text/x-php', title: 'PHP' },- { mime: 'text/x-python', title: 'Python' },- { mime: 'text/x-ruby', title: 'Ruby' },- { mime: 'text/x-rustsrc', title: 'Rust' },- { mime: 'text/x-scala', title: 'Scala' },- { mime: 'text/x-sh', title: 'Shell' },- { mime: 'text/x-sql', title: 'SQL' },- { mime: 'text/x-swift', title: 'Swift' },- { mime: 'text/xml', title: 'XML' },- { mime: 'text/x-yaml', title: 'YAML' }- ]);+ this.codeMimeTypes = ko.observableArray(DEFAULT_MIME_TYPES);this.typeString = function() {const type = self.type();@@ -149,5 +151,9 @@ export default {noteTypeModel.mime(mime);noteTypeModel.updateExecuteScriptButtonVisibility();- }+ },++ getDefaultCodeMimeTypes: () => DEFAULT_MIME_TYPES.slice(),+ getCodeMimeTypes: () => noteTypeModel.codeMimeTypes(),+ setCodeMimeTypes: types => noteTypeModel.codeMimeTypes(types)};\ No newline at end of file