Created
July 20, 2019 04:43
-
-
Save emitanaka/eaa258bb8471c041797ff377704c8505 to your computer and use it in GitHub Desktop.
Collapsible Code Output for `xaringan`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
(function() { | |
var divHTML = document.querySelectorAll(".details-open"); | |
divHTML.forEach(function (el) { | |
var preNodes = el.getElementsByTagName("pre"); | |
var outputNode = preNodes[1]; | |
outputNode.outerHTML = "<details open class='output'><summary>Output</summary>" + outputNode.outerHTML + "</details>"; | |
}) | |
})(); | |
(function() { | |
var divHTML = document.querySelectorAll(".details"); | |
divHTML.forEach(function (el) { | |
var preNodes = el.getElementsByTagName("pre"); | |
var outputNode = preNodes[1]; | |
outputNode.outerHTML = "<details class='output'><summary>Output</summary>" + outputNode.outerHTML + "</details>"; | |
}) | |
})(); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
output: | |
xaringan::moon_reader: | |
includes: | |
after_body: "collapseoutput.js" | |
--- | |
### This output is closed first | |
.details[ | |
```{r} | |
summary(cars) | |
``` | |
] | |
### This output is open first | |
.details-open[ | |
```{r} | |
str(cars) | |
``` | |
] | |
Hey @emitanaka, what tweaks in your code are needed to collapse source code instead of output?
You'll need to change preNodes[1]
to preNodes[0]
in js @ashirwad
When I include this code, I have problems with special characters (e.g., ' %>% )
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@seasmith not for
xaringan
because it's processed byremark.js
instead of Pandoc (from what I understand)