Skip to content

Commit 0de8f11

Browse files
authored
Revert and improve change on code block regarding scrolling (#1204)
* Icon will stay on the top right on the block when scrolling * Icon button is lighter by default, and darker on hover
1 parent 2719e5f commit 0de8f11

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: bookdown
22
Type: Package
33
Title: Authoring Books and Technical Documents with R Markdown
4-
Version: 0.22.11
4+
Version: 0.22.12
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("JJ", "Allaire", role = "ctb"),

NEWS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
- In `bs4_book()`, improvement regarding copy button:
44
* It has now a light icon instead of a text with white background (#1192).
55
* It will no more show on output block code when knitr's option is `collapse = FALSE` (#1197).
6-
* For code block with very long line, it will now wrap in the code block with no more x-scroll bar, and it will wraps around the copy button icon so that text is not hidden (#1187).
7-
If you want to customize part of the UI to change this default behavior, you can do it using a custom css with `bs4_book()`.
6+
* It will now be placed correctly on the right side of the code block, with a light color which gets darker on hover so that it is less obtrusive when ovelapping text in block with long lines (#1204). If you want to customize part of the UI to change this default behavior, you can do it using a custom css with `bs4_book()`.
87

98
- Fix an issue with `bs4_book()` where text written using [Line Block](https://bookdown.org/yihui/rmarkdown-cookbook/indent-text.html) was not found in search (thanks, @dmklotz, #1141).
109

inst/resources/bs4_book/bs4_book.css

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,8 @@ code {
378378

379379
pre code {
380380
background-color: transparent;
381-
white-space: pre-wrap;
382-
word-break: break-all;
383-
overflow-wrap: break-word;
381+
word-break: normal; /* force wide blocks to scroll, not wrap */
382+
word-wrap: normal;
384383
}
385384

386385
pre, code {
@@ -395,16 +394,25 @@ code a:any-link {
395394

396395
/* copy button */
397396

398-
pre .copy {
399-
float: right;
397+
div.sourceCode {
398+
position: relative;
399+
}
400+
401+
.btn-copy {
402+
position: absolute;
403+
top: 0rem;
404+
right: -0.5rem; /* coherent with pre margin rule */
405+
}
406+
407+
div.sourceCode > button {
408+
filter: opacity(50%);
400409
}
401410

402-
pre .copy button {
403-
font-size: 80%;
404-
padding: 4px 6px;
411+
div.sourceCode > button:hover {
412+
filter: opacity(100%);
405413
}
406414

407-
pre .copy > button > i.bi::before {
415+
div.sourceCode > button > i.bi::before {
408416
display: inline-block;
409417
height: 1rem;
410418
width: 1rem;
@@ -415,7 +423,7 @@ pre .copy > button > i.bi::before {
415423
background-size: 1rem 1rem;
416424
}
417425

418-
pre .copy > button.btn-copy-checked > .bi::before {
426+
div.sourceCode > button.btn-copy-checked > .bi::before {
419427
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg>');
420428
}
421429

@@ -512,6 +520,11 @@ body {
512520
padding: 1rem;
513521
}
514522

523+
.rmdcaution .btn-copy, .rmdimportant .btn-copy, .rmdnote .btn-copy, .rmdtip .btn-copy, .rmdwarning .btn-copy {
524+
/* Needs to be set according to margin in callout pre block */
525+
right: -1rem;
526+
}
527+
515528
main ul {
516529
list-style-type: square;
517530
}

inst/resources/bs4_book/bs4_book.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,15 @@ function changeTooltipMessage(element, msg) {
107107
$(document).ready(function() {
108108
if(ClipboardJS.isSupported()) {
109109
// Insert copy buttons
110-
var copyButton = "<div class='copy'><button type='button' class='btn btn-copy' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='popover' data-placement='top' data-trigger='hover'><i class='bi'></i></button></div>";
111-
$(copyButton).prependTo("pre.sourceCode");
110+
var copyButton = "<button type='button' class='btn btn-copy' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='popover' data-placement='top' data-trigger='hover'><i class='bi'></i></button>";
111+
$(copyButton).appendTo("div.sourceCode");
112112
// Initialize tooltips:
113113
$('.btn-copy').tooltip({container: 'body', boundary: 'window'});
114114

115115
// Initialize clipboard:
116116
var clipboard = new ClipboardJS('.btn-copy', {
117117
text: function(trigger) {
118-
return trigger.parentNode.nextSibling.textContent;
118+
return trigger.parentNode.textContent;
119119
}
120120
});
121121

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy