diff --git a/.changeset/frank-doors-smell.md b/.changeset/frank-doors-smell.md new file mode 100644 index 0000000000..399dc02361 --- /dev/null +++ b/.changeset/frank-doors-smell.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Printable collapsed code block diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/ClientCodeBlock.tsx b/packages/gitbook/src/components/DocumentView/CodeBlock/ClientCodeBlock.tsx index 9280a0c27b..b9d79be41d 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/ClientCodeBlock.tsx +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/ClientCodeBlock.tsx @@ -19,6 +19,7 @@ import { plainHighlight } from './plain-highlight'; type ClientBlockProps = Pick, 'block' | 'style'> & { inlines: RenderedInline[]; inlineExprVariables: InlineExpressionVariables; + mode: BlockProps['context']['mode']; }; export const CODE_BLOCK_DEFAULT_COLLAPSED_LINE_COUNT = 10; @@ -28,7 +29,7 @@ export const CODE_BLOCK_DEFAULT_COLLAPSED_LINE_COUNT = 10; * It allows us to defer some load to avoid blocking the rendering of the whole page with block highlighting. */ export function ClientCodeBlock(props: ClientBlockProps) { - const { block, style, inlines, inlineExprVariables } = props; + const { block, mode, style, inlines, inlineExprVariables } = props; const blockRef = useRef(null); const isInViewportRef = useRef(false); const [isInViewport, setIsInViewport] = useState(false); @@ -123,7 +124,9 @@ export function ClientCodeBlock(props: ClientBlockProps) { const numberOfLinesOfCode = lines?.length ?? plainLines.length; const collapsedLineCount = block.data.collapsedLineCount || CODE_BLOCK_DEFAULT_COLLAPSED_LINE_COUNT; - const isExpandable = Boolean(expandable && numberOfLinesOfCode > collapsedLineCount); + const isExpandable = Boolean( + expandable && mode !== 'print' && numberOfLinesOfCode > collapsedLineCount + ); const codeBlockBodyId = useId(); diff --git a/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlock.tsx b/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlock.tsx index 43e6f7efbe..6ef4ee8cf2 100644 --- a/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlock.tsx +++ b/packages/gitbook/src/components/DocumentView/CodeBlock/CodeBlock.tsx @@ -73,6 +73,7 @@ export async function CodeBlock(props: BlockProps) { style={style} inlines={richInlines} inlineExprVariables={variables} + mode={context.mode} /> );