From 78c10340e792f2ab5a99f14030e217f4abcbc679 Mon Sep 17 00:00:00 2001 From: conico974 Date: Thu, 3 Jul 2025 13:05:42 +0200 Subject: [PATCH] Increase max line length for code highlighting (#3415) Co-authored-by: Nicolas Dorseuil --- .../src/components/DocumentView/CodeBlock/highlight.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts index 89d00dafb..c9f596034 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts @@ -77,10 +77,17 @@ export async function highlight( themes: [theme], }); + let tokenizeMaxLineLength = 400; + // In some cases, people will use unindented code blocks with a single line. + // In this case, we can safely increase the max line length to avoid not highlighting the code. + if (block.nodes.length === 1) { + tokenizeMaxLineLength = 5000; + } + const lines = highlighter.codeToTokensBase(code, { lang: langName, theme, - tokenizeMaxLineLength: 400, + tokenizeMaxLineLength, }); let currentIndex = 0;