Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc87225

Browse files
maellecderv
andauthored
bs4_book: no scroll on x overflow and correct copy btn placement (#1187)
This follows the work done in pkgdown. Co-authored-by: christophe dervieux <[email protected]>
1 parent fc329f7 commit dc87225

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
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.10
4+
Version: 0.22.11
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
77
person("JJ", "Allaire", role = "ctb"),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
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()`.
68

79
- 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).
810

inst/resources/bs4_book/bs4_book.css

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

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

385386
pre, code {
@@ -395,9 +396,7 @@ code a:any-link {
395396
/* copy button */
396397

397398
pre .copy {
398-
position: absolute;
399-
top: 0.5rem;
400-
right: 0.5rem;
399+
float: right;
401400
}
402401

403402
pre .copy button {

inst/resources/bs4_book/bs4_book.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,14 @@ $(document).ready(function() {
108108
if(ClipboardJS.isSupported()) {
109109
// Insert copy buttons
110110
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).appendTo("pre.sourceCode");
111+
$(copyButton).prependTo("pre.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.previousSibling.textContent;
118+
return trigger.parentNode.nextSibling.textContent;
119119
}
120120
});
121121

0 commit comments

Comments
 (0)