mirror of
https://github.com/zadam/trilium.git
synced 2025-11-02 11:26:15 +01:00
fix(highlightjs): unable to match due to init normalization
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import hljs from "../node_modules/highlight.js/es/core.js";
|
||||
import type { MimeType } from "@triliumnext/commons";
|
||||
import { normalizeMimeTypeForCKEditor, type MimeType } from "@triliumnext/commons";
|
||||
import definitions from "./syntax_highlighting.js";
|
||||
import { type HighlightOptions } from "highlight.js";
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function ensureMimeTypes(mimeTypes: MimeType[]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const mime = mimeType.mime;
|
||||
const mime = normalizeMimeTypeForCKEditor(mimeType.mime);
|
||||
if (registeredMimeTypes.has(mime)) {
|
||||
continue;
|
||||
}
|
||||
@@ -25,7 +25,6 @@ export async function ensureMimeTypes(mimeTypes: MimeType[]) {
|
||||
}
|
||||
|
||||
const language = (await loader).default;
|
||||
console.info(`Registered highlighting for ${mime}.`);
|
||||
hljs.registerLanguage(mime, language);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +35,7 @@ export function highlight(code: string, options: HighlightOptions) {
|
||||
}
|
||||
|
||||
if (!registeredMimeTypes.has(options.language)) {
|
||||
console.warn(`Unable to find highlighting for ${code}.`);
|
||||
console.warn(`Unable to find highlighting for ${options.language}.`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { normalizeMimeTypeForCKEditor } from "@triliumnext/commons";
|
||||
import type { LanguageFn } from "highlight.js";
|
||||
|
||||
const byMimeType: Record<string, (Promise<{ default: LanguageFn}> | null)> = {
|
||||
type MimeRecord = Record<string, (Promise<{ default: LanguageFn}> | null)>;
|
||||
|
||||
const byMimeType: MimeRecord = {
|
||||
"text/plain": import("highlight.js/lib/languages/plaintext"),
|
||||
"application/dart": import("highlight.js/lib/languages/dart"),
|
||||
"application/edn": null,
|
||||
@@ -166,4 +169,10 @@ const byMimeType: Record<string, (Promise<{ default: LanguageFn}> | null)> = {
|
||||
"text/xml": import("highlight.js/lib/languages/xml"),
|
||||
}
|
||||
|
||||
export default byMimeType;
|
||||
const normalizedByMimeType: MimeRecord = {};
|
||||
for (const [mimeType, loader] of Object.entries(byMimeType)) {
|
||||
const normalizedMimeType = normalizeMimeTypeForCKEditor(mimeType);
|
||||
normalizedByMimeType[normalizedMimeType] = loader;
|
||||
}
|
||||
|
||||
export default normalizedByMimeType;
|
||||
|
||||
Reference in New Issue
Block a user