Skip to content

Commit 78c1034

Browse files
conico974Nicolas Dorseuil
andauthored
Increase max line length for code highlighting (#3415)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
1 parent c16890a commit 78c1034

File tree

1 file changed

+8
-1
lines changed
  • packages/gitbook/src/components/DocumentView/CodeBlock

1 file changed

+8
-1
lines changed

packages/gitbook/src/components/DocumentView/CodeBlock/highlight.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ export async function highlight(
7777
themes: [theme],
7878
});
7979

80+
let tokenizeMaxLineLength = 400;
81+
// In some cases, people will use unindented code blocks with a single line.
82+
// In this case, we can safely increase the max line length to avoid not highlighting the code.
83+
if (block.nodes.length === 1) {
84+
tokenizeMaxLineLength = 5000;
85+
}
86+
8087
const lines = highlighter.codeToTokensBase(code, {
8188
lang: langName,
8289
theme,
83-
tokenizeMaxLineLength: 400,
90+
tokenizeMaxLineLength,
8491
});
8592

8693
let currentIndex = 0;

0 commit comments

Comments
 (0)