From e30f23267855d0ed6dd6e24e667ec154a2919c3b Mon Sep 17 00:00:00 2001 From: Michael Chow Date: Thu, 19 Nov 2020 15:58:58 -0500 Subject: [PATCH] support code syntax highlighting --- R/decorate_chunk.R | 2 ++ R/with_flair.R | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/decorate_chunk.R b/R/decorate_chunk.R index 1083617..257cfd8 100644 --- a/R/decorate_chunk.R +++ b/R/decorate_chunk.R @@ -165,6 +165,8 @@ decorate_chunk <- function(chunk_name, attr(knitted, "orig_chunk_text") <- my_code + attr(knitted, "engine") <- my_engine + return(knitted) } diff --git a/R/with_flair.R b/R/with_flair.R index 8d1fdff..161d164 100644 --- a/R/with_flair.R +++ b/R/with_flair.R @@ -40,8 +40,8 @@ knit_print.with_flair <- function(x, ...) { } where_sources <- map(x, ~attr(.x, "class")) == "source" - - x[where_sources] <- map(x[where_sources], function(src) prep_source(src, doc_type)) + src_type = attr(x, "engine") + x[where_sources] <- map(x[where_sources], function(src) prep_source(src, doc_type, src_type)) x <- stringr::str_c(unlist(x), collapse = "\n") @@ -56,7 +56,7 @@ knit_print.with_flair <- function(x, ...) { #' #' @return Properly wrapped text. #' -prep_source <- function(x, doc_type = "unknown") { +prep_source <- function(x, doc_type = "unknown", src_type = "unknown") { x <- stringr::str_trim(x) %>% stringr::str_replace_all("(?<=\\s) ", " ") @@ -87,7 +87,7 @@ prep_source <- function(x, doc_type = "unknown") { } else if (doc_type == "html_document") { - x <- paste0("
", txt_tocode(x), "
") + x <- paste0("
", txt_tocode(x), "
") } else if (doc_type == "ioslides_presentation") {