From ca137f3fd7fd7a98e71e8ce3c063979a10a51e20 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 21 Nov 2025 18:08:05 +0100 Subject: [PATCH 1/4] fix Firefox text selection? --- .../src/theme/CodeBlock/Line/index.tsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx index 80000b80d312..b50c1875b4d3 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx @@ -17,12 +17,13 @@ type Token = Props['line'][number]; // Replaces '\n' by '' // Historical code, not sure why we even need this :/ function fixLineBreak(line: Token[]) { + /* const singleLineBreakToken = line.length === 1 && line[0]!.content === '\n' ? line[0] : undefined; - if (singleLineBreakToken) { return [{...singleLineBreakToken, content: ''}]; } + */ return line; } @@ -51,7 +52,7 @@ export default function CodeBlockLine({ }); return ( - +
{showLineNumbers ? ( <> @@ -60,7 +61,6 @@ export default function CodeBlockLine({ ) : ( lineTokens )} -
-
+
); } From b23b3186c81327e42eaf05c9724f13c42f7067af Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 21 Nov 2025 18:09:38 +0100 Subject: [PATCH 2/4] revert fixlinebreak? --- .../src/theme/CodeBlock/Line/index.tsx | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx index b50c1875b4d3..ea2555921385 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx @@ -12,31 +12,13 @@ import type {Props} from '@theme/CodeBlock/Line'; import styles from './styles.module.css'; -type Token = Props['line'][number]; - -// Replaces '\n' by '' -// Historical code, not sure why we even need this :/ -function fixLineBreak(line: Token[]) { - /* - const singleLineBreakToken = - line.length === 1 && line[0]!.content === '\n' ? line[0] : undefined; - if (singleLineBreakToken) { - return [{...singleLineBreakToken, content: ''}]; - } - */ - - return line; -} - export default function CodeBlockLine({ - line: lineProp, + line, classNames, showLineNumbers, getLineProps, getTokenProps, }: Props): ReactNode { - const line = fixLineBreak(lineProp); - const lineProps = getLineProps({ line, className: clsx(classNames, showLineNumbers && styles.codeLine), From c2ba2e24b4febc81c08026d0a3b09913a061019c Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 21 Nov 2025 18:46:27 +0100 Subject: [PATCH 3/4] revert line break --- .../src/theme/CodeBlock/Line/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx index ea2555921385..526998921fa2 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx @@ -12,6 +12,16 @@ import type {Props} from '@theme/CodeBlock/Line'; import styles from './styles.module.css'; +/* +This
; +} + export default function CodeBlockLine({ line, classNames, @@ -43,6 +53,7 @@ export default function CodeBlockLine({ ) : ( lineTokens )} + ); } From 89f4c361ea9cbfcd20c0cca42f06b6e076bb81a3 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 21 Nov 2025 19:07:26 +0100 Subject: [PATCH 4/4] keep all line break workarounds --- .../src/theme/CodeBlock/Line/index.tsx | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx index 526998921fa2..803c06466eae 100644 --- a/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx +++ b/packages/docusaurus-theme-classic/src/theme/CodeBlock/Line/index.tsx @@ -12,23 +12,36 @@ import type {Props} from '@theme/CodeBlock/Line'; import styles from './styles.module.css'; -/* -This
; } +// Replaces single lines with '\n' by '' so that we don't end up with +// duplicate line breaks (the '\n' + the artificial
above) +// see also https://github.com/facebook/docusaurus/pull/11565 +function fixLineBreak(line: Token[]) { + const singleLineBreakToken = + line.length === 1 && line[0]!.content === '\n' ? line[0] : undefined; + if (singleLineBreakToken) { + return [{...singleLineBreakToken, content: ''}]; + } + return line; +} + export default function CodeBlockLine({ - line, + line: lineProp, classNames, showLineNumbers, getLineProps, getTokenProps, }: Props): ReactNode { + const line = fixLineBreak(lineProp); const lineProps = getLineProps({ line, className: clsx(classNames, showLineNumbers && styles.codeLine),