From af77bd6474abf4d1f731af281c2d3b34e88b2773 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 27 Apr 2026 22:55:16 -0400 Subject: [PATCH] fix: Uncollapse code when printing (#12193) closes #12192 --- shared/editor/components/Styles.ts | 19 +++++++++++++++++++ shared/editor/nodes/CodeFence.ts | 3 +-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/shared/editor/components/Styles.ts b/shared/editor/components/Styles.ts index 1bc2999774..dd5d8c55a2 100644 --- a/shared/editor/components/Styles.ts +++ b/shared/editor/components/Styles.ts @@ -1893,6 +1893,8 @@ mark { } &::after { + max-height: calc(10 * 1.4em + 0.75em); + overflow: hidden; clip-path: inset(0 0 calc(100% - 10 * 1.4em - 0.75em) 0); } @@ -1913,6 +1915,23 @@ mark { ${props.theme.codeBackground} 100% ); } + + @media print { + pre { + max-height: none; + overflow: visible; + } + + &::after { + max-height: none; + overflow: visible; + clip-path: none; + } + + &::before { + display: none; + } + } } .${EditorStyleHelper.codeBlockToggle} { diff --git a/shared/editor/nodes/CodeFence.ts b/shared/editor/nodes/CodeFence.ts index 0cec74de67..23b9f7eadb 100644 --- a/shared/editor/nodes/CodeFence.ts +++ b/shared/editor/nodes/CodeFence.ts @@ -107,9 +107,8 @@ function buildCollapseState( if (isCollapsed) { const totalLines = (node.textContent.match(/\n/g)?.length ?? 0) + 1; - const cappedLines = Math.min(totalLines, COLLAPSE_LINE_THRESHOLD); const gutterWidth = String(totalLines).length; - const lineNumberText = Array.from({ length: cappedLines }, (_, i) => + const lineNumberText = Array.from({ length: totalLines }, (_, i) => String(i + 1).padStart(gutterWidth, " ") ).join("\n");