File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed
packages/gitbook/src/components/DocumentView/CodeBlock Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " gitbook " : patch
3
+ ---
4
+
5
+ Remove highlighting in Safari for PowerShell and C++ to avoid page crash until next version with bug fix is released
Original file line number Diff line number Diff line change @@ -34,6 +34,8 @@ export type RenderedInline = {
34
34
body : React . ReactNode ;
35
35
} ;
36
36
37
+ const isSafari =
38
+ typeof navigator !== 'undefined' && / ^ ( (? ! c h r o m e | a n d r o i d ) .) * s a f a r i / i. test ( navigator . userAgent ) ;
37
39
const theme = createCssVariablesTheme ( ) ;
38
40
39
41
const { getSingletonHighlighter } = createSingletonShorthands (
@@ -65,8 +67,13 @@ export async function highlight(
65
67
inlines : RenderedInline [ ]
66
68
) : Promise < HighlightLine [ ] > {
67
69
const langName = getBlockLang ( block ) ;
68
- if ( ! langName ) {
69
- // Language not found, fallback to plain highlighting
70
+
71
+ if ( ! langName || ( isSafari && [ 'powershell' , 'cpp' ] . includes ( langName ) ) ) {
72
+ // Fallback to plain highlighting if
73
+ // - language is not found
74
+ // - TEMP : language is PowerShell or C++ and browser is Safari:
75
+ // RegExp#[Symbol.search] throws TypeError when `lastIndex` isn’t writable
76
+ // Fixed in upcoming Safari 18.6, remove when it'll be released - RND-7772
70
77
return plainHighlight ( block , inlines ) ;
71
78
}
72
79
You can’t perform that action at this time.
0 commit comments