Skip to content

Commit 37b7756

Browse files
Optimize code blocks for printing
1 parent 9b4633f commit 37b7756

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

docs/userGuide/syntax/code.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,17 @@ A _wrap text_ button can be added to code blocks using the `codeBlockWrapButtons
281281
##### Printing optimization
282282

283283
<div id="code-print-optimization">
284-
Markbind enhances the readability of your code blocks for printing by applying soft wrapping, ensuring code doesn't get cut off. Additionally, line numbers are added to maintain context when wrapping occurs.
284+
Markbind enhances the readability of your code blocks for printing by
285+
286+
- Applying soft wrapping, ensuring code doesn't get cut off
287+
- Adding line numbers to maintain context when wrapping occurs
288+
- Automatically changing dark code theme to light
289+
- Removing [codeBlockCopyButtons]({{baseUrl}}/userGuide/formattingContents.html#copy-button) and [codeBlockWrapButtons]({{baseUrl}}/userGuide/formattingContents.html#wrap-text-button)
290+
291+
<box type="warning" seamless>
292+
There are some issues with printing in Firefox. Please use other browsers such as Chrome if these issues persist.
293+
</box>
294+
285295
</div>
286296
<br>
287297

packages/core-web/src/styles/markbind.css

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import url("../../asset/css/codeblock-light.min.css") print;
2+
13
:root {
24
--sticky-header-height: 0;
35
}
@@ -27,7 +29,7 @@ pre.hljs > code {
2729
background: none;
2830
}
2931

30-
pre > code.hljs {
32+
pre > code.hljs {
3133
background-clip: padding-box;
3234
border-radius: 5px;
3335
counter-reset: line;
@@ -63,24 +65,13 @@ pre > code.hljs[heading] {
6365
display: block;
6466
}
6567

66-
/* switch to light style on print view */
6768
@media print {
6869
pre > code.hljs {
6970
white-space: pre-wrap;
7071
word-wrap: break-word;
7172
word-break: break-all;
7273
}
7374

74-
code.hljs.inline {
75-
background: ghostwhite;
76-
color: #333;
77-
border: 0.5px solid #d4d4d4;
78-
}
79-
80-
code span.highlighted {
81-
background: lavender;
82-
}
83-
8475
.hljs:not(.inline).line-numbers-print > span {
8576
padding: 0 0.5em 0 3.5em;
8677
position: relative;
@@ -102,6 +93,12 @@ pre > code.hljs[heading] {
10293
width: 3em;
10394
height: 100%;
10495
}
96+
97+
/* force printing the highlighting colour */
98+
.hljs span.highlighted{
99+
-webkit-print-color-adjust:exact;
100+
background:#e6e6fa !important;
101+
}
105102
}
106103

107104
kbd {

packages/core/src/plugins/codeBlockCopyButtons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const COPY_ICON = `
2323
`;
2424

2525
function getButtonHTML() {
26-
const html = `<button onclick="copyCodeBlock(this)" class="function-btn">
26+
const html = `<button onclick="copyCodeBlock(this)" class="function-btn d-print-none">
2727
<div class="function-btn-body">
2828
${COPY_ICON}
2929
</div>

packages/core/src/plugins/codeBlockWrapButtons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const WRAP_ICON = `
2828
`;
2929

3030
function getButtonHTML() {
31-
const html = `<button onclick="toggleCodeBlockWrap(this)" class="function-btn">
31+
const html = `<button onclick="toggleCodeBlockWrap(this)" class="function-btn d-print-none">
3232
<div class="function-btn-body">
3333
${WRAP_ICON}
3434
</div>

0 commit comments

Comments
 (0)