Skip to content

Commit

Permalink
revert #706, 13e25ad, and 5beb7fd: get rid of the hackish `clean_pand…
Browse files Browse the repository at this point in the history
…oc2_highlight_tags()` method; this is also a much more robust fix to #733
  • Loading branch information
yihui committed Jul 5, 2019
1 parent 9c47c2b commit 52b71f9
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bookdown
Type: Package
Title: Authoring Books and Technical Documents with R Markdown
Version: 0.11.2
Version: 0.11.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("JJ", "Allaire", role = "ctb"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGES IN bookdown VERSION 0.12

## MINOR CHANGES

- Reverted #706 and removed the `clean_highlight_tags` argument in `html_document2()`; **bookdown** will no longer clean up the HTML tags of the syntax-highlighted code blocks.

## BUG FIXES

- The `gitbook` format failed to work with Pandoc 2.7.3 (thanks, @varemo @jwbowers @serine @RLesur, #733).
Expand Down
7 changes: 7 additions & 0 deletions R/gitbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ gitbook = function(
config$post_processor = function(metadata, input, output, clean, verbose) {
if (is.function(post)) output = post(metadata, input, output, clean, verbose)
on.exit(write_search_data(), add = TRUE)

# a hack to remove Pandoc's margin for code blocks since gitbook has already
# defined margin on <pre> (there would be too much bottom margin)
x = read_utf8(output)
x = x[x != 'div.sourceCode { margin: 1em 0; }']
write_utf8(x, output)

move_files_html(output, lib_dir)
output2 = split_chapters(
output, gitbook_page, number_sections, split_by, split_bib, gb_config, split_by
Expand Down
16 changes: 1 addition & 15 deletions R/html.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ tufte_html_book = function(...) {
#' (the i-th figure/table); if \code{FALSE}, figures/tables will be numbered
#' sequentially in the document from 1, 2, ..., and you cannot cross-reference
#' section headers in this case.
#' @param clean_highlight_tags Whether to remove the \verb{<div>} tags around
#' \verb{<pre>}, and clean up \verb{<a>} on all lines in code blocks.
#' @inheritParams pdf_book
#' @return An R Markdown output format object to be passed to
#' \code{rmarkdown::\link{render}()}.
Expand All @@ -123,8 +121,7 @@ tufte_html_book = function(...) {
#' @references \url{https://bookdown.org/yihui/bookdown/}
#' @export
html_document2 = function(
..., number_sections = TRUE, pandoc_args = NULL, base_format = rmarkdown::html_document,
clean_highlight_tags = TRUE
..., number_sections = TRUE, pandoc_args = NULL, base_format = rmarkdown::html_document
) {
base_format = get_base_format(base_format)
config = base_format(
Expand All @@ -137,7 +134,6 @@ html_document2 = function(
x = restore_appendix_html(x, remove = FALSE)
x = restore_part_html(x, remove = FALSE)
x = resolve_refs_html(x, global = !number_sections)
if (clean_highlight_tags) x = clean_pandoc2_highlight_tags(x)
write_utf8(x, output)
output
}
Expand Down Expand Up @@ -267,7 +263,6 @@ split_chapters = function(output, build = build_chapter, number_sections, split_
x = add_section_ids(x)
x = restore_part_html(x)
x = restore_appendix_html(x)
x = clean_pandoc2_highlight_tags(x)

# no (or not enough) tokens found in the template
if (any(c(i1, i2, i3, i4, i5, i6) == 0)) {
Expand Down Expand Up @@ -1008,15 +1003,6 @@ restore_math_labels = function(x) {
x
}

# remove the <div> tags around <pre>, and clean up <a> on all lines
clean_pandoc2_highlight_tags = function(x) {
if (!pandoc2.0()) return(x)
x = gsub('(</code></pre>)</div>', '\\1', x)
x = gsub('<div class="sourceCode"[^>]+>(<pre)', '\\1', x)
x = gsub('<a class="sourceLine"[^>]+>(.*)</a>', '\\1', x)
x
}

# extract a chapter title from the body, and prepend it to the page <title>
prepend_chapter_title = function(head, body) {
r1 = '(.*?<title>)(.+?)(</title>.*)'
Expand Down
5 changes: 1 addition & 4 deletions man/html_document2.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52b71f9

Please sign in to comment.