Ten years ago, I wrote a piece of JS code to add a button to toggle the visibility of all R code blocks on a HTML page, which partially implemented the code-folding feature. The original code was this:
function toggle_R() { var x = document.getElementsByClassName(‘r’); if (x.length == 0) return; function toggle_vis(o) { var d = o.style.display; o.style.display = (d == ‘block’ || d == “) ? ‘none’:‘block’; } for (i = 0; i < x.length; i++) { var y = x[i]; if …