From 1ae437d5d25bee79c35f54d113726ba33afe6564 Mon Sep 17 00:00:00 2001 From: Steven Hall Date: Sat, 13 Apr 2024 15:39:11 +0100 Subject: [PATCH] Test plain highlighting --- .../DocumentView/CodeBlock/highlight.ts | 46 +------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/src/components/DocumentView/CodeBlock/highlight.ts b/src/components/DocumentView/CodeBlock/highlight.ts index c936f5b30..484fa46e0 100644 --- a/src/components/DocumentView/CodeBlock/highlight.ts +++ b/src/components/DocumentView/CodeBlock/highlight.ts @@ -31,51 +31,7 @@ type PositionedToken = ThemedToken & { start: number; end: number }; * Highlight a code block while preserving inline elements. */ export async function highlight(block: DocumentBlockCode): Promise { - const langName = block.data.syntax ? getLanguageForSyntax(block.data.syntax) : null; - if (!langName) { - // Language not found, fallback to plain highlighting - return plainHighlighting(block); - } - - const inlines: InlineIndexed[] = []; - const code = getPlainCodeBlock(block, inlines); - - inlines.sort((a, b) => { - return a.start - b.start; - }); - - const highlighter = await loadHighlighter(); - await loadHighlighterLanguage(langName); - const lines = highlighter.codeToTokensBase(code, { - lang: langName, - }); - let currentIndex = 0; - - return lines.map((tokens, index) => { - const lineBlock = block.nodes[index]; - const result: HighlightToken[] = []; - - const eatToken = (): PositionedToken | null => { - const token = tokens.shift(); - if (token) { - currentIndex += token.content.length; - } - return token - ? { ...token, start: currentIndex - token.content.length, end: currentIndex } - : null; - }; - - while (tokens.length > 0) { - result.push(...matchTokenAndInlines(eatToken, inlines)); - } - - currentIndex += 1; // for the \n - - return { - highlighted: !!lineBlock.data.highlighted, - tokens: result, - }; - }); + return plainHighlighting(block); } /**