Skip to content

support code syntax highlighting #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions R/decorate_chunk.R
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ decorate_chunk <- function(chunk_name,

attr(knitted, "orig_chunk_text") <- my_code

attr(knitted, "engine") <- my_engine

return(knitted)

}
Expand Down
8 changes: 4 additions & 4 deletions R/with_flair.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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) ", "&nbsp;")
Expand Down Expand Up @@ -87,7 +87,7 @@ prep_source <- function(x, doc_type = "unknown") {

} else if (doc_type == "html_document") {

x <- paste0("<pre class='prettyprint'>", txt_tocode(x), "</pre>")
x <- paste0("<pre class='prettyprint ", src_type, "'>", txt_tocode(x), "</pre>")

} else if (doc_type == "ioslides_presentation") {

Expand Down