From 734c1bd9c6902891e1bdabfecd0108a223b3368f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 6 Oct 2020 12:07:32 +0200 Subject: [PATCH 01/53] add an argument defaulting to FALSE and check for downlit package --- R/html_document.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/R/html_document.R b/R/html_document.R index 2c23dbf2b4..6e74038052 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -193,6 +193,7 @@ html_document <- function(toc = FALSE, self_contained = TRUE, theme = "default", highlight = "default", + highlight_downlit = FALSE, mathjax = "default", template = "default", extra_dependencies = NULL, @@ -278,7 +279,13 @@ html_document <- function(toc = FALSE, } # highlight - args <- c(args, pandoc_html_highlight_args(template, highlight)) + if (highlight_downlit) { + if (!requireNamespace("downlit", quietly = TRUE)) { + warning("highlight_downlit=TRUE requires the downlit package", + "downlit highlighting won't be apply", + "and no linking will be done.", call. = FALSE) + highlight_downlit <- FALSE + } # add highlight.js html_dependency if required extra_dependencies <- append( From c89fc5c098854be0b864fe1620a386ef3f9776b6 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 6 Oct 2020 12:09:19 +0200 Subject: [PATCH 02/53] if using downlit, default to pygments and not highlight.js --- R/html_document.R | 3 +++ R/pandoc.R | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index 6e74038052..6451822492 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -286,6 +286,9 @@ html_document <- function(toc = FALSE, "and no linking will be done.", call. = FALSE) highlight_downlit <- FALSE } + args <- c(args, + pandoc_html_highlight_args(template, highlight, highlight_downlit) + ) # add highlight.js html_dependency if required extra_dependencies <- append( diff --git a/R/pandoc.R b/R/pandoc.R index 9eca78c7bd..3784bf19e6 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -551,14 +551,14 @@ unix_mathjax_path <- function() { pandoc_html_highlight_args <- function(template, - highlight) { + highlight, highlight_downlit = FALSE) { args <- c() if (is.null(highlight)) { args <- c(args, "--no-highlight") } - else if (!identical(template, "default")) { + else if (highlight_downlit || !identical(template, "default")) { if (identical(highlight, "default")) highlight <- "pygments" args <- c(args, "--highlight-style", highlight) From f2c88921ec944e14ce4fc035f2121bd4b921c8b1 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 6 Oct 2020 12:16:36 +0200 Subject: [PATCH 03/53] Add downlit as post-processing step --- R/html_document.R | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/R/html_document.R b/R/html_document.R index 6451822492..2dbef884a2 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -444,6 +444,17 @@ html_document <- function(toc = FALSE, args } + # post-processor that use the output file from pandoc + post_processor <- function(metadata, input_file, output_file, clean, verbose) { + + # add a post processor for syntax highlighting with downlit if requested + if (highlight_downlit) { + output_file <- downlit::downlit_html_path(output_file, output_file) + } + + output_file + } + # return format output_format( knitr = knitr_options_html(fig_width, fig_height, fig_retina, keep_md, dev), @@ -456,6 +467,7 @@ html_document <- function(toc = FALSE, pre_knit = pre_knit, post_knit = post_knit, pre_processor = pre_processor, + post_processor = post_processor, on_exit = on_exit, base_format = html_document_base(theme = theme, self_contained = self_contained, From b666a2a84b4ca02d20291a335b0351d01ab22ea9 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 6 Oct 2020 12:18:30 +0200 Subject: [PATCH 04/53] missing bracket --- R/html_document.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/html_document.R b/R/html_document.R index 2dbef884a2..5ae982c65b 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -285,6 +285,7 @@ html_document <- function(toc = FALSE, "downlit highlighting won't be apply", "and no linking will be done.", call. = FALSE) highlight_downlit <- FALSE + } } args <- c(args, pandoc_html_highlight_args(template, highlight, highlight_downlit) From 6cc19895daf0ae374ea71927e26ab85cfca402f8 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 29 Oct 2020 15:58:18 +0100 Subject: [PATCH 05/53] use dev downlit for Pandoc highlighting support --- DESCRIPTION | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 98b8df6017..d1f75eb3cf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -101,7 +101,8 @@ Suggests: vctrs, tibble, fs, - rsconnect + rsconnect, + downlit (>= 0.2.0.9000) SystemRequirements: pandoc (>= 1.14) - http://pandoc.org URL: https://github.com/rstudio/rmarkdown BugReports: https://github.com/rstudio/rmarkdown/issues @@ -109,3 +110,4 @@ License: GPL-3 RoxygenNote: 7.1.1 Encoding: UTF-8 VignetteBuilder: knitr +Remotes: r-lib/downlit From b20a651666b42ebc5a769b5fe8e8231e0d40c074 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 29 Oct 2020 15:59:50 +0100 Subject: [PATCH 06/53] Correct wording. --- R/html_document.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index 5ae982c65b..b44f983cb8 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -282,8 +282,8 @@ html_document <- function(toc = FALSE, if (highlight_downlit) { if (!requireNamespace("downlit", quietly = TRUE)) { warning("highlight_downlit=TRUE requires the downlit package", - "downlit highlighting won't be apply", - "and no linking will be done.", call. = FALSE) + "downlit highlighting won't be applied", + "and no function linking will be done.", call. = FALSE) highlight_downlit <- FALSE } } From dbc9c4331a92a2f2e692b3f8e1f0e1b6804a4f6f Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 10:52:01 +0100 Subject: [PATCH 07/53] use xfun here --- R/html_document.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/html_document.R b/R/html_document.R index b44f983cb8..10cb121233 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -280,7 +280,7 @@ html_document <- function(toc = FALSE, # highlight if (highlight_downlit) { - if (!requireNamespace("downlit", quietly = TRUE)) { + if (!xfun::loadable("downlit")) { warning("highlight_downlit=TRUE requires the downlit package", "downlit highlighting won't be applied", "and no function linking will be done.", call. = FALSE) From 559f5f8854b146d4a1d212c67849299b48b42a8a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 11:03:52 +0100 Subject: [PATCH 08/53] Add tests for pandoc syntax highlighting argument --- tests/testthat/test-pandoc.R | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/testthat/test-pandoc.R diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R new file mode 100644 index 0000000000..50db57d6ae --- /dev/null +++ b/tests/testthat/test-pandoc.R @@ -0,0 +1,21 @@ +test_that("Correct syntax highlighting argument as requested", { + expect_equal(pandoc_html_highlight_args("default", NULL), "--no-highlight") + expect_equal(pandoc_html_highlight_args("dummy.html", NULL), "--no-highlight") + expect_equal(pandoc_html_highlight_args("dummy.html", "default"), + c("--highlight-style", "pygments")) + expect_equal(pandoc_html_highlight_args("dummy.html", "zenburn"), + c("--highlight-style", "zenburn")) + expect_equal(pandoc_html_highlight_args("default", "breezedark"), + c("--highlight-style", "breezedark")) + expect_equal(pandoc_html_highlight_args("default", "default"), + c("--no-highlight", "--variable", "highlightjs=1")) + expect_equal(pandoc_html_highlight_args("default", "default", + highlight_downlit = TRUE), + c("--highlight-style", "pygments")) + expect_equal(pandoc_html_highlight_args("dummy.html", "default", + highlight_downlit = TRUE), + c("--highlight-style", "pygments")) + expect_equal(pandoc_html_highlight_args("default", "tango", + highlight_downlit = TRUE), + c("--highlight-style", "tango")) +}) From e35a921f172b3a7fbb11902a67f4f1800dda806c Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 11:05:04 +0100 Subject: [PATCH 09/53] style and add comment about the current logic --- R/pandoc.R | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/R/pandoc.R b/R/pandoc.R index 3784bf19e6..669f4ec22c 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -551,25 +551,26 @@ unix_mathjax_path <- function() { pandoc_html_highlight_args <- function(template, - highlight, highlight_downlit = FALSE) { - + highlight, + highlight_downlit = FALSE) { args <- c() - if (is.null(highlight)) { + # deactivate all highlighting if requesting args <- c(args, "--no-highlight") - } - else if (highlight_downlit || !identical(template, "default")) { - if (identical(highlight, "default")) - highlight <- "pygments" + } else if (highlight_downlit || !identical(template, "default")) { + # Use requested pandoc highlighting for non default pandoc template or if + # downlit is requested + if (identical(highlight, "default")) highlight <- "pygments" args <- c(args, "--highlight-style", highlight) - } - else { + } else { + # for default template only - Pandoc .theme file not supported highlight <- match.arg(highlight, html_highlighters()) if (is_highlightjs(highlight)) { + # use highlightjs by default and not pandoc highlighting args <- c(args, "--no-highlight") args <- c(args, "--variable", "highlightjs=1") - } - else { + } else { + # or specified highlight style args <- c(args, "--highlight-style", highlight) } } From eb1e04d4a963324ca9cdbd928b1fd9e091376c03 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 11:07:15 +0100 Subject: [PATCH 10/53] explicitly add the pandoc classes from downlit --- R/html_document.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/html_document.R b/R/html_document.R index 10cb121233..7182a45c71 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -450,7 +450,8 @@ html_document <- function(toc = FALSE, # add a post processor for syntax highlighting with downlit if requested if (highlight_downlit) { - output_file <- downlit::downlit_html_path(output_file, output_file) + output_file <- downlit::downlit_html_path(output_file, output_file, + classes = downlit::classes_pandoc()) } output_file From e7bfead4c3c608e483a49fde1f733c9f7bf2e435 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 11:40:58 +0100 Subject: [PATCH 11/53] style --- R/html_document.R | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index 7182a45c71..f62094e333 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -278,7 +278,7 @@ html_document <- function(toc = FALSE, ) } - # highlight + # highlighting --------- if (highlight_downlit) { if (!xfun::loadable("downlit")) { warning("highlight_downlit=TRUE requires the downlit package", @@ -450,8 +450,10 @@ html_document <- function(toc = FALSE, # add a post processor for syntax highlighting with downlit if requested if (highlight_downlit) { - output_file <- downlit::downlit_html_path(output_file, output_file, - classes = downlit::classes_pandoc()) + output_file <- downlit::downlit_html_path( + output_file, output_file, + classes = downlit::classes_pandoc() + ) } output_file From 41ee41fb910ab1ca16bdf0f456d0dbf72e01847b Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 11:45:28 +0100 Subject: [PATCH 12/53] typo --- R/md_document.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/md_document.R b/R/md_document.R index 95f577c111..cf2acbfdf5 100644 --- a/R/md_document.R +++ b/R/md_document.R @@ -22,7 +22,7 @@ #' widely used retina displays, but will also result in the output of #' \code{} tags rather than markdown images due to the need to set the #' width of the image explicitly. -#' @param ext Extention of the output document (defaults to ".md"). +#' @param ext Extension of the output document (defaults to ".md"). #' @return R Markdown output format to pass to \code{\link{render}} #' @examples #' \dontrun{ From 5fe312a3454f4c386b89ec12e75841188839589a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2020 12:58:39 +0100 Subject: [PATCH 13/53] separate highlight logic to add specific css in template --- R/pandoc.R | 10 +++++++--- inst/rmd/h/default.html | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/R/pandoc.R b/R/pandoc.R index 669f4ec22c..e0d82291c0 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -557,9 +557,13 @@ pandoc_html_highlight_args <- function(template, if (is.null(highlight)) { # deactivate all highlighting if requesting args <- c(args, "--no-highlight") - } else if (highlight_downlit || !identical(template, "default")) { - # Use requested pandoc highlighting for non default pandoc template or if - # downlit is requested + } else if (highlight_downlit) { + # use pandoc highlight and add custom css + if (identical(highlight, "default")) highlight <- "pygments" + args <- c(args, "--highlight-style", highlight) + args <- c(args, "--variable", "highlight-downlit=1") + } else if (!identical(template, "default")) { + # Use requested pandoc highlighting for non default pandoc template if (identical(highlight, "default")) highlight <- "pygments" args <- c(args, "--highlight-style", highlight) } else { diff --git a/inst/rmd/h/default.html b/inst/rmd/h/default.html index f96d5135a6..1e3281cac8 100644 --- a/inst/rmd/h/default.html +++ b/inst/rmd/h/default.html @@ -62,6 +62,17 @@ $endif$ +$if(highlight-downlit)$ + +$endif$ + $if(highlighting-css)$ +#' $endif$} +#' #'@section Navigation Bars: #' #' If you have a set of html documents which you'd like to provide a common @@ -169,16 +218,19 @@ #' Note however that if you choose not to use the "default" HTML template then #' several aspects of HTML document rendering will behave differently: #' -#' \itemize{ \item{The \code{theme} parameter does not work (you can still -#' provide styles using the \code{css} parameter). } \item{For the -#' \code{highlight} parameter, the default highlighting style will resolve to -#' "pygments" and the "textmate" highlighting style is not available } -#' \item{The \code{toc_float} parameter will not work. } \item{The -#' \code{code_folding} parameter will not work. } \item{Tabbed sections (as -#' described above) will not work.} \item{Navigation bars (as described above) -#' will not work. }\item{MathJax will not work if \code{self_contained} is -#' \code{TRUE} (these two options can't be used together in normal pandoc -#' templates). } } +#' \itemize{ +#' \item{The \code{theme} parameter does not work (you can still provide styles +#' using the \code{css} parameter). } +#' \item{For the \code{highlight} parameter, the default highlighting engine +#' will resolve to Pandoc instead of highlightjs and highlighting style will default to +#' "pygments". "textmate" style is not available as related to highlightjs} +#' \item{The \code{toc_float} parameter will not work. } +#' \item{The \code{code_folding} parameter will not work. } +#' \item{Tabbed sections (as described above) will not work.} +#' \item{Navigation bars (as described above) will not work. } +#' \item{MathJax will not work if \code{self_contained} is \code{TRUE} (these +#' two options can't be used together in normal pandoc templates). } +#' } #' #' Due to the above restrictions, you might consider using the \code{includes} #' parameter as an alternative to providing a fully custom template. diff --git a/R/pandoc.R b/R/pandoc.R index eb7e67b7df..fbe6dc9547 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -586,12 +586,15 @@ pandoc_html_highlight_args <- function(template, } args <- c( pandoc_highlight_args(highlight, default = resolve_highlight("a11y")), + # variable used to insert some css in a Pandoc template pandoc_variable_arg("highlight-downlit") ) } else if (is_highlightjs(highlight) || (highlight == "default" && template == "default")) { # highlightjs engine args <- c(pandoc_highlight_args(NULL), + # variable used to insert some css and js + # in the Pandoc default template pandoc_variable_arg("highlightjs", "1")) } else { # Pandoc engine diff --git a/man/html_document.Rd b/man/html_document.Rd index 0b1f89d5a1..16852898e4 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -99,8 +99,11 @@ its size).} "sandstone", "simplex", or "yeti"). Pass \code{NULL} for no theme (in this case you can use the \code{css} parameter to add your own styles).} -\item{highlight}{Syntax highlight engine and style. "default" (and "textmate") - will use highlightjs as syntax highlighting engine instead of Pandoc. +\item{highlight}{Syntax highlight engine and style. See the + \emph{Highlighting} section below for details. + + "default" (and "textmate") will use highlightjs as syntax highlighting + engine instead of Pandoc. Any other value will be passed to Pandoc's \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting @@ -109,7 +112,8 @@ style}. Pandoc's built-in styles include "tango", "pygments", "kate", themes are also included, "a11y", for accessible color scheme and "rstudio", to replicate RStudio editor theme. - Pass \code{NULL} to prevent syntax highlighting.} + Pass \code{NULL} to prevent syntax highlighting. Pass a path to a + \samp{.theme} file to use a custom highlighting style for Pandoc.} \item{highlight_downlit}{\code{TRUE} to use the \pkg{downlit} package as syntax highlight engine to highlight inline code and R code chunks @@ -171,6 +175,53 @@ the markdown syntax for citations in the \href{https://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html}{Bibliographies and Citations} article in the online documentation. } +\section{Highlighting}{ + + + Different highlighting engines can be used with a R Markdown HTML documents: + highlightjs and Pandoc for all languages they support, \pkg{downlit} only + for R code. + + highlightjs engine can only be used with the default template (i.e + \code{template = "default"}) and it has a unique style ("textmate"). When + activated, a JS script and a CSS file are inserted into the output HTML to + make it works. For now, \code{highlight = "default"} will use this engine. In + next versions, highghlightjs engine could be removed. + + Pandoc built-in highlighting engine works with any template, default or + custom, and style can be chosen among the built-in ones ("tango", "pygments", "kate", +"monochrome", "espresso", "zenburn", "haddock" and "breezedark") or among some custom + theme passed as ".theme" files (see Details in the + \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). + \pkg{rmarkdown} includes two custom theme to select with \code{highlight} parameter: + \itemize{ + \item{"a11y", an accessible color theme derived from \url{https://github.com/ericwbailey/a11y-syntax-highlighting}} + \item{"rstudio", a color scheme close to RStudio's default highlighting and + highglightjs's textmate.} + } + + \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in + R. It will also do automatic linking of R code (requires internet + connectivity). It is activated only if \code{highlight_downlit} is + \code{TRUE} and will pass after Pandoc engine to replace only R code syntax + highlighting and will use any selected Pandoc's style. Default color scheme + is the accessible theme "a11y". If default template is used, some CSS is + added to get the link introduced by autolinking to use the color scheme + chosen. If you want to use with a custom template, add this to your + template: + + \preformatted{ +$if(highlight-downlit)$ + + $endif$} +} + \section{Navigation Bars}{ @@ -252,16 +303,19 @@ right: Note however that if you choose not to use the "default" HTML template then several aspects of HTML document rendering will behave differently: - \itemize{ \item{The \code{theme} parameter does not work (you can still - provide styles using the \code{css} parameter). } \item{For the - \code{highlight} parameter, the default highlighting style will resolve to - "pygments" and the "textmate" highlighting style is not available } - \item{The \code{toc_float} parameter will not work. } \item{The - \code{code_folding} parameter will not work. } \item{Tabbed sections (as - described above) will not work.} \item{Navigation bars (as described above) - will not work. }\item{MathJax will not work if \code{self_contained} is - \code{TRUE} (these two options can't be used together in normal pandoc - templates). } } + \itemize{ + \item{The \code{theme} parameter does not work (you can still provide styles + using the \code{css} parameter). } + \item{For the \code{highlight} parameter, the default highlighting engine + will resolve to Pandoc instead of highlightjs and highlighting style will default to + "pygments". "textmate" style is not available as related to highlightjs} + \item{The \code{toc_float} parameter will not work. } + \item{The \code{code_folding} parameter will not work. } + \item{Tabbed sections (as described above) will not work.} + \item{Navigation bars (as described above) will not work. } + \item{MathJax will not work if \code{self_contained} is \code{TRUE} (these + two options can't be used together in normal pandoc templates). } + } Due to the above restrictions, you might consider using the \code{includes} parameter as an alternative to providing a fully custom template. diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index fcc47892b6..00e9286229 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -63,8 +63,11 @@ chunks by default.} "sandstone", "simplex", or "yeti"). Pass \code{NULL} for no theme (in this case you can use the \code{css} parameter to add your own styles).} -\item{highlight}{Syntax highlight engine and style. "default" (and "textmate") - will use highlightjs as syntax highlighting engine instead of Pandoc. +\item{highlight}{Syntax highlight engine and style. See the + \emph{Highlighting} section below for details. + + "default" (and "textmate") will use highlightjs as syntax highlighting + engine instead of Pandoc. Any other value will be passed to Pandoc's \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting @@ -73,7 +76,8 @@ style}. Pandoc's built-in styles include "tango", "pygments", "kate", themes are also included, "a11y", for accessible color scheme and "rstudio", to replicate RStudio editor theme. - Pass \code{NULL} to prevent syntax highlighting.} + Pass \code{NULL} to prevent syntax highlighting. Pass a path to a + \samp{.theme} file to use a custom highlighting style for Pandoc.} \item{mathjax}{Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is From e2007dc40ca36b5ec7515fa47dbebda9e8dc285c Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 9 Nov 2020 15:59:08 +0100 Subject: [PATCH 33/53] custom themes file for syntax highlighting style are only available for Pandoc 2.0+ --- R/html_document.R | 20 +++++++++++--------- R/pandoc.R | 10 +++++++++- man/html_document.Rd | 20 +++++++++++--------- man/html_notebook.Rd | 19 ++++++++++--------- tests/testthat/test-pandoc.R | 6 ++++-- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index b757207c7f..ed077dc5b3 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -55,15 +55,16 @@ #' "default" (and "textmate") will use highlightjs as syntax highlighting #' engine instead of Pandoc. #' -#' Any other value will be passed to Pandoc's -#' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting -#' style}. Pandoc's built-in styles include "tango", "pygments", "kate", -#' "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom -#' themes are also included, "a11y", for accessible color scheme and "rstudio", -#' to replicate RStudio editor theme. +#' Any other value will be passed to Pandoc's +#' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting +#' style}. Pandoc's built-in styles include "tango", "pygments", "kate", +#' "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom +#' are also included, "a11y", for accessible color scheme and "rstudio", +#' to replicate RStudio editor theme. A path to a \samp{.theme} file can also be +#' passed to be used as a custom highlighting style for Pandoc. Note that custom +#' style are available for Pandoc 2.0+. #' -#' Pass \code{NULL} to prevent syntax highlighting. Pass a path to a -#' \samp{.theme} file to use a custom highlighting style for Pandoc. +#' Pass \code{NULL} to prevent syntax highlighting. #' #'@param highlight_downlit \code{TRUE} to use the \pkg{downlit} package as #' syntax highlight engine to highlight inline code and R code chunks @@ -115,12 +116,13 @@ #' "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or among some custom #' theme passed as ".theme" files (see Details in the #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). -#' \pkg{rmarkdown} includes two custom theme to select with \code{highlight} parameter: +#' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: #' \itemize{ #' \item{"a11y", an accessible color theme derived from \url{https://github.com/ericwbailey/a11y-syntax-highlighting}} #' \item{"rstudio", a color scheme close to RStudio's default highlighting and #' highglightjs's textmate.} #' } +#' Custom theme are only available for Pandoc 2.0 and above. #' #' \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in #' R. It will also do automatic linking of R code (requires internet diff --git a/R/pandoc.R b/R/pandoc.R index fbe6dc9547..ab59e1a125 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -561,6 +561,12 @@ pandoc_html_highlight_args <- function(template, # TODO: move out so that it works also for other formats resolve_highlight <- function(highlight) { + # if Pandoc built-in highlighter, do no nothing + if (highlight %in% highlighters()) return(highlight) + if (!pandoc2.0()) { + stop("Using a custom highlighting style requires Pandoc 2.0 and above", + call. = FALSE) + } custom <- list( # from distill # https://github.com/rstudio/distill/blob/c98d332192ff75f268ddf69bddace34e4db6d89b/inst/rmarkdown/templates/distill_article/resources/a11y.theme @@ -569,6 +575,7 @@ pandoc_html_highlight_args <- function(template, # https://github.com/rstudio/distill/blob/c98d332192ff75f268ddf69bddace34e4db6d89b/inst/rmarkdown/templates/distill_article/resources/rstudio.theme rstudio = pkg_file_highlight("rstudio.theme") ) + # if not an alias use the provided custom path custom[[highlight]] %||% highlight } highlight <- resolve_highlight(highlight) @@ -584,8 +591,9 @@ pandoc_html_highlight_args <- function(template, call. = FALSE ) } + default <- if (pandoc2.0()) resolve_highlight("a11y") else "pygments" args <- c( - pandoc_highlight_args(highlight, default = resolve_highlight("a11y")), + pandoc_highlight_args(highlight, default = default), # variable used to insert some css in a Pandoc template pandoc_variable_arg("highlight-downlit") ) diff --git a/man/html_document.Rd b/man/html_document.Rd index 16852898e4..8083572c14 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -105,15 +105,16 @@ case you can use the \code{css} parameter to add your own styles).} "default" (and "textmate") will use highlightjs as syntax highlighting engine instead of Pandoc. -Any other value will be passed to Pandoc's -\href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting -style}. Pandoc's built-in styles include "tango", "pygments", "kate", -"monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom -themes are also included, "a11y", for accessible color scheme and "rstudio", -to replicate RStudio editor theme. + Any other value will be passed to Pandoc's + \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting + style}. Pandoc's built-in styles include "tango", "pygments", "kate", + "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom + are also included, "a11y", for accessible color scheme and "rstudio", + to replicate RStudio editor theme. A path to a \samp{.theme} file can also be + passed to be used as a custom highlighting style for Pandoc. Note that custom + style are available for Pandoc 2.0+. - Pass \code{NULL} to prevent syntax highlighting. Pass a path to a - \samp{.theme} file to use a custom highlighting style for Pandoc.} + Pass \code{NULL} to prevent syntax highlighting.} \item{highlight_downlit}{\code{TRUE} to use the \pkg{downlit} package as syntax highlight engine to highlight inline code and R code chunks @@ -193,12 +194,13 @@ and Citations} article in the online documentation. "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or among some custom theme passed as ".theme" files (see Details in the \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). - \pkg{rmarkdown} includes two custom theme to select with \code{highlight} parameter: + \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: \itemize{ \item{"a11y", an accessible color theme derived from \url{https://github.com/ericwbailey/a11y-syntax-highlighting}} \item{"rstudio", a color scheme close to RStudio's default highlighting and highglightjs's textmate.} } + Custom theme are only available for Pandoc 2.0 and above. \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in R. It will also do automatic linking of R code (requires internet diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index 00e9286229..5b82d32d45 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -69,15 +69,16 @@ case you can use the \code{css} parameter to add your own styles).} "default" (and "textmate") will use highlightjs as syntax highlighting engine instead of Pandoc. -Any other value will be passed to Pandoc's -\href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting -style}. Pandoc's built-in styles include "tango", "pygments", "kate", -"monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom -themes are also included, "a11y", for accessible color scheme and "rstudio", -to replicate RStudio editor theme. - - Pass \code{NULL} to prevent syntax highlighting. Pass a path to a - \samp{.theme} file to use a custom highlighting style for Pandoc.} + Any other value will be passed to Pandoc's + \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting + style}. Pandoc's built-in styles include "tango", "pygments", "kate", + "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom + are also included, "a11y", for accessible color scheme and "rstudio", + to replicate RStudio editor theme. A path to a \samp{.theme} file can also be + passed to be used as a custom highlighting style for Pandoc. Note that custom + style are available for Pandoc 2.0+. + + Pass \code{NULL} to prevent syntax highlighting.} \item{mathjax}{Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index 2a3449ac64..50d5eefec7 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -30,13 +30,15 @@ test_that("Correct HTML highlighting argument as requested", { expect_equal(hl_args("default", "default"), c(hl_style(NULL), highlightjs)) expect_equal(hl_args("textmate", "default"), c(hl_style(NULL), highlightjs)) # downlit - expect_equal(hl_args("default", "default", TRUE), c(a11y_theme, downlit)) - expect_equal(hl_args("default", "dummy.html", TRUE), c(a11y_theme, downlit)) expect_equal(hl_args("tango", "default", TRUE), c(hl_style("tango"), downlit)) expect_error(hl_args("textmate", "dummy.html", TRUE)) # custom theme + skip_if_not(pandoc2.0()) + expect_equal(hl_args("default", "default", TRUE), c(a11y_theme, downlit)) + expect_equal(hl_args("default", "dummy.html", TRUE), c(a11y_theme, downlit)) expect_equal(hl_args("a11y", "default", FALSE), c(a11y_theme)) expect_equal(hl_args("rstudio", "default", TRUE), c(rstudio_theme, downlit)) + expect_equal(hl_args("path/to.theme", "default"), c(hl_style("path/to.theme"))) }) test_that("detect highlightjs theme", { From fba6bc26dfa0008cfc27a0c619649329f60cbcb4 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 24 Nov 2020 17:43:46 +0100 Subject: [PATCH 34/53] use arrow.theme from https://github.com/rstudio/distill/pull/221 --- R/html_document.R | 38 ++--- R/pandoc.R | 6 +- inst/rmarkdown/highlight/a11y.theme | 211 -------------------------- inst/rmarkdown/highlight/arrow.theme | 214 +++++++++++++++++++++++++++ man/html_document.Rd | 38 ++--- man/html_notebook.Rd | 2 +- tests/testthat/test-pandoc.R | 8 +- 7 files changed, 262 insertions(+), 255 deletions(-) delete mode 100644 inst/rmarkdown/highlight/a11y.theme create mode 100644 inst/rmarkdown/highlight/arrow.theme diff --git a/R/html_document.R b/R/html_document.R index ed077dc5b3..d7c73fe77b 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -59,7 +59,7 @@ #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting #' style}. Pandoc's built-in styles include "tango", "pygments", "kate", #' "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom -#' are also included, "a11y", for accessible color scheme and "rstudio", +#' are also included, "arrow", for accessible color scheme and "rstudio", #' to replicate RStudio editor theme. A path to a \samp{.theme} file can also be #' passed to be used as a custom highlighting style for Pandoc. Note that custom #' style are available for Pandoc 2.0+. @@ -70,7 +70,7 @@ #' syntax highlight engine to highlight inline code and R code chunks #' (including providing hyperlinks to function documentation). Only Pandoc #' color schemes are supported with this engine. With \code{highlight} -#' "default", it will use the accessible theme called "a11y". To learn more +#' "default", it will use the accessible theme called "arrow". To learn more #' about \pkg{downlit} highlighting engine, see #' \url{https://downlit.r-lib.org/}. #'@param mathjax Include mathjax. The "default" option uses an https URL from a @@ -108,31 +108,33 @@ #' highlightjs engine can only be used with the default template (i.e #' \code{template = "default"}) and it has a unique style ("textmate"). When #' activated, a JS script and a CSS file are inserted into the output HTML to -#' make it works. For now, \code{highlight = "default"} will use this engine. In -#' next versions, highghlightjs engine could be removed. +#' make it works. For now, \code{highlight = "default"} will use this engine. +#' In next versions, highghlightjs engine could be removed. #' #' Pandoc built-in highlighting engine works with any template, default or -#' custom, and style can be chosen among the built-in ones ("tango", "pygments", "kate", -#' "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or among some custom -#' theme passed as ".theme" files (see Details in the +#' custom, and style can be chosen among the built-in ones ("tango", "pygments", +#' "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or +#' among some custom theme passed as ".theme" files (see Details in the #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). -#' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: +#' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} +#' parameter: #' \itemize{ -#' \item{"a11y", an accessible color theme derived from \url{https://github.com/ericwbailey/a11y-syntax-highlighting}} +#' \item{"arrow", an accessible color theme derived from \href{optimized for +#' accessibility and color contrast}{https://www.a11yproject.com/}} #' \item{"rstudio", a color scheme close to RStudio's default highlighting and #' highglightjs's textmate.} #' } #' Custom theme are only available for Pandoc 2.0 and above. #' -#' \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in -#' R. It will also do automatic linking of R code (requires internet -#' connectivity). It is activated only if \code{highlight_downlit} is -#' \code{TRUE} and will pass after Pandoc engine to replace only R code syntax -#' highlighting and will use any selected Pandoc's style. Default color scheme -#' is the accessible theme "a11y". If default template is used, some CSS is -#' added to get the link introduced by autolinking to use the color scheme -#' chosen. If you want to use with a custom template, add this to your -#' template: +#' \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that +#' provides a syntax highlighting engine in R. It will also do automatic +#' linking of R code (requires internet connectivity). It is activated only if +#' \code{highlight_downlit} is \code{TRUE} and will pass after Pandoc engine to +#' replace only R code syntax highlighting and will use any selected Pandoc's +#' style. Default color scheme is the accessible theme "arrow". If default +#' template is used, some CSS is added to get the link introduced by +#' autolinking to use the color scheme chosen. If you want to use with a custom +#' template, add this to your template: #' #' \preformatted{ #' $if(highlight-downlit)$ diff --git a/R/pandoc.R b/R/pandoc.R index ab59e1a125..f802ec62a7 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -569,8 +569,8 @@ pandoc_html_highlight_args <- function(template, } custom <- list( # from distill - # https://github.com/rstudio/distill/blob/c98d332192ff75f268ddf69bddace34e4db6d89b/inst/rmarkdown/templates/distill_article/resources/a11y.theme - a11y = pkg_file_highlight("a11y.theme"), + # https://raw.githubusercontent.com/apreshill/distill/arrow/inst/rmarkdown/templates/distill_article/resources/arrow.theme + arrow = pkg_file_highlight("arrow.theme"), # from distill # https://github.com/rstudio/distill/blob/c98d332192ff75f268ddf69bddace34e4db6d89b/inst/rmarkdown/templates/distill_article/resources/rstudio.theme rstudio = pkg_file_highlight("rstudio.theme") @@ -591,7 +591,7 @@ pandoc_html_highlight_args <- function(template, call. = FALSE ) } - default <- if (pandoc2.0()) resolve_highlight("a11y") else "pygments" + default <- if (pandoc2.0()) resolve_highlight("arrow") else "pygments" args <- c( pandoc_highlight_args(highlight, default = default), # variable used to insert some css in a Pandoc template diff --git a/inst/rmarkdown/highlight/a11y.theme b/inst/rmarkdown/highlight/a11y.theme deleted file mode 100644 index 5be20e45a5..0000000000 --- a/inst/rmarkdown/highlight/a11y.theme +++ /dev/null @@ -1,211 +0,0 @@ -{ - "text-color": null, - "background-color": null, - "line-number-color": "#aaaaaa", - "line-number-background-color": null, - "text-styles": { - "Other": { - "text-color": "#007faa", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Attribute": { - "text-color": "#7d9029", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "SpecialString": { - "text-color": "#bb6688", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Annotation": { - "text-color": "#545454", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "Function": { - "text-color": "#4254A7", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "String": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "ControlFlow": { - "text-color": "#007faa", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "Operator": { - "text-color": "#696969", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Error": { - "text-color": "#ff0000", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "BaseN": { - "text-color": "#a1024a", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Alert": { - "text-color": "#ff0000", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "Variable": { - "text-color": "#19177c", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "BuiltIn": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Extension": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Preprocessor": { - "text-color": "#bc7a00", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Information": { - "text-color": "#545454", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "VerbatimString": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Warning": { - "text-color": "#545454", - "background-color": null, - "bold": true, - "italic": true, - "underline": false - }, - "Documentation": { - "text-color": "#ba2121", - "background-color": null, - "bold": false, - "italic": true, - "underline": false - }, - "Import": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Char": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "DataType": { - "text-color": "#aa5d00", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Float": { - "text-color": "#a1024a", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Comment": { - "text-color": "#545454", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "CommentVar": { - "text-color": "#545454", - "background-color": null, - "bold": true, - "italic": true, - "underline": false - }, - "Constant": { - "text-color": "#d91e18", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "SpecialChar": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "DecVal": { - "text-color": "#a1024a", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Keyword": { - "text-color": "#007faa", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - } - } -} diff --git a/inst/rmarkdown/highlight/arrow.theme b/inst/rmarkdown/highlight/arrow.theme new file mode 100644 index 0000000000..58a0c04f14 --- /dev/null +++ b/inst/rmarkdown/highlight/arrow.theme @@ -0,0 +1,214 @@ +// 20201124173225 +// https://raw.githubusercontent.com/apreshill/distill/arrow/inst/rmarkdown/templates/distill_article/resources/arrow.theme + +{ + "text-color": null, + "background-color": null, + "line-number-color": "#aaaaaa", + "line-number-background-color": null, + "text-styles": { + "Other": { + "text-color": "#007BA5", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Attribute": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "SpecialString": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Annotation": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Function": { + "text-color": "#4758AB", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "String": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "ControlFlow": { + "text-color": "#007BA5", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Operator": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Error": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "BaseN": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Alert": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Variable": { + "text-color": "#111111", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "BuiltIn": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Extension": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Preprocessor": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Information": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "VerbatimString": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Warning": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": true, + "underline": false + }, + "Documentation": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": true, + "underline": false + }, + "Import": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Char": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "DataType": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Float": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Comment": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "CommentVar": { + "text-color": "#5E5E5E", + "background-color": null, + "bold": false, + "italic": true, + "underline": false + }, + "Constant": { + "text-color": "#A8602C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "SpecialChar": { + "text-color": "#20794D", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "DecVal": { + "text-color": "#B8003C", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Keyword": { + "text-color": "#007BA5", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + } + } +} diff --git a/man/html_document.Rd b/man/html_document.Rd index 8083572c14..3d1eb83e7a 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -109,7 +109,7 @@ case you can use the \code{css} parameter to add your own styles).} \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting style}. Pandoc's built-in styles include "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom - are also included, "a11y", for accessible color scheme and "rstudio", + are also included, "arrow", for accessible color scheme and "rstudio", to replicate RStudio editor theme. A path to a \samp{.theme} file can also be passed to be used as a custom highlighting style for Pandoc. Note that custom style are available for Pandoc 2.0+. @@ -120,7 +120,7 @@ case you can use the \code{css} parameter to add your own styles).} syntax highlight engine to highlight inline code and R code chunks (including providing hyperlinks to function documentation). Only Pandoc color schemes are supported with this engine. With \code{highlight} -"default", it will use the accessible theme called "a11y". To learn more +"default", it will use the accessible theme called "arrow". To learn more about \pkg{downlit} highlighting engine, see \url{https://downlit.r-lib.org/}.} @@ -186,31 +186,33 @@ and Citations} article in the online documentation. highlightjs engine can only be used with the default template (i.e \code{template = "default"}) and it has a unique style ("textmate"). When activated, a JS script and a CSS file are inserted into the output HTML to - make it works. For now, \code{highlight = "default"} will use this engine. In - next versions, highghlightjs engine could be removed. + make it works. For now, \code{highlight = "default"} will use this engine. + In next versions, highghlightjs engine could be removed. Pandoc built-in highlighting engine works with any template, default or - custom, and style can be chosen among the built-in ones ("tango", "pygments", "kate", -"monochrome", "espresso", "zenburn", "haddock" and "breezedark") or among some custom - theme passed as ".theme" files (see Details in the + custom, and style can be chosen among the built-in ones ("tango", "pygments", + "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or + among some custom theme passed as ".theme" files (see Details in the \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). - \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: + \pkg{rmarkdown} includes two custom themes to select with \code{highlight} + parameter: \itemize{ - \item{"a11y", an accessible color theme derived from \url{https://github.com/ericwbailey/a11y-syntax-highlighting}} + \item{"arrow", an accessible color theme derived from \href{optimized for + accessibility and color contrast}{https://www.a11yproject.com/}} \item{"rstudio", a color scheme close to RStudio's default highlighting and highglightjs's textmate.} } Custom theme are only available for Pandoc 2.0 and above. - \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in - R. It will also do automatic linking of R code (requires internet - connectivity). It is activated only if \code{highlight_downlit} is - \code{TRUE} and will pass after Pandoc engine to replace only R code syntax - highlighting and will use any selected Pandoc's style. Default color scheme - is the accessible theme "a11y". If default template is used, some CSS is - added to get the link introduced by autolinking to use the color scheme - chosen. If you want to use with a custom template, add this to your - template: + \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that + provides a syntax highlighting engine in R. It will also do automatic + linking of R code (requires internet connectivity). It is activated only if + \code{highlight_downlit} is \code{TRUE} and will pass after Pandoc engine to + replace only R code syntax highlighting and will use any selected Pandoc's + style. Default color scheme is the accessible theme "arrow". If default + template is used, some CSS is added to get the link introduced by + autolinking to use the color scheme chosen. If you want to use with a custom + template, add this to your template: \preformatted{ $if(highlight-downlit)$ diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index 5b82d32d45..41bf0a0137 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -73,7 +73,7 @@ case you can use the \code{css} parameter to add your own styles).} \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting style}. Pandoc's built-in styles include "tango", "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom - are also included, "a11y", for accessible color scheme and "rstudio", + are also included, "arrow", for accessible color scheme and "rstudio", to replicate RStudio editor theme. A path to a \samp{.theme} file can also be passed to be used as a custom highlighting style for Pandoc. Note that custom style are available for Pandoc 2.0+. diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index 50d5eefec7..ae643b414f 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -16,7 +16,7 @@ test_that("Correct HTML highlighting argument as requested", { hl_style <- pandoc_highlight_args downlit <- pandoc_variable_arg("highlight-downlit") highlightjs <- pandoc_variable_arg("highlightjs", "1") - a11y_theme <- hl_style(pkg_file_highlight("a11y.theme")) + arrow_theme <- hl_style(pkg_file_highlight("arrow.theme")) rstudio_theme <- hl_style(pkg_file_highlight("rstudio.theme")) # check logic # no engine @@ -34,9 +34,9 @@ test_that("Correct HTML highlighting argument as requested", { expect_error(hl_args("textmate", "dummy.html", TRUE)) # custom theme skip_if_not(pandoc2.0()) - expect_equal(hl_args("default", "default", TRUE), c(a11y_theme, downlit)) - expect_equal(hl_args("default", "dummy.html", TRUE), c(a11y_theme, downlit)) - expect_equal(hl_args("a11y", "default", FALSE), c(a11y_theme)) + expect_equal(hl_args("default", "default", TRUE), c(arrow_theme, downlit)) + expect_equal(hl_args("default", "dummy.html", TRUE), c(arrow_theme, downlit)) + expect_equal(hl_args("arrow", "default", FALSE), c(arrow_theme)) expect_equal(hl_args("rstudio", "default", TRUE), c(rstudio_theme, downlit)) expect_equal(hl_args("path/to.theme", "default"), c(hl_style("path/to.theme"))) }) From 98e7af94d62b0dd9fb238af347cdbc74cb33fba1 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Tue, 24 Nov 2020 18:02:18 +0100 Subject: [PATCH 35/53] \href is url then text Will be easier when we switch to Markdown syntax for help --- R/html_document.R | 4 ++-- man/html_document.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index d7c73fe77b..a17877d922 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -119,8 +119,8 @@ #' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} #' parameter: #' \itemize{ -#' \item{"arrow", an accessible color theme derived from \href{optimized for -#' accessibility and color contrast}{https://www.a11yproject.com/}} +#' \item{"arrow", an accessible color theme derived from \href{https://www.a11yproject.com/}{optimized for +#' accessibility and color contrast}} #' \item{"rstudio", a color scheme close to RStudio's default highlighting and #' highglightjs's textmate.} #' } diff --git a/man/html_document.Rd b/man/html_document.Rd index 3d1eb83e7a..b25e06f7e6 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -197,8 +197,8 @@ and Citations} article in the online documentation. \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: \itemize{ - \item{"arrow", an accessible color theme derived from \href{optimized for - accessibility and color contrast}{https://www.a11yproject.com/}} + \item{"arrow", an accessible color theme derived from \href{https://www.a11yproject.com/}{optimized for + accessibility and color contrast}} \item{"rstudio", a color scheme close to RStudio's default highlighting and highglightjs's textmate.} } From e315e03bd68693e2b0dfa18a9093fc616b23e438 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 27 Nov 2020 17:15:05 +0100 Subject: [PATCH 36/53] texmate can be used with non default template now. But the template would require some javascript configuration --- tests/testthat/test-pandoc.R | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index ae643b414f..cb27dad3bc 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -28,6 +28,7 @@ test_that("Correct HTML highlighting argument as requested", { expect_equal(hl_args("breezedark", "default"), hl_style("breezedark")) # highlight expect_equal(hl_args("default", "default"), c(hl_style(NULL), highlightjs)) + expect_equal(hl_args("textmate", "dummy.html"), c(hl_style(NULL), highlightjs)) expect_equal(hl_args("textmate", "default"), c(hl_style(NULL), highlightjs)) # downlit expect_equal(hl_args("tango", "default", TRUE), c(hl_style("tango"), downlit)) From 38a86cf54e374d9c8140ec9709aa78ed417c86fb Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 27 Nov 2020 17:59:55 +0100 Subject: [PATCH 37/53] in fact stick with current behavior for highlight.js as it is safer to no change it highlightjs will only be used with default template and highgligh argument in default or textmate --- R/pandoc.R | 14 ++++++-------- tests/testthat/test-pandoc.R | 10 ++++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/R/pandoc.R b/R/pandoc.R index f802ec62a7..109c5151b4 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -582,13 +582,12 @@ pandoc_html_highlight_args <- function(template, # downlit engine if (highlight_downlit) { - if (is_highlightjs(highlight)) { + if (highlight != "default" && is_highlightjs(highlight)) { stop( sprintf( "'%s' theme is for highlightjs highlighting engine", - "and can't be used with downlit.", highlight - ), - call. = FALSE + "and can't be used with downlit.", highlight + ), call. = FALSE ) } default <- if (pandoc2.0()) resolve_highlight("arrow") else "pygments" @@ -597,9 +596,8 @@ pandoc_html_highlight_args <- function(template, # variable used to insert some css in a Pandoc template pandoc_variable_arg("highlight-downlit") ) - } else if (is_highlightjs(highlight) || - (highlight == "default" && template == "default")) { - # highlightjs engine + } else if (template == "default" && is_highlightjs(highlight)) { + # highlightjs engine for default template only args <- c(pandoc_highlight_args(NULL), # variable used to insert some css and js # in the Pandoc default template @@ -613,7 +611,7 @@ pandoc_html_highlight_args <- function(template, } is_highlightjs <- function(highlight) { - !is.null(highlight) && (highlight %in% c("textmate")) + !is.null(highlight) && (highlight %in% c("default", "textmate")) } #' Find the \command{pandoc} executable diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index cb27dad3bc..cd2dc18641 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -28,25 +28,31 @@ test_that("Correct HTML highlighting argument as requested", { expect_equal(hl_args("breezedark", "default"), hl_style("breezedark")) # highlight expect_equal(hl_args("default", "default"), c(hl_style(NULL), highlightjs)) - expect_equal(hl_args("textmate", "dummy.html"), c(hl_style(NULL), highlightjs)) expect_equal(hl_args("textmate", "default"), c(hl_style(NULL), highlightjs)) + ##-- will error in pandoc but currently unhandled + expect_equal(hl_args("textmate", "dummy.html"), c(hl_style("textmate"))) # downlit expect_equal(hl_args("tango", "default", TRUE), c(hl_style("tango"), downlit)) + expect_equal(hl_args("tango", "dummy.html", TRUE), c(hl_style("tango"), downlit)) expect_error(hl_args("textmate", "dummy.html", TRUE)) + expect_error(hl_args("textmate", "default", TRUE)) # custom theme skip_if_not(pandoc2.0()) expect_equal(hl_args("default", "default", TRUE), c(arrow_theme, downlit)) expect_equal(hl_args("default", "dummy.html", TRUE), c(arrow_theme, downlit)) expect_equal(hl_args("arrow", "default", FALSE), c(arrow_theme)) + expect_equal(hl_args("arrow", "dummy.html", FALSE), c(arrow_theme)) expect_equal(hl_args("rstudio", "default", TRUE), c(rstudio_theme, downlit)) + expect_equal(hl_args("rstudio", "dummy.html", TRUE), c(rstudio_theme, downlit)) expect_equal(hl_args("path/to.theme", "default"), c(hl_style("path/to.theme"))) + expect_equal(hl_args("path/to.theme", "dummy.html"), c(hl_style("path/to.theme"))) }) test_that("detect highlightjs theme", { expect_false(is_highlightjs(NULL)) expect_false(is_highlightjs("zenburn")) - expect_false(is_highlightjs("default")) expect_false(is_highlightjs("path/to/hl.theme")) + expect_true(is_highlightjs("default")) expect_true(is_highlightjs("textmate")) }) From 1a33c361777e76ed872406fdf44a8213ed4530ac Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 27 Nov 2020 18:13:50 +0100 Subject: [PATCH 38/53] Fix an issue with custom template and highlight=textmate Previously it could be passed to Pandoc `--highlight-style` argument - which will cause error in Pandoc. Now it will throw an error from R. --- R/pandoc.R | 17 +++++++++++------ tests/testthat/test-pandoc.R | 7 +++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/R/pandoc.R b/R/pandoc.R index 109c5151b4..66c8fc17a1 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -580,16 +580,20 @@ pandoc_html_highlight_args <- function(template, } highlight <- resolve_highlight(highlight) - # downlit engine - if (highlight_downlit) { + check_highlightjs <- function(highlight, engine) { if (highlight != "default" && is_highlightjs(highlight)) { stop( - sprintf( - "'%s' theme is for highlightjs highlighting engine", - "and can't be used with downlit.", highlight - ), call. = FALSE + sprintf(c( + "'%s' theme is for highlightjs highlighting engine ", + "and can't be used with %s engine."), c(highlight, engine)), + call. = FALSE ) } + } + + # downlit engine + if (highlight_downlit) { + check_highlightjs(highlight, "downlit") default <- if (pandoc2.0()) resolve_highlight("arrow") else "pygments" args <- c( pandoc_highlight_args(highlight, default = default), @@ -604,6 +608,7 @@ pandoc_html_highlight_args <- function(template, pandoc_variable_arg("highlightjs", "1")) } else { # Pandoc engine + check_highlightjs(highlight, "Pandoc") args <- pandoc_highlight_args(highlight, default = "pygments") } diff --git a/tests/testthat/test-pandoc.R b/tests/testthat/test-pandoc.R index cd2dc18641..2b3b667d03 100644 --- a/tests/testthat/test-pandoc.R +++ b/tests/testthat/test-pandoc.R @@ -29,13 +29,12 @@ test_that("Correct HTML highlighting argument as requested", { # highlight expect_equal(hl_args("default", "default"), c(hl_style(NULL), highlightjs)) expect_equal(hl_args("textmate", "default"), c(hl_style(NULL), highlightjs)) - ##-- will error in pandoc but currently unhandled - expect_equal(hl_args("textmate", "dummy.html"), c(hl_style("textmate"))) + expect_error(hl_args("textmate", "dummy.html"), "Pandoc engine") # downlit expect_equal(hl_args("tango", "default", TRUE), c(hl_style("tango"), downlit)) expect_equal(hl_args("tango", "dummy.html", TRUE), c(hl_style("tango"), downlit)) - expect_error(hl_args("textmate", "dummy.html", TRUE)) - expect_error(hl_args("textmate", "default", TRUE)) + expect_error(hl_args("textmate", "dummy.html", TRUE), "downlit engine") + expect_error(hl_args("textmate", "default", TRUE), "downlit engine") # custom theme skip_if_not(pandoc2.0()) expect_equal(hl_args("default", "default", TRUE), c(arrow_theme, downlit)) From 3ee0e70a914d5d743da775dd67933d0aea1de4ba Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 27 Nov 2020 18:18:10 +0100 Subject: [PATCH 39/53] update documentation --- R/html_document.R | 8 ++++---- man/html_document.Rd | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index a17877d922..dbe11478ec 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -106,10 +106,10 @@ #' for R code. #' #' highlightjs engine can only be used with the default template (i.e -#' \code{template = "default"}) and it has a unique style ("textmate"). When -#' activated, a JS script and a CSS file are inserted into the output HTML to -#' make it works. For now, \code{highlight = "default"} will use this engine. -#' In next versions, highghlightjs engine could be removed. +#' \code{template = "default"}) and it has two styles ("default" and +#' "textmate"). When activated, a JS script and a CSS file are inserted into +#' the output HTML to make it works. For now, this is the default engine for +#' the default template - this could change in the future. #' #' Pandoc built-in highlighting engine works with any template, default or #' custom, and style can be chosen among the built-in ones ("tango", "pygments", diff --git a/man/html_document.Rd b/man/html_document.Rd index b25e06f7e6..c4e317d703 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -184,10 +184,10 @@ and Citations} article in the online documentation. for R code. highlightjs engine can only be used with the default template (i.e - \code{template = "default"}) and it has a unique style ("textmate"). When - activated, a JS script and a CSS file are inserted into the output HTML to - make it works. For now, \code{highlight = "default"} will use this engine. - In next versions, highghlightjs engine could be removed. + \code{template = "default"}) and it has two styles ("default" and + "textmate"). When activated, a JS script and a CSS file are inserted into + the output HTML to make it works. For now, this is the default engine for + the default template - this could change in the future. Pandoc built-in highlighting engine works with any template, default or custom, and style can be chosen among the built-in ones ("tango", "pygments", From 994a7b5bcfddf75bfe829941a243a33a3a90f1af Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Fri, 27 Nov 2020 21:58:50 +0100 Subject: [PATCH 40/53] remove comment lines introduced by copy pasting the theme json file --- inst/rmarkdown/highlight/arrow.theme | 3 --- 1 file changed, 3 deletions(-) diff --git a/inst/rmarkdown/highlight/arrow.theme b/inst/rmarkdown/highlight/arrow.theme index 58a0c04f14..f9ce133935 100644 --- a/inst/rmarkdown/highlight/arrow.theme +++ b/inst/rmarkdown/highlight/arrow.theme @@ -1,6 +1,3 @@ -// 20201124173225 -// https://raw.githubusercontent.com/apreshill/distill/arrow/inst/rmarkdown/templates/distill_article/resources/arrow.theme - { "text-color": null, "background-color": null, From d88d9e3c7e797eb64e168a234fc8ab7ce7c5d714 Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Fri, 27 Nov 2020 22:05:58 +0100 Subject: [PATCH 41/53] reformart rstudio.theme correctly --- inst/rmarkdown/highlight/rstudio.theme | 374 ++++++++++++------------- 1 file changed, 187 insertions(+), 187 deletions(-) diff --git a/inst/rmarkdown/highlight/rstudio.theme b/inst/rmarkdown/highlight/rstudio.theme index a13c0c40f1..e638834d91 100644 --- a/inst/rmarkdown/highlight/rstudio.theme +++ b/inst/rmarkdown/highlight/rstudio.theme @@ -1,190 +1,190 @@ { - "text-color": null, - "background-color": null, - "line-number-color": "#aaaaaa", - "line-number-background-color": null, - "text-styles": { - "Other": { - "text-color": "#ff4000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Attribute": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "SpecialString": { - "text-color": "#008080", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Annotation": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "String": { - "text-color": "#036a07", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "DecVal": { - "text-color": "#0000cd", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Float": { - "text-color": "#0000cd", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "ControlFlow": { - "text-color": "#0000ff", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Operator": { - "text-color": "#687687", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Error": { - "text-color": "#ff0000", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "Alert": { - "text-color": "#ff0000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Variable": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "BuiltIn": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Extension": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Preprocessor": { - "text-color": "#ff4000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Information": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "VerbatimString": { - "text-color": "#008080", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Warning": { - "text-color": "#008000", - "background-color": null, - "bold": true, - "italic": false, - "underline": false - }, - "Documentation": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Import": { - "text-color": null, - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Char": { - "text-color": "#008080", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Comment": { - "text-color": "#4c886b", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "CommentVar": { - "text-color": "#008000", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Constant": { - "text-color": "#585cf6", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "SpecialChar": { - "text-color": "#008080", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - }, - "Keyword": { - "text-color": "#0000ff", - "background-color": null, - "bold": false, - "italic": false, - "underline": false - } + "text-color": null, + "background-color": null, + "line-number-color": "#aaaaaa", + "line-number-background-color": null, + "text-styles": { + "Other": { + "text-color": "#ff4000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Attribute": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "SpecialString": { + "text-color": "#008080", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Annotation": { + "text-color": "#008000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "String": { + "text-color": "#036a07", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "DecVal": { + "text-color": "#0000cd", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Float": { + "text-color": "#0000cd", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "ControlFlow": { + "text-color": "#0000ff", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Operator": { + "text-color": "#687687", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Error": { + "text-color": "#ff0000", + "background-color": null, + "bold": true, + "italic": false, + "underline": false + }, + "Alert": { + "text-color": "#ff0000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Variable": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "BuiltIn": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Extension": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Preprocessor": { + "text-color": "#ff4000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Information": { + "text-color": "#008000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "VerbatimString": { + "text-color": "#008080", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Warning": { + "text-color": "#008000", + "background-color": null, + "bold": true, + "italic": false, + "underline": false + }, + "Documentation": { + "text-color": "#008000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Import": { + "text-color": null, + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Char": { + "text-color": "#008080", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Comment": { + "text-color": "#4c886b", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "CommentVar": { + "text-color": "#008000", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Constant": { + "text-color": "#585cf6", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "SpecialChar": { + "text-color": "#008080", + "background-color": null, + "bold": false, + "italic": false, + "underline": false + }, + "Keyword": { + "text-color": "#0000ff", + "background-color": null, + "bold": false, + "italic": false, + "underline": false } + } } From a1d40ef63f53810cab2abd8a633fc2d3649a9271 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 30 Nov 2020 17:11:34 +0100 Subject: [PATCH 42/53] Apply suggestions from code review Co-authored-by: Hadley Wickham --- R/html_document.R | 22 +++++++++++----------- R/md_document.R | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index dbe11478ec..cc98fb47f3 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -107,14 +107,14 @@ #' #' highlightjs engine can only be used with the default template (i.e #' \code{template = "default"}) and it has two styles ("default" and -#' "textmate"). When activated, a JS script and a CSS file are inserted into -#' the output HTML to make it works. For now, this is the default engine for +#' "textmate"). When activated, it adds two additional dependencies to the +#' output file: a JS script and a CSS file. For now, this is the default engine for #' the default template - this could change in the future. #' #' Pandoc built-in highlighting engine works with any template, default or #' custom, and style can be chosen among the built-in ones ("tango", "pygments", #' "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or -#' among some custom theme passed as ".theme" files (see Details in the +#' a path to a custom theme ".theme" file (see Details in the #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). #' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} #' parameter: @@ -124,17 +124,18 @@ #' \item{"rstudio", a color scheme close to RStudio's default highlighting and #' highglightjs's textmate.} #' } -#' Custom theme are only available for Pandoc 2.0 and above. +#' Custom themes are only available for Pandoc 2.0 and above. #' #' \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that #' provides a syntax highlighting engine in R. It will also do automatic #' linking of R code (requires internet connectivity). It is activated only if -#' \code{highlight_downlit} is \code{TRUE} and will pass after Pandoc engine to -#' replace only R code syntax highlighting and will use any selected Pandoc's -#' style. Default color scheme is the accessible theme "arrow". If default -#' template is used, some CSS is added to get the link introduced by -#' autolinking to use the color scheme chosen. If you want to use with a custom -#' template, add this to your template: +#' \code{highlight_downlit} is \code{TRUE}. It only affects R code, leaving +#' highlighting for other languages unchanged. The default color scheme is +#' the accessible theme "arrow". +#' +#' It requires some CSS in the template to correctly style links. This is included +#' in the default template, but if you want to use with a custom template, you will +#' need to add this to your template: #' #' \preformatted{ #' $if(highlight-downlit)$ @@ -745,4 +746,3 @@ navbar_link_text <- function(x, ...) { else tagList(x$text, ...) } - diff --git a/R/md_document.R b/R/md_document.R index cf2acbfdf5..96d17b140b 100644 --- a/R/md_document.R +++ b/R/md_document.R @@ -22,7 +22,7 @@ #' widely used retina displays, but will also result in the output of #' \code{} tags rather than markdown images due to the need to set the #' width of the image explicitly. -#' @param ext Extension of the output document (defaults to ".md"). +#' @param ext Extension of the output file (defaults to ".md"). #' @return R Markdown output format to pass to \code{\link{render}} #' @examples #' \dontrun{ From 827bfadd3bc2761671806099730c614e097f2b54 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Mon, 30 Nov 2020 17:40:13 +0100 Subject: [PATCH 43/53] Other changes after @hadley's review --- R/html_document.R | 58 ++++++++++++++++++++----------------- man/html_document.Rd | 69 ++++++++++++++++++++++++-------------------- man/html_notebook.Rd | 11 +++---- man/md_document.Rd | 2 +- 4 files changed, 75 insertions(+), 65 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index cc98fb47f3..9c29fcba84 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -58,20 +58,23 @@ #' Any other value will be passed to Pandoc's #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting #' style}. Pandoc's built-in styles include "tango", "pygments", "kate", -#' "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom -#' are also included, "arrow", for accessible color scheme and "rstudio", -#' to replicate RStudio editor theme. A path to a \samp{.theme} file can also be -#' passed to be used as a custom highlighting style for Pandoc. Note that custom -#' style are available for Pandoc 2.0+. +#' "monochrome", "espresso", "zenburn", "haddock" and "breezedark". +#' +#' Two custom styles are also included, "arrow", an accessible color scheme, +#' and "rstudio", which mimics the default IDE theme. Alternatively, supply a +#' path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This +#' requires Pandoc 2.0+) #' #' Pass \code{NULL} to prevent syntax highlighting. #' #'@param highlight_downlit \code{TRUE} to use the \pkg{downlit} package as #' syntax highlight engine to highlight inline code and R code chunks -#' (including providing hyperlinks to function documentation). Only Pandoc -#' color schemes are supported with this engine. With \code{highlight} -#' "default", it will use the accessible theme called "arrow". To learn more -#' about \pkg{downlit} highlighting engine, see +#' (including providing hyperlinks to function documentation). The package +#' needs to be installed to use this feature. +#' +#' Only Pandoc color schemes are supported with this engine. With +#' \code{highlight = "default"}, it will use the accessible theme called +#' "arrow". To learn more about \pkg{downlit} highlighting engine, see #' \url{https://downlit.r-lib.org/}. #'@param mathjax Include mathjax. The "default" option uses an https URL from a #' MathJax CDN. The "local" option uses a local version of MathJax (which is @@ -101,37 +104,37 @@ #'@return R Markdown output format to pass to \code{\link{render}} #'@section Highlighting: #' -#' Different highlighting engines can be used with a R Markdown HTML documents: -#' highlightjs and Pandoc for all languages they support, \pkg{downlit} only -#' for R code. +#' There are three highlighting engines available to HTML documents: #' -#' highlightjs engine can only be used with the default template (i.e -#' \code{template = "default"}) and it has two styles ("default" and -#' "textmate"). When activated, it adds two additional dependencies to the -#' output file: a JS script and a CSS file. For now, this is the default engine for -#' the default template - this could change in the future. +#' \describe{ +#' \item{highlightjs}{It does highlighting in the browser, using javascript It +#' can only be used with the default template (i.e \code{template = "default"}) +#' and it has two styles ("default" and "textmate"). When activated, it adds +#' two additional dependencies to the output file: a JS script and a CSS file. +#' For now, this is the default engine for the default template - this could +#' change in the future.} #' -#' Pandoc built-in highlighting engine works with any template, default or -#' custom, and style can be chosen among the built-in ones ("tango", "pygments", -#' "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or -#' a path to a custom theme ".theme" file (see Details in the +#' \item{Pandoc}{Pandoc's built-in highlighting.engine works with any template, +#' default or custom, and style can be chosen among the built-in ones ("tango", +#' "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and +#' "breezedark") or a path to a custom theme ".theme" file (see Details in the #' \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). #' \pkg{rmarkdown} includes two custom themes to select with \code{highlight} #' parameter: #' \itemize{ -#' \item{"arrow", an accessible color theme derived from \href{https://www.a11yproject.com/}{optimized for +#' \item{"arrow", an accessible style using colors \href{https://www.a11yproject.com/}{optimized for #' accessibility and color contrast}} #' \item{"rstudio", a color scheme close to RStudio's default highlighting and #' highglightjs's textmate.} #' } -#' Custom themes are only available for Pandoc 2.0 and above. +#' Custom themes are only available for Pandoc 2.0 and above.} #' -#' \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that +#' \item{downlit}{\href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that #' provides a syntax highlighting engine in R. It will also do automatic #' linking of R code (requires internet connectivity). It is activated only if -#' \code{highlight_downlit} is \code{TRUE}. It only affects R code, leaving -#' highlighting for other languages unchanged. The default color scheme is -#' the accessible theme "arrow". +#' \code{highlight_downlit = TRUE} and only affects R code, leaving +#' highlighting for other languages unchanged. The default color scheme is +#' the accessible theme "arrow". #' #' It requires some CSS in the template to correctly style links. This is included #' in the default template, but if you want to use with a custom template, you will @@ -147,6 +150,7 @@ #' } #' #' $endif$} +#' }} #' #'@section Navigation Bars: #' diff --git a/man/html_document.Rd b/man/html_document.Rd index c4e317d703..1eca17d430 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -108,21 +108,24 @@ case you can use the \code{css} parameter to add your own styles).} Any other value will be passed to Pandoc's \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting style}. Pandoc's built-in styles include "tango", "pygments", "kate", - "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom - are also included, "arrow", for accessible color scheme and "rstudio", - to replicate RStudio editor theme. A path to a \samp{.theme} file can also be - passed to be used as a custom highlighting style for Pandoc. Note that custom - style are available for Pandoc 2.0+. + "monochrome", "espresso", "zenburn", "haddock" and "breezedark". + + Two custom styles are also included, "arrow", an accessible color scheme, + and "rstudio", which mimics the default IDE theme. Alternatively, supply a + path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This + requires Pandoc 2.0+) Pass \code{NULL} to prevent syntax highlighting.} \item{highlight_downlit}{\code{TRUE} to use the \pkg{downlit} package as -syntax highlight engine to highlight inline code and R code chunks -(including providing hyperlinks to function documentation). Only Pandoc -color schemes are supported with this engine. With \code{highlight} -"default", it will use the accessible theme called "arrow". To learn more -about \pkg{downlit} highlighting engine, see -\url{https://downlit.r-lib.org/}.} + syntax highlight engine to highlight inline code and R code chunks + (including providing hyperlinks to function documentation). The package + needs to be installed to use this feature. + + Only Pandoc color schemes are supported with this engine. With + \code{highlight = "default"}, it will use the accessible theme called + "arrow". To learn more about \pkg{downlit} highlighting engine, see + \url{https://downlit.r-lib.org/}.} \item{mathjax}{Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is @@ -179,40 +182,41 @@ and Citations} article in the online documentation. \section{Highlighting}{ - Different highlighting engines can be used with a R Markdown HTML documents: - highlightjs and Pandoc for all languages they support, \pkg{downlit} only - for R code. + There are three highlighting engines available to HTML documents: - highlightjs engine can only be used with the default template (i.e - \code{template = "default"}) and it has two styles ("default" and - "textmate"). When activated, a JS script and a CSS file are inserted into - the output HTML to make it works. For now, this is the default engine for - the default template - this could change in the future. + \describe{ + \item{highlightjs}{It does highlighting in the browser, using javascript It + can only be used with the default template (i.e \code{template = "default"}) + and it has two styles ("default" and "textmate"). When activated, it adds + two additional dependencies to the output file: a JS script and a CSS file. + For now, this is the default engine for the default template - this could + change in the future.} - Pandoc built-in highlighting engine works with any template, default or - custom, and style can be chosen among the built-in ones ("tango", "pygments", - "kate", "monochrome", "espresso", "zenburn", "haddock" and "breezedark") or - among some custom theme passed as ".theme" files (see Details in the + \item{Pandoc}{Pandoc's built-in highlighting.engine works with any template, + default or custom, and style can be chosen among the built-in ones ("tango", + "pygments", "kate", "monochrome", "espresso", "zenburn", "haddock" and + "breezedark") or a path to a custom theme ".theme" file (see Details in the \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{Pandoc Manual}). \pkg{rmarkdown} includes two custom themes to select with \code{highlight} parameter: \itemize{ - \item{"arrow", an accessible color theme derived from \href{https://www.a11yproject.com/}{optimized for + \item{"arrow", an accessible style using colors \href{https://www.a11yproject.com/}{optimized for accessibility and color contrast}} \item{"rstudio", a color scheme close to RStudio's default highlighting and highglightjs's textmate.} } - Custom theme are only available for Pandoc 2.0 and above. + Custom themes are only available for Pandoc 2.0 and above.} - \href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that + \item{downlit}{\href{https://downlit.r-lib.org/}{\pkg{downlit}} is an R package that provides a syntax highlighting engine in R. It will also do automatic linking of R code (requires internet connectivity). It is activated only if - \code{highlight_downlit} is \code{TRUE} and will pass after Pandoc engine to - replace only R code syntax highlighting and will use any selected Pandoc's - style. Default color scheme is the accessible theme "arrow". If default - template is used, some CSS is added to get the link introduced by - autolinking to use the color scheme chosen. If you want to use with a custom - template, add this to your template: + \code{highlight_downlit = TRUE} and only affects R code, leaving + highlighting for other languages unchanged. The default color scheme is + the accessible theme "arrow". + + It requires some CSS in the template to correctly style links. This is included + in the default template, but if you want to use with a custom template, you will + need to add this to your template: \preformatted{ $if(highlight-downlit)$ @@ -224,6 +228,7 @@ $if(highlight-downlit)$ } $endif$} + }} } \section{Navigation Bars}{ diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index 41bf0a0137..2132f17d53 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -72,11 +72,12 @@ case you can use the \code{css} parameter to add your own styles).} Any other value will be passed to Pandoc's \href{https://pandoc.org/MANUAL.html#syntax-highlighting}{highlighting style}. Pandoc's built-in styles include "tango", "pygments", "kate", - "monochrome", "espresso", "zenburn", "haddock" and "breezedark". Two custom - are also included, "arrow", for accessible color scheme and "rstudio", - to replicate RStudio editor theme. A path to a \samp{.theme} file can also be - passed to be used as a custom highlighting style for Pandoc. Note that custom - style are available for Pandoc 2.0+. + "monochrome", "espresso", "zenburn", "haddock" and "breezedark". + + Two custom styles are also included, "arrow", an accessible color scheme, + and "rstudio", which mimics the default IDE theme. Alternatively, supply a + path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This + requires Pandoc 2.0+) Pass \code{NULL} to prevent syntax highlighting.} diff --git a/man/md_document.Rd b/man/md_document.Rd index 277bd276de..76b6db2e19 100644 --- a/man/md_document.Rd +++ b/man/md_document.Rd @@ -70,7 +70,7 @@ additional details.} \item{pandoc_args}{Additional command line options to pass to pandoc} -\item{ext}{Extension of the output document (defaults to ".md").} +\item{ext}{Extension of the output file (defaults to ".md").} } \value{ R Markdown output format to pass to \code{\link{render}} From c7e331c9bd70f386bd2aad8d6ee9bc4df92089c2 Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Wed, 2 Dec 2020 22:34:35 +0100 Subject: [PATCH 44/53] update arrow.theme to last changes following rstudio/distill#229 from @apreshill --- inst/rmarkdown/highlight/arrow.theme | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/inst/rmarkdown/highlight/arrow.theme b/inst/rmarkdown/highlight/arrow.theme index f9ce133935..2ca31f6cc4 100644 --- a/inst/rmarkdown/highlight/arrow.theme +++ b/inst/rmarkdown/highlight/arrow.theme @@ -61,21 +61,21 @@ "underline": false }, "Error": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, "underline": false }, "BaseN": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, "underline": false }, "Alert": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, @@ -103,7 +103,7 @@ "underline": false }, "Preprocessor": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, @@ -152,14 +152,14 @@ "underline": false }, "DataType": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, "underline": false }, "Float": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, @@ -180,7 +180,7 @@ "underline": false }, "Constant": { - "text-color": "#A8602C", + "text-color": "#8f5902", "background-color": null, "bold": false, "italic": false, @@ -194,7 +194,7 @@ "underline": false }, "DecVal": { - "text-color": "#B8003C", + "text-color": "#AD0000", "background-color": null, "bold": false, "italic": false, From 518d8ae577aa63d09f9c9b38942575f16a8c7bca Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Wed, 9 Dec 2020 18:32:38 +0100 Subject: [PATCH 45/53] Add a reminder comment for #1976 --- R/pandoc.R | 3 +++ 1 file changed, 3 insertions(+) diff --git a/R/pandoc.R b/R/pandoc.R index 66c8fc17a1..1af7e0106d 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -554,6 +554,9 @@ pandoc_html_highlight_args <- function(template, highlight, highlight_downlit = FALSE) { + # Reminder: we do not use pandoc_path_arg() for argument to --highlight-style + # https://github.com/rstudio/rmarkdown/issues/1976 + args <- c() # no highlighting engine From a5588486e616669f729dea856d806a88dcccd6fe Mon Sep 17 00:00:00 2001 From: christophe dervieux Date: Wed, 10 Mar 2021 18:03:52 +0100 Subject: [PATCH 46/53] Arrow theme tweaks from rstudio/distill#338 --- inst/rmarkdown/highlight/arrow.theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/highlight/arrow.theme b/inst/rmarkdown/highlight/arrow.theme index 2ca31f6cc4..e3f35d56c5 100644 --- a/inst/rmarkdown/highlight/arrow.theme +++ b/inst/rmarkdown/highlight/arrow.theme @@ -12,7 +12,7 @@ "underline": false }, "Attribute": { - "text-color": "#20794D", + "text-color": null, "background-color": null, "bold": false, "italic": false, @@ -187,7 +187,7 @@ "underline": false }, "SpecialChar": { - "text-color": "#20794D", + "text-color": "#5E5E5E", "background-color": null, "bold": false, "italic": false, From 932b0ddabadb270ce0c522b886e390d51c8fc34e Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jan 2022 16:00:50 +0100 Subject: [PATCH 47/53] missing word in documentation --- R/html_document.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/html_document.R b/R/html_document.R index 126d5f392f..9b081587fe 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -71,8 +71,8 @@ #' #' Two custom styles are also included, "arrow", an accessible color scheme, #' and "rstudio", which mimics the default IDE theme. Alternatively, supply a -#' path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This -#' requires Pandoc 2.0+) +#' path to a \samp{.theme} to use a custom Pandoc style. Note that custom theme +#' requires Pandoc 2.0+. #' #' Pass \code{NULL} to prevent syntax highlighting. #' From 36ce5d20d2de908b0358f85b02b222cf70203d76 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jan 2022 16:01:01 +0100 Subject: [PATCH 48/53] Update requirement for downlit in Suggests --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 13074c2340..bb6102296e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -75,7 +75,7 @@ Suggests: dygraphs, fs, rsconnect, - downlit (>= 0.2.1), + downlit (>= 0.4.0), sass (>= 0.4.0), shiny (>= 1.6.0), testthat (>= 3.0.0), From d1a9a6bd19e0c8735b2b89cc8d2f14f752f4633a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jan 2022 16:07:28 +0100 Subject: [PATCH 49/53] typo --- R/html_document.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/html_document.R b/R/html_document.R index 9b081587fe..e0fd4d5508 100644 --- a/R/html_document.R +++ b/R/html_document.R @@ -581,7 +581,7 @@ html_document <- function(toc = FALSE, args } - # post-processor that use the output file from pandoc + # post-processor that uses the output file from pandoc post_processor <- function(metadata, input_file, output_file, clean, verbose) { # add a post processor for syntax highlighting with downlit if requested From 2345a805aa86af45fbbecfb951d820adafe59e0a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Thu, 13 Jan 2022 17:38:50 +0100 Subject: [PATCH 50/53] Correctly test as `template` can be NULL --- R/pandoc.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pandoc.R b/R/pandoc.R index 9a067aeb18..fe60b28e0a 100644 --- a/R/pandoc.R +++ b/R/pandoc.R @@ -605,7 +605,7 @@ pandoc_html_highlight_args <- function(template, # variable used to insert some css in a Pandoc template pandoc_variable_arg("highlight-downlit") ) - } else if (template == "default" && is_highlightjs(highlight)) { + } else if (identical(template, "default") && is_highlightjs(highlight)) { # highlightjs engine for default template only args <- c(pandoc_highlight_args(NULL), # variable used to insert some css and js From d63608d8782af533959ce8c38f8fbe1959af73dc Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Jan 2022 10:52:14 +0100 Subject: [PATCH 51/53] Add NEWS bullet and bump version [skip ci] --- DESCRIPTION | 2 +- NEWS.md | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index bb6102296e..2812f98d60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: rmarkdown Title: Dynamic Documents for R -Version: 2.11.6 +Version: 2.11.7 Authors@R: c( person("JJ", "Allaire", , "jj@rstudio.com", role = "aut"), person("Yihui", "Xie", , "xie@yihui.name", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-0645-5666")), diff --git a/NEWS.md b/NEWS.md index d9420952da..005c0bffa0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,11 @@ rmarkdown 2.12 ================================================================================ +- Improved the highlighting mechanism for HTML outputs: + * It is now possible to pass a custom theme file `.theme` in `highlight` argument for customizing the [syntax highlighting style used by Pandoc](https://pandoc.org/MANUAL.html#syntax-highlighting). + * In addition to Pandoc's own supported themes, two more themes are bundled in the package: `highlight: arrow` a theme [optimized for accessibility and color constrast](https://www.a11yproject.com/) (thanks to @apreshill), and `highlight: rstudio` to mimic the RStudio editor theme. + * Added optional [downlit](https://downlit.r-lib.org/) support in `html_document()` for R syntax highlighting and autolinking. Use `highlight_downlit = TRUE` to activate it (same argument as in **distill**). This features require the **downlit** package. + - Added a global option `rmarkdown.html_dependency.header_attr` (`TRUE` by default). It can be set to `FALSE` to opt-out the HTML dependency `html_dependency_header_attrs()` in documents based on `html_document_base()` (thanks, @salim-b rstudio/bookdown#865, @maelle r-lib/downlit#1538). - `draft()` now works with `devtools::load_all()` and **testthat** when used in other packages. From 5f9299d896c1d3deb6411b31fdeafc6c99c2faf0 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Jan 2022 10:54:42 +0100 Subject: [PATCH 52/53] Rebuild documentation --- man/html_document.Rd | 4 ++-- man/html_notebook.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/man/html_document.Rd b/man/html_document.Rd index 662fb3bd5d..48d797b63f 100644 --- a/man/html_document.Rd +++ b/man/html_document.Rd @@ -126,8 +126,8 @@ style}. Pandoc's built-in styles include "tango", "pygments", "kate", Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a -path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This -requires Pandoc 2.0+) +path to a \samp{.theme} to use a custom Pandoc style. Note that custom theme +requires Pandoc 2.0+. Pass \code{NULL} to prevent syntax highlighting.} diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index 9b706250de..8c5d53b8f9 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -85,8 +85,8 @@ style}. Pandoc's built-in styles include "tango", "pygments", "kate", Two custom styles are also included, "arrow", an accessible color scheme, and "rstudio", which mimics the default IDE theme. Alternatively, supply a -path to a \samp{.theme} to use a custom Pandoc style. Note that custom (This -requires Pandoc 2.0+) +path to a \samp{.theme} to use a custom Pandoc style. Note that custom theme +requires Pandoc 2.0+. Pass \code{NULL} to prevent syntax highlighting.} From 0e3863f47cfab52ef92e4eea4d1ca7c6886eb6d4 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 14 Jan 2022 11:04:59 +0100 Subject: [PATCH 53/53] Add correct support for highlight_downlit in html_notebook default needs to be change to a pandoc theme instead when `highlight_downlit` is TRUE --- R/html_notebook.R | 5 +++++ man/html_notebook.Rd | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/R/html_notebook.R b/R/html_notebook.R index 019aedad8b..9dc435c465 100644 --- a/R/html_notebook.R +++ b/R/html_notebook.R @@ -27,6 +27,7 @@ html_notebook <- function(toc = FALSE, code_folding = "show", theme = "default", highlight = "textmate", + highlight_downlit = FALSE, mathjax = "default", extra_dependencies = NULL, css = NULL, @@ -189,6 +190,9 @@ html_notebook <- function(toc = FALSE, extra_dependencies <- append(extra_dependencies, list(html_dependency_pagedtable())) + # Change default value of highlight theme if downlit is to be used + if (highlight_downlit && missing(highlight)) highlight <- "default" + # generate actual format base_format <- html_document(toc = toc, toc_depth = toc_depth, @@ -201,6 +205,7 @@ html_notebook <- function(toc = FALSE, code_folding = code_folding, theme = theme, highlight = highlight, + highlight_downlit = highlight_downlit, mathjax = mathjax, extra_dependencies = extra_dependencies, css = css, diff --git a/man/html_notebook.Rd b/man/html_notebook.Rd index 8c5d53b8f9..06fb2fd337 100644 --- a/man/html_notebook.Rd +++ b/man/html_notebook.Rd @@ -16,6 +16,7 @@ html_notebook( code_folding = "show", theme = "default", highlight = "textmate", + highlight_downlit = FALSE, mathjax = "default", extra_dependencies = NULL, css = NULL, @@ -90,6 +91,16 @@ requires Pandoc 2.0+. Pass \code{NULL} to prevent syntax highlighting.} +\item{highlight_downlit}{\code{TRUE} to use the \pkg{downlit} package as +syntax highlight engine to highlight inline code and R code chunks +(including providing hyperlinks to function documentation). The package +needs to be installed to use this feature. + +Only Pandoc color schemes are supported with this engine. With +\code{highlight = "default"}, it will use the accessible theme called +"arrow". To learn more about \pkg{downlit} highlighting engine, see +\url{https://downlit.r-lib.org/}.} + \item{mathjax}{Include mathjax. The "default" option uses an https URL from a MathJax CDN. The "local" option uses a local version of MathJax (which is copied into the output directory). You can pass an alternate URL or pass