import { ensureMimeTypes, highlight, highlightAuto, loadTheme, Themes, type AutoHighlightResult, type HighlightResult, type Theme } from "@triliumnext/highlightjs"; import mime_types from "./mime_types.js"; import options from "./options.js"; import { t } from "./i18n.js"; import { copyText, copyTextWithToast } from "./clipboard_ext.js"; import { isShare } from "./utils.js"; import { MimeType } from "@triliumnext/commons"; let highlightingLoaded = false; /** * Identifies all the code blocks (as `pre code`) under the specified hierarchy and uses the highlight.js library to obtain the highlighted text which is then applied on to the code blocks. * Additionally, adds a "Copy to clipboard" button. * * @param $container the container under which to look for code blocks and to apply syntax highlighting to them. */ export async function formatCodeBlocks($container: JQuery) { const syntaxHighlightingEnabled = isSyntaxHighlightEnabled(); const codeBlocks = $container.find("pre code"); for (const codeBlock of codeBlocks) { const normalizedMimeType = extractLanguageFromClassList(codeBlock); if (!normalizedMimeType) { continue; } applyCopyToClipboardButton($(codeBlock)); if (syntaxHighlightingEnabled) { applySingleBlockSyntaxHighlight($(codeBlock), normalizedMimeType); } } } export function applyCopyToClipboardButton($codeBlock: JQuery) { const $copyButton = $("