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;