diff --git a/R/html.R b/R/html.R index 1bbd2ed65..6e4d7d867 100644 --- a/R/html.R +++ b/R/html.R @@ -1014,6 +1014,16 @@ clean_pandoc2_highlight_tags = function(x) { x = gsub('()', '\\1', x) x = gsub('
]+>(]+>(.*)', '\\1', x) + + css_start = which(x == '') + css_end = vapply(css_start, function(x) style_end[x < style_end][1L], 1L) + css_range = intersect( + unlist(Map(seq, css_start, css_end)), + which(x %in% c("div.sourceCode { margin: 1em 0; }", "pre.sourceCode { margin: 0; }")) + ) + if (length(css_range) > 0) x = x[-css_range] + x } diff --git a/inst/templates/default.html b/inst/templates/default.html index d20f6b347..4f5478913 100644 --- a/inst/templates/default.html +++ b/inst/templates/default.html @@ -98,6 +98,23 @@ margin-left: auto; margin-right: auto; } +pre:not([class]), + pre[class="sourceCode numberSource numberLines"], + pre[class="sourceCode numberSource numberLines lineAnchors"], + pre[class="sourceCode numberSource numberLines line-anchors"], + pre[class="sourceCode numberSource number-lines"], + pre[class="sourceCode numberSource number-lines lineAnchors"], + pre[class="sourceCode numberSource number-lines line-anchors"], + pre[class="sourceCode numberSource lineAnchors numberLines"], + pre[class="sourceCode numberSource lineAnchors number-Lines"], + pre[class="sourceCode numberSource line-anchors numberLines"], + pre[class="sourceCode numberSource line-anchors number-lines"] { + background-color: white; +} +pre.sourceCode { + margin-top: 10px; + margin-bottom: 10px; +} code { color: inherit; background-color: rgba(0, 0, 0, 0.04); diff --git a/inst/templates/gitbook.html b/inst/templates/gitbook.html index d560b3e2f..9f011ef79 100644 --- a/inst/templates/gitbook.html +++ b/inst/templates/gitbook.html @@ -77,6 +77,12 @@ $endif$ + + $for(css)$ $endfor$