Skip to content

Instantly share code, notes, and snippets.

@favstats
Forked from emitanaka/collapseoutput.js
Last active July 13, 2021 09:40
Show Gist options
  • Save favstats/301afa21c192be4f32d9d4eb2f263f8d to your computer and use it in GitHub Desktop.
Save favstats/301afa21c192be4f32d9d4eb2f263f8d to your computer and use it in GitHub Desktop.
Collapsible Code Output for `xaringan`
<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>Run</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>Run</summary>" + outputNode.outerHTML + "</details>";
})
})();
</script>
---
output:
xaringan::moon_reader:
includes:
after_body: "collapseoutput.js"
---
### "Run" code in your slides!
.details[
```{r}
summary(cars)
```
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment