diff --git a/NEWS.md b/NEWS.md index 875554f97..04a113978 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # pkgdown (development version) +* Syntax highlighting works on Windows once more (#1282) + * Rendering empty `.md` file now returns empty string (#1285). * `build_articles_index()` is now exported to rapidly rebuild the index (#1281) diff --git a/R/highlight.r b/R/highlight.r index 75052ddfb..0026ff662 100644 --- a/R/highlight.r +++ b/R/highlight.r @@ -4,6 +4,7 @@ highlight_text <- function(text) { stopifnot(is.character(text), length(text) == 1) + text <- gsub("\r", "", text) expr <- tryCatch( parse(text = text, keep.source = TRUE), error = function(e) NULL @@ -11,7 +12,7 @@ highlight_text <- function(text) { # Failed to parse, or yielded empty expression if (length(expr) == 0) { - return(text) + return(escape_html(text)) } packages <- extract_package_attach(expr) diff --git a/tests/testthat/test-highlight.R b/tests/testthat/test-highlight.R index e6e01bfc4..d9c471962 100644 --- a/tests/testthat/test-highlight.R +++ b/tests/testthat/test-highlight.R @@ -43,3 +43,18 @@ test_that("can link to implicit base topics", { "median()" ) }) + +test_that("can parse code with carriage returns", { + scoped_package_context("test") + + expect_equal( + highlight_text("1\r\n2"), + "1\n2" + ) +}) + +test_that("unparsed code is still escaped", { + scoped_package_context("test") + + expect_equal(highlight_text("<"), "<") +})