mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	refactor(common): rename highlightjs to markdown language code
This commit is contained in:
		| @@ -38,8 +38,8 @@ export function getHighlightJsNameForMime(mimeType: string) { | |||||||
|         for (const mimeType of mimeTypes) { |         for (const mimeType of mimeTypes) { | ||||||
|             // The mime stored by CKEditor is text-x-csrc instead of text/x-csrc so we keep this format for faster lookup. |             // The mime stored by CKEditor is text-x-csrc instead of text/x-csrc so we keep this format for faster lookup. | ||||||
|             const normalizedMime = normalizeMimeTypeForCKEditor(mimeType.mime); |             const normalizedMime = normalizeMimeTypeForCKEditor(mimeType.mime); | ||||||
|             if (mimeType.highlightJs) { |             if (mimeType.mdLanguageCode) { | ||||||
|                 mimeToHighlightJsMapping[normalizedMime] = mimeType.highlightJs; |                 mimeToHighlightJsMapping[normalizedMime] = mimeType.mdLanguageCode; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -3,7 +3,7 @@ | |||||||
| import { parse, Renderer, type Tokens } from "marked"; | import { parse, Renderer, type Tokens } from "marked"; | ||||||
| import htmlSanitizer from "../html_sanitizer.js"; | import htmlSanitizer from "../html_sanitizer.js"; | ||||||
| import importUtils from "./utils.js"; | import importUtils from "./utils.js"; | ||||||
| import { getMimeTypeFromHighlightJs, MIME_TYPE_AUTO } from "@triliumnext/commons"; | import { getMimeTypeFromMarkdownName, MIME_TYPE_AUTO } from "@triliumnext/commons"; | ||||||
| import { ADMONITION_TYPE_MAPPINGS } from "../export/markdown.js"; | import { ADMONITION_TYPE_MAPPINGS } from "../export/markdown.js"; | ||||||
| import utils from "../utils.js"; | import utils from "../utils.js"; | ||||||
| import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons"; | import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons"; | ||||||
| @@ -156,9 +156,9 @@ function renderToHtml(content: string, title: string) { | |||||||
|  |  | ||||||
| function getNormalizedMimeFromMarkdownLanguage(language: string | undefined) { | function getNormalizedMimeFromMarkdownLanguage(language: string | undefined) { | ||||||
|     if (language) { |     if (language) { | ||||||
|         const highlightJsName = getMimeTypeFromHighlightJs(language); |         const mimeDefinition = getMimeTypeFromMarkdownName(language); | ||||||
|         if (highlightJsName) { |         if (mimeDefinition) { | ||||||
|             return normalizeMimeTypeForCKEditor(highlightJsName.mime); |             return normalizeMimeTypeForCKEditor(mimeDefinition.mime); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -8,9 +8,7 @@ export interface MimeTypeDefinition { | |||||||
|     title: string; |     title: string; | ||||||
|     mime: string; |     mime: string; | ||||||
|     /** The name of the language/mime type as defined by highlight.js (or one of the aliases), in order to be used for syntax highlighting such as inside code blocks. */ |     /** The name of the language/mime type as defined by highlight.js (or one of the aliases), in order to be used for syntax highlighting such as inside code blocks. */ | ||||||
|     highlightJs?: string; |     mdLanguageCode?: string; | ||||||
|     /** If specified, will load the corresponding highlight.js file from the `libraries/highlightjs/${id}.js` instead of `node_modules/@highlightjs/cdn-assets/languages/${id}.min.js`. */ |  | ||||||
|     highlightJsSource?: "libraries"; |  | ||||||
|     /** If specified, will load the corresponding highlight file from the given path instead of `node_modules`. */ |     /** If specified, will load the corresponding highlight file from the given path instead of `node_modules`. */ | ||||||
|     codeMirrorSource?: string; |     codeMirrorSource?: string; | ||||||
| } | } | ||||||
| @@ -38,7 +36,7 @@ export function normalizeMimeTypeForCKEditor(mimeType: string) { | |||||||
|  */ |  */ | ||||||
|  |  | ||||||
| export const MIME_TYPES_DICT: readonly MimeTypeDefinition[] = Object.freeze([ | export const MIME_TYPES_DICT: readonly MimeTypeDefinition[] = Object.freeze([ | ||||||
|     { title: "Plain text", mime: "text/plain", highlightJs: "plaintext", default: true }, |     { title: "Plain text", mime: "text/plain", mdLanguageCode: "plaintext", default: true }, | ||||||
|  |  | ||||||
|     // Keep sorted alphabetically. |     // Keep sorted alphabetically. | ||||||
|     { title: "APL", mime: "text/apl" }, |     { title: "APL", mime: "text/apl" }, | ||||||
| @@ -46,183 +44,183 @@ export const MIME_TYPES_DICT: readonly MimeTypeDefinition[] = Object.freeze([ | |||||||
|     { title: "ASP.NET", mime: "application/x-aspx" }, |     { title: "ASP.NET", mime: "application/x-aspx" }, | ||||||
|     { title: "Asterisk", mime: "text/x-asterisk" }, |     { title: "Asterisk", mime: "text/x-asterisk" }, | ||||||
|     { title: "Batch file (DOS)", mime: "application/x-bat", highlightJs: "dos", codeMirrorSource: "libraries/codemirror/batch.js" }, |     { title: "Batch file (DOS)", mime: "application/x-bat", highlightJs: "dos", codeMirrorSource: "libraries/codemirror/batch.js" }, | ||||||
|     { title: "Brainfuck", mime: "text/x-brainfuck", highlightJs: "brainfuck" }, |     { title: "Brainfuck", mime: "text/x-brainfuck", mdLanguageCode: "brainfuck" }, | ||||||
|     { title: "C", mime: "text/x-csrc", highlightJs: "c", default: true }, |     { title: "C", mime: "text/x-csrc", mdLanguageCode: "c", default: true }, | ||||||
|     { title: "C#", mime: "text/x-csharp", highlightJs: "csharp", default: true }, |     { title: "C#", mime: "text/x-csharp", mdLanguageCode: "csharp", default: true }, | ||||||
|     { title: "C++", mime: "text/x-c++src", highlightJs: "cpp", default: true }, |     { title: "C++", mime: "text/x-c++src", mdLanguageCode: "cpp", default: true }, | ||||||
|     { title: "Clojure", mime: "text/x-clojure", highlightJs: "clojure" }, |     { title: "Clojure", mime: "text/x-clojure", mdLanguageCode: "clojure" }, | ||||||
|     { title: "ClojureScript", mime: "text/x-clojurescript" }, |     { title: "ClojureScript", mime: "text/x-clojurescript" }, | ||||||
|     { title: "Closure Stylesheets (GSS)", mime: "text/x-gss" }, |     { title: "Closure Stylesheets (GSS)", mime: "text/x-gss" }, | ||||||
|     { title: "CMake", mime: "text/x-cmake", highlightJs: "cmake" }, |     { title: "CMake", mime: "text/x-cmake", mdLanguageCode: "cmake" }, | ||||||
|     { title: "Cobol", mime: "text/x-cobol" }, |     { title: "Cobol", mime: "text/x-cobol" }, | ||||||
|     { title: "CoffeeScript", mime: "text/coffeescript", highlightJs: "coffeescript" }, |     { title: "CoffeeScript", mime: "text/coffeescript", mdLanguageCode: "coffeescript" }, | ||||||
|     { title: "Common Lisp", mime: "text/x-common-lisp", highlightJs: "lisp" }, |     { title: "Common Lisp", mime: "text/x-common-lisp", mdLanguageCode: "lisp" }, | ||||||
|     { title: "CQL", mime: "text/x-cassandra" }, |     { title: "CQL", mime: "text/x-cassandra" }, | ||||||
|     { title: "Crystal", mime: "text/x-crystal", highlightJs: "crystal" }, |     { title: "Crystal", mime: "text/x-crystal", mdLanguageCode: "crystal" }, | ||||||
|     { title: "CSS", mime: "text/css", highlightJs: "css", default: true }, |     { title: "CSS", mime: "text/css", mdLanguageCode: "css", default: true }, | ||||||
|     { title: "Cypher", mime: "application/x-cypher-query" }, |     { title: "Cypher", mime: "application/x-cypher-query" }, | ||||||
|     { title: "Cython", mime: "text/x-cython" }, |     { title: "Cython", mime: "text/x-cython" }, | ||||||
|     { title: "D", mime: "text/x-d", highlightJs: "d" }, |     { title: "D", mime: "text/x-d", mdLanguageCode: "d" }, | ||||||
|     { title: "Dart", mime: "application/dart", highlightJs: "dart" }, |     { title: "Dart", mime: "application/dart", mdLanguageCode: "dart" }, | ||||||
|     { title: "diff", mime: "text/x-diff", highlightJs: "diff" }, |     { title: "diff", mime: "text/x-diff", mdLanguageCode: "diff" }, | ||||||
|     { title: "Django", mime: "text/x-django", highlightJs: "django" }, |     { title: "Django", mime: "text/x-django", mdLanguageCode: "django" }, | ||||||
|     { title: "Dockerfile", mime: "text/x-dockerfile", highlightJs: "dockerfile" }, |     { title: "Dockerfile", mime: "text/x-dockerfile", mdLanguageCode: "dockerfile" }, | ||||||
|     { title: "DTD", mime: "application/xml-dtd" }, |     { title: "DTD", mime: "application/xml-dtd" }, | ||||||
|     { title: "Dylan", mime: "text/x-dylan" }, |     { title: "Dylan", mime: "text/x-dylan" }, | ||||||
|     { title: "EBNF", mime: "text/x-ebnf", highlightJs: "ebnf" }, |     { title: "EBNF", mime: "text/x-ebnf", mdLanguageCode: "ebnf" }, | ||||||
|     { title: "ECL", mime: "text/x-ecl" }, |     { title: "ECL", mime: "text/x-ecl" }, | ||||||
|     { title: "edn", mime: "application/edn" }, |     { title: "edn", mime: "application/edn" }, | ||||||
|     { title: "Eiffel", mime: "text/x-eiffel" }, |     { title: "Eiffel", mime: "text/x-eiffel" }, | ||||||
|     { title: "Elm", mime: "text/x-elm", highlightJs: "elm" }, |     { title: "Elm", mime: "text/x-elm", mdLanguageCode: "elm" }, | ||||||
|     { title: "Embedded Javascript", mime: "application/x-ejs" }, |     { title: "Embedded Javascript", mime: "application/x-ejs" }, | ||||||
|     { title: "Embedded Ruby", mime: "application/x-erb", highlightJs: "erb" }, |     { title: "Embedded Ruby", mime: "application/x-erb", mdLanguageCode: "erb" }, | ||||||
|     { title: "Erlang", mime: "text/x-erlang", highlightJs: "erlang" }, |     { title: "Erlang", mime: "text/x-erlang", mdLanguageCode: "erlang" }, | ||||||
|     { title: "Esper", mime: "text/x-esper" }, |     { title: "Esper", mime: "text/x-esper" }, | ||||||
|     { title: "F#", mime: "text/x-fsharp", highlightJs: "fsharp" }, |     { title: "F#", mime: "text/x-fsharp", mdLanguageCode: "fsharp" }, | ||||||
|     { title: "Factor", mime: "text/x-factor" }, |     { title: "Factor", mime: "text/x-factor" }, | ||||||
|     { title: "FCL", mime: "text/x-fcl" }, |     { title: "FCL", mime: "text/x-fcl" }, | ||||||
|     { title: "Forth", mime: "text/x-forth" }, |     { title: "Forth", mime: "text/x-forth" }, | ||||||
|     { title: "Fortran", mime: "text/x-fortran", highlightJs: "fortran" }, |     { title: "Fortran", mime: "text/x-fortran", mdLanguageCode: "fortran" }, | ||||||
|     { title: "Gas", mime: "text/x-gas" }, |     { title: "Gas", mime: "text/x-gas" }, | ||||||
|     { title: "GDScript (Godot)", mime: "text/x-gdscript" }, |     { title: "GDScript (Godot)", mime: "text/x-gdscript" }, | ||||||
|     { title: "Gherkin", mime: "text/x-feature", highlightJs: "gherkin" }, |     { title: "Gherkin", mime: "text/x-feature", mdLanguageCode: "gherkin" }, | ||||||
|     { title: "GitHub Flavored Markdown", mime: "text/x-gfm", highlightJs: "markdown" }, |     { title: "GitHub Flavored Markdown", mime: "text/x-gfm", mdLanguageCode: "markdown" }, | ||||||
|     { title: "Go", mime: "text/x-go", highlightJs: "go", default: true }, |     { title: "Go", mime: "text/x-go", mdLanguageCode: "go", default: true }, | ||||||
|     { title: "Groovy", mime: "text/x-groovy", highlightJs: "groovy", default: true }, |     { title: "Groovy", mime: "text/x-groovy", mdLanguageCode: "groovy", default: true }, | ||||||
|     { title: "HAML", mime: "text/x-haml", highlightJs: "haml" }, |     { title: "HAML", mime: "text/x-haml", mdLanguageCode: "haml" }, | ||||||
|     { title: "Haskell (Literate)", mime: "text/x-literate-haskell" }, |     { title: "Haskell (Literate)", mime: "text/x-literate-haskell" }, | ||||||
|     { title: "Haskell", mime: "text/x-haskell", highlightJs: "haskell", default: true }, |     { title: "Haskell", mime: "text/x-haskell", mdLanguageCode: "haskell", default: true }, | ||||||
|     { title: "Haxe", mime: "text/x-haxe", highlightJs: "haxe" }, |     { title: "Haxe", mime: "text/x-haxe", mdLanguageCode: "haxe" }, | ||||||
|     { title: "HTML", mime: "text/html", highlightJs: "xml", default: true }, |     { title: "HTML", mime: "text/html", mdLanguageCode: "xml", default: true }, | ||||||
|     { title: "HTTP", mime: "message/http", highlightJs: "http", default: true }, |     { title: "HTTP", mime: "message/http", mdLanguageCode: "http", default: true }, | ||||||
|     { title: "HXML", mime: "text/x-hxml" }, |     { title: "HXML", mime: "text/x-hxml" }, | ||||||
|     { title: "IDL", mime: "text/x-idl" }, |     { title: "IDL", mime: "text/x-idl" }, | ||||||
|     { title: "Java Server Pages", mime: "application/x-jsp", highlightJs: "java" }, |     { title: "Java Server Pages", mime: "application/x-jsp", mdLanguageCode: "java" }, | ||||||
|     { title: "Java", mime: "text/x-java", highlightJs: "java", default: true }, |     { title: "Java", mime: "text/x-java", mdLanguageCode: "java", default: true }, | ||||||
|     { title: "Jinja2", mime: "text/jinja2" }, |     { title: "Jinja2", mime: "text/jinja2" }, | ||||||
|     { title: "JS backend", mime: "application/javascript;env=backend", highlightJs: "javascript", default: true }, |     { title: "JS backend", mime: "application/javascript;env=backend", mdLanguageCode: "javascript", default: true }, | ||||||
|     { title: "JS frontend", mime: "application/javascript;env=frontend", highlightJs: "javascript", default: true }, |     { title: "JS frontend", mime: "application/javascript;env=frontend", mdLanguageCode: "javascript", default: true }, | ||||||
|     { title: "JSON-LD", mime: "application/ld+json", highlightJs: "json" }, |     { title: "JSON-LD", mime: "application/ld+json", mdLanguageCode: "json" }, | ||||||
|     { title: "JSON", mime: "application/json", highlightJs: "json", default: true }, |     { title: "JSON", mime: "application/json", mdLanguageCode: "json", default: true }, | ||||||
|     { title: "JSX", mime: "text/jsx", highlightJs: "javascript" }, |     { title: "JSX", mime: "text/jsx", mdLanguageCode: "javascript" }, | ||||||
|     { title: "Julia", mime: "text/x-julia", highlightJs: "julia" }, |     { title: "Julia", mime: "text/x-julia", mdLanguageCode: "julia" }, | ||||||
|     { title: "Kotlin", mime: "text/x-kotlin", highlightJs: "kotlin", default: true }, |     { title: "Kotlin", mime: "text/x-kotlin", mdLanguageCode: "kotlin", default: true }, | ||||||
|     { title: "LaTeX", mime: "text/x-latex", highlightJs: "latex" }, |     { title: "LaTeX", mime: "text/x-latex", mdLanguageCode: "latex" }, | ||||||
|     { title: "LESS", mime: "text/x-less", highlightJs: "less" }, |     { title: "LESS", mime: "text/x-less", mdLanguageCode: "less" }, | ||||||
|     { title: "LiveScript", mime: "text/x-livescript", highlightJs: "livescript" }, |     { title: "LiveScript", mime: "text/x-livescript", mdLanguageCode: "livescript" }, | ||||||
|     { title: "Lua", mime: "text/x-lua", highlightJs: "lua" }, |     { title: "Lua", mime: "text/x-lua", mdLanguageCode: "lua" }, | ||||||
|     { title: "MariaDB SQL", mime: "text/x-mariadb", highlightJs: "sql" }, |     { title: "MariaDB SQL", mime: "text/x-mariadb", mdLanguageCode: "sql" }, | ||||||
|     { title: "Markdown", mime: "text/x-markdown", highlightJs: "markdown", default: true }, |     { title: "Markdown", mime: "text/x-markdown", mdLanguageCode: "markdown", default: true }, | ||||||
|     { title: "Mathematica", mime: "text/x-mathematica", highlightJs: "mathematica" }, |     { title: "Mathematica", mime: "text/x-mathematica", mdLanguageCode: "mathematica" }, | ||||||
|     { title: "mbox", mime: "application/mbox" }, |     { title: "mbox", mime: "application/mbox" }, | ||||||
|     { title: "MIPS Assembler", mime: "text/x-asm-mips", highlightJs: "mips" }, |     { title: "MIPS Assembler", mime: "text/x-asm-mips", mdLanguageCode: "mips" }, | ||||||
|     { title: "mIRC", mime: "text/mirc" }, |     { title: "mIRC", mime: "text/mirc" }, | ||||||
|     { title: "Modelica", mime: "text/x-modelica" }, |     { title: "Modelica", mime: "text/x-modelica" }, | ||||||
|     { title: "MS SQL", mime: "text/x-mssql", highlightJs: "sql" }, |     { title: "MS SQL", mime: "text/x-mssql", mdLanguageCode: "sql" }, | ||||||
|     { title: "mscgen", mime: "text/x-mscgen" }, |     { title: "mscgen", mime: "text/x-mscgen" }, | ||||||
|     { title: "msgenny", mime: "text/x-msgenny" }, |     { title: "msgenny", mime: "text/x-msgenny" }, | ||||||
|     { title: "MUMPS", mime: "text/x-mumps" }, |     { title: "MUMPS", mime: "text/x-mumps" }, | ||||||
|     { title: "MySQL", mime: "text/x-mysql", highlightJs: "sql" }, |     { title: "MySQL", mime: "text/x-mysql", mdLanguageCode: "sql" }, | ||||||
|     { title: "Nix", mime: "text/x-nix", highlightJs: "nix" }, |     { title: "Nix", mime: "text/x-nix", mdLanguageCode: "nix" }, | ||||||
|     { title: "Nginx", mime: "text/x-nginx-conf", highlightJs: "nginx" }, |     { title: "Nginx", mime: "text/x-nginx-conf", mdLanguageCode: "nginx" }, | ||||||
|     { title: "NSIS", mime: "text/x-nsis", highlightJs: "nsis" }, |     { title: "NSIS", mime: "text/x-nsis", mdLanguageCode: "nsis" }, | ||||||
|     { title: "NTriples", mime: "application/n-triples" }, |     { title: "NTriples", mime: "application/n-triples" }, | ||||||
|     { title: "Objective-C", mime: "text/x-objectivec", highlightJs: "objectivec" }, |     { title: "Objective-C", mime: "text/x-objectivec", mdLanguageCode: "objectivec" }, | ||||||
|     { title: "OCaml", mime: "text/x-ocaml", highlightJs: "ocaml" }, |     { title: "OCaml", mime: "text/x-ocaml", mdLanguageCode: "ocaml" }, | ||||||
|     { title: "Octave", mime: "text/x-octave" }, |     { title: "Octave", mime: "text/x-octave" }, | ||||||
|     { title: "Oz", mime: "text/x-oz" }, |     { title: "Oz", mime: "text/x-oz" }, | ||||||
|     { title: "Pascal", mime: "text/x-pascal", highlightJs: "delphi" }, |     { title: "Pascal", mime: "text/x-pascal", mdLanguageCode: "delphi" }, | ||||||
|     { title: "PEG.js", mime: "null" }, |     { title: "PEG.js", mime: "null" }, | ||||||
|     { title: "Perl", mime: "text/x-perl", default: true }, |     { title: "Perl", mime: "text/x-perl", default: true }, | ||||||
|     { title: "PGP", mime: "application/pgp" }, |     { title: "PGP", mime: "application/pgp" }, | ||||||
|     { title: "PHP", mime: "text/x-php", default: true }, |     { title: "PHP", mime: "text/x-php", default: true }, | ||||||
|     { title: "Pig", mime: "text/x-pig" }, |     { title: "Pig", mime: "text/x-pig" }, | ||||||
|     { title: "PLSQL", mime: "text/x-plsql", highlightJs: "sql" }, |     { title: "PLSQL", mime: "text/x-plsql", mdLanguageCode: "sql" }, | ||||||
|     { title: "PostgreSQL", mime: "text/x-pgsql", highlightJs: "pgsql" }, |     { title: "PostgreSQL", mime: "text/x-pgsql", mdLanguageCode: "pgsql" }, | ||||||
|     { title: "PowerShell", mime: "application/x-powershell", highlightJs: "powershell" }, |     { title: "PowerShell", mime: "application/x-powershell", mdLanguageCode: "powershell" }, | ||||||
|     { title: "Properties files", mime: "text/x-properties", highlightJs: "properties" }, |     { title: "Properties files", mime: "text/x-properties", mdLanguageCode: "properties" }, | ||||||
|     { title: "ProtoBuf", mime: "text/x-protobuf", highlightJs: "protobuf" }, |     { title: "ProtoBuf", mime: "text/x-protobuf", mdLanguageCode: "protobuf" }, | ||||||
|     { title: "Pug", mime: "text/x-pug" }, |     { title: "Pug", mime: "text/x-pug" }, | ||||||
|     { title: "Puppet", mime: "text/x-puppet", highlightJs: "puppet" }, |     { title: "Puppet", mime: "text/x-puppet", mdLanguageCode: "puppet" }, | ||||||
|     { title: "Python", mime: "text/x-python", highlightJs: "python", default: true }, |     { title: "Python", mime: "text/x-python", mdLanguageCode: "python", default: true }, | ||||||
|     { title: "Q", mime: "text/x-q", highlightJs: "q" }, |     { title: "Q", mime: "text/x-q", mdLanguageCode: "q" }, | ||||||
|     { title: "R", mime: "text/x-rsrc", highlightJs: "r" }, |     { title: "R", mime: "text/x-rsrc", mdLanguageCode: "r" }, | ||||||
|     { title: "reStructuredText", mime: "text/x-rst" }, |     { title: "reStructuredText", mime: "text/x-rst" }, | ||||||
|     { title: "RPM Changes", mime: "text/x-rpm-changes" }, |     { title: "RPM Changes", mime: "text/x-rpm-changes" }, | ||||||
|     { title: "RPM Spec", mime: "text/x-rpm-spec" }, |     { title: "RPM Spec", mime: "text/x-rpm-spec" }, | ||||||
|     { title: "Ruby", mime: "text/x-ruby", highlightJs: "ruby", default: true }, |     { title: "Ruby", mime: "text/x-ruby", mdLanguageCode: "ruby", default: true }, | ||||||
|     { title: "Rust", mime: "text/x-rustsrc", highlightJs: "rust" }, |     { title: "Rust", mime: "text/x-rustsrc", mdLanguageCode: "rust" }, | ||||||
|     { title: "SAS", mime: "text/x-sas", highlightJs: "sas" }, |     { title: "SAS", mime: "text/x-sas", mdLanguageCode: "sas" }, | ||||||
|     { title: "Sass", mime: "text/x-sass" }, |     { title: "Sass", mime: "text/x-sass" }, | ||||||
|     { title: "Scala", mime: "text/x-scala" }, |     { title: "Scala", mime: "text/x-scala" }, | ||||||
|     { title: "Scheme", mime: "text/x-scheme" }, |     { title: "Scheme", mime: "text/x-scheme" }, | ||||||
|     { title: "SCSS", mime: "text/x-scss", highlightJs: "scss" }, |     { title: "SCSS", mime: "text/x-scss", mdLanguageCode: "scss" }, | ||||||
|     { title: "Shell (bash)", mime: "text/x-sh", highlightJs: "bash", default: true }, |     { title: "Shell (bash)", mime: "text/x-sh", mdLanguageCode: "bash", default: true }, | ||||||
|     { title: "Sieve", mime: "application/sieve" }, |     { title: "Sieve", mime: "application/sieve" }, | ||||||
|     { title: "Slim", mime: "text/x-slim" }, |     { title: "Slim", mime: "text/x-slim" }, | ||||||
|     { title: "Smalltalk", mime: "text/x-stsrc", highlightJs: "smalltalk" }, |     { title: "Smalltalk", mime: "text/x-stsrc", mdLanguageCode: "smalltalk" }, | ||||||
|     { title: "Smarty", mime: "text/x-smarty" }, |     { title: "Smarty", mime: "text/x-smarty" }, | ||||||
|     { title: "SML", mime: "text/x-sml", highlightJs: "sml" }, |     { title: "SML", mime: "text/x-sml", mdLanguageCode: "sml" }, | ||||||
|     { title: "Solr", mime: "text/x-solr" }, |     { title: "Solr", mime: "text/x-solr" }, | ||||||
|     { title: "Soy", mime: "text/x-soy" }, |     { title: "Soy", mime: "text/x-soy" }, | ||||||
|     { title: "SPARQL", mime: "application/sparql-query" }, |     { title: "SPARQL", mime: "application/sparql-query" }, | ||||||
|     { title: "Spreadsheet", mime: "text/x-spreadsheet" }, |     { title: "Spreadsheet", mime: "text/x-spreadsheet" }, | ||||||
|     { title: "SQL", mime: "text/x-sql", highlightJs: "sql", default: true }, |     { title: "SQL", mime: "text/x-sql", mdLanguageCode: "sql", default: true }, | ||||||
|     { title: "SQLite (Trilium)", mime: "text/x-sqlite;schema=trilium", highlightJs: "sql", default: true }, |     { title: "SQLite (Trilium)", mime: "text/x-sqlite;schema=trilium", mdLanguageCode: "sql", default: true }, | ||||||
|     { title: "SQLite", mime: "text/x-sqlite", highlightJs: "sql" }, |     { title: "SQLite", mime: "text/x-sqlite", mdLanguageCode: "sql" }, | ||||||
|     { title: "Squirrel", mime: "text/x-squirrel" }, |     { title: "Squirrel", mime: "text/x-squirrel" }, | ||||||
|     { title: "sTeX", mime: "text/x-stex" }, |     { title: "sTeX", mime: "text/x-stex" }, | ||||||
|     { title: "Stylus", mime: "text/x-styl", highlightJs: "stylus" }, |     { title: "Stylus", mime: "text/x-styl", mdLanguageCode: "stylus" }, | ||||||
|     { title: "Swift", mime: "text/x-swift", default: true }, |     { title: "Swift", mime: "text/x-swift", default: true }, | ||||||
|     { title: "SystemVerilog", mime: "text/x-systemverilog" }, |     { title: "SystemVerilog", mime: "text/x-systemverilog" }, | ||||||
|     { title: "Tcl", mime: "text/x-tcl", highlightJs: "tcl" }, |     { title: "Tcl", mime: "text/x-tcl", mdLanguageCode: "tcl" }, | ||||||
|     { title: "Terraform (HCL)", mime: "text/x-hcl", highlightJs: "terraform", highlightJsSource: "libraries", codeMirrorSource: "libraries/codemirror/hcl.js" }, |     { title: "Terraform (HCL)", mime: "text/x-hcl", highlightJs: "terraform", highlightJsSource: "libraries", codeMirrorSource: "libraries/codemirror/hcl.js" }, | ||||||
|     { title: "Textile", mime: "text/x-textile" }, |     { title: "Textile", mime: "text/x-textile" }, | ||||||
|     { title: "TiddlyWiki ", mime: "text/x-tiddlywiki" }, |     { title: "TiddlyWiki ", mime: "text/x-tiddlywiki" }, | ||||||
|     { title: "Tiki wiki", mime: "text/tiki" }, |     { title: "Tiki wiki", mime: "text/tiki" }, | ||||||
|     { title: "TOML", mime: "text/x-toml", highlightJs: "ini" }, |     { title: "TOML", mime: "text/x-toml", mdLanguageCode: "ini" }, | ||||||
|     { title: "Tornado", mime: "text/x-tornado" }, |     { title: "Tornado", mime: "text/x-tornado" }, | ||||||
|     { title: "troff", mime: "text/troff" }, |     { title: "troff", mime: "text/troff" }, | ||||||
|     { title: "TTCN_CFG", mime: "text/x-ttcn-cfg" }, |     { title: "TTCN_CFG", mime: "text/x-ttcn-cfg" }, | ||||||
|     { title: "TTCN", mime: "text/x-ttcn" }, |     { title: "TTCN", mime: "text/x-ttcn" }, | ||||||
|     { title: "Turtle", mime: "text/turtle" }, |     { title: "Turtle", mime: "text/turtle" }, | ||||||
|     { title: "Twig", mime: "text/x-twig", highlightJs: "twig" }, |     { title: "Twig", mime: "text/x-twig", mdLanguageCode: "twig" }, | ||||||
|     { title: "TypeScript-JSX", mime: "text/typescript-jsx" }, |     { title: "TypeScript-JSX", mime: "text/typescript-jsx" }, | ||||||
|     { title: "TypeScript", mime: "application/typescript", highlightJs: "typescript" }, |     { title: "TypeScript", mime: "application/typescript", mdLanguageCode: "typescript" }, | ||||||
|     { title: "VB.NET", mime: "text/x-vb", highlightJs: "vbnet" }, |     { title: "VB.NET", mime: "text/x-vb", mdLanguageCode: "vbnet" }, | ||||||
|     { title: "VBScript", mime: "text/vbscript", highlightJs: "vbscript" }, |     { title: "VBScript", mime: "text/vbscript", mdLanguageCode: "vbscript" }, | ||||||
|     { title: "Velocity", mime: "text/velocity" }, |     { title: "Velocity", mime: "text/velocity" }, | ||||||
|     { title: "Verilog", mime: "text/x-verilog", highlightJs: "verilog" }, |     { title: "Verilog", mime: "text/x-verilog", mdLanguageCode: "verilog" }, | ||||||
|     { title: "VHDL", mime: "text/x-vhdl", highlightJs: "vhdl" }, |     { title: "VHDL", mime: "text/x-vhdl", mdLanguageCode: "vhdl" }, | ||||||
|     { title: "Vue.js Component", mime: "text/x-vue" }, |     { title: "Vue.js Component", mime: "text/x-vue" }, | ||||||
|     { title: "Web IDL", mime: "text/x-webidl" }, |     { title: "Web IDL", mime: "text/x-webidl" }, | ||||||
|     { title: "XML", mime: "text/xml", highlightJs: "xml", default: true }, |     { title: "XML", mime: "text/xml", mdLanguageCode: "xml", default: true }, | ||||||
|     { title: "XQuery", mime: "application/xquery", highlightJs: "xquery" }, |     { title: "XQuery", mime: "application/xquery", mdLanguageCode: "xquery" }, | ||||||
|     { title: "xu", mime: "text/x-xu" }, |     { title: "xu", mime: "text/x-xu" }, | ||||||
|     { title: "Yacas", mime: "text/x-yacas" }, |     { title: "Yacas", mime: "text/x-yacas" }, | ||||||
|     { title: "YAML", mime: "text/x-yaml", highlightJs: "yaml", default: true }, |     { title: "YAML", mime: "text/x-yaml", mdLanguageCode: "yaml", default: true }, | ||||||
|     { title: "Z80", mime: "text/x-z80" } |     { title: "Z80", mime: "text/x-z80" } | ||||||
| ]); | ]); | ||||||
|  |  | ||||||
| let byHighlightJsNameMappings: Record<string, MimeTypeDefinition> | null = null; | let byMarkdownNameMappings: Record<string, MimeTypeDefinition> | null = null; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Given a Highlight.js language tag (e.g. `css`), it returns a corresponding {@link MimeTypeDefinition} if found. |  * Given a Markdown language tag (e.g. `css`), it returns a corresponding {@link MimeTypeDefinition} if found. | ||||||
|  * |  * | ||||||
|  * If there are multiple {@link MimeTypeDefinition}s for the language tag, then only the first one is retrieved. For example for `javascript`, the "JS frontend" mime type is returned. |  * If there are multiple {@link MimeTypeDefinition}s for the language tag, then only the first one is retrieved. For example for `javascript`, the "JS frontend" mime type is returned. | ||||||
|  * |  * | ||||||
|  * @param highlightJsName a language tag. |  * @param mdLanguageCode a language tag. | ||||||
|  * @returns the corresponding {@link MimeTypeDefinition} if found, or `undefined` otherwise. |  * @returns the corresponding {@link MimeTypeDefinition} if found, or `undefined` otherwise. | ||||||
|  */ |  */ | ||||||
| export function getMimeTypeFromHighlightJs(highlightJsName: string) { | export function getMimeTypeFromMarkdownName(mdLanguageCode: string) { | ||||||
|     if (!byHighlightJsNameMappings) { |     if (!byMarkdownNameMappings) { | ||||||
|         byHighlightJsNameMappings = {}; |         byMarkdownNameMappings = {}; | ||||||
|         for (const mimeType of MIME_TYPES_DICT) { |         for (const mimeType of MIME_TYPES_DICT) { | ||||||
|             if (mimeType.highlightJs && !byHighlightJsNameMappings[mimeType.highlightJs]) { |             if (mimeType.mdLanguageCode && !byMarkdownNameMappings[mimeType.mdLanguageCode]) { | ||||||
|                 byHighlightJsNameMappings[mimeType.highlightJs] = mimeType; |                 byMarkdownNameMappings[mimeType.mdLanguageCode] = mimeType; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return byHighlightJsNameMappings[highlightJsName]; |     return byMarkdownNameMappings[mdLanguageCode]; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user