Skip to content

Commit 1ae437d

Browse files
committed
Test plain highlighting
1 parent dd28b4b commit 1ae437d

File tree

1 file changed

+1
-45
lines changed

1 file changed

+1
-45
lines changed

src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,51 +31,7 @@ type PositionedToken = ThemedToken & { start: number; end: number };
3131
* Highlight a code block while preserving inline elements.
3232
*/
3333
export async function highlight(block: DocumentBlockCode): Promise<HighlightLine[]> {
34-
const langName = block.data.syntax ? getLanguageForSyntax(block.data.syntax) : null;
35-
if (!langName) {
36-
// Language not found, fallback to plain highlighting
37-
return plainHighlighting(block);
38-
}
39-
40-
const inlines: InlineIndexed[] = [];
41-
const code = getPlainCodeBlock(block, inlines);
42-
43-
inlines.sort((a, b) => {
44-
return a.start - b.start;
45-
});
46-
47-
const highlighter = await loadHighlighter();
48-
await loadHighlighterLanguage(langName);
49-
const lines = highlighter.codeToTokensBase(code, {
50-
lang: langName,
51-
});
52-
let currentIndex = 0;
53-
54-
return lines.map((tokens, index) => {
55-
const lineBlock = block.nodes[index];
56-
const result: HighlightToken[] = [];
57-
58-
const eatToken = (): PositionedToken | null => {
59-
const token = tokens.shift();
60-
if (token) {
61-
currentIndex += token.content.length;
62-
}
63-
return token
64-
? { ...token, start: currentIndex - token.content.length, end: currentIndex }
65-
: null;
66-
};
67-
68-
while (tokens.length > 0) {
69-
result.push(...matchTokenAndInlines(eatToken, inlines));
70-
}
71-
72-
currentIndex += 1; // for the \n
73-
74-
return {
75-
highlighted: !!lineBlock.data.highlighted,
76-
tokens: result,
77-
};
78-
});
34+
return plainHighlighting(block);
7935
}
8036

8137
/**

0 commit comments

Comments
 (0)