-
-
Notifications
You must be signed in to change notification settings - Fork 978
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
Support custom highlight theme in other formats #2285
Conversation
with different supportted value for PDF and HTML
[skip ci]
R/pandoc.R
Outdated
is_supported <- TRUE | ||
# for backward compatibility, partial match still need to work | ||
highlight <- tryCatch( | ||
error = function(e) { is_supported <<- FALSE; highlight }, | ||
match.arg(highlight, supported) | ||
) | ||
if (is_supported) return(highlight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did this change to bring back the partial matching feature that was there when match.arg()
was used. Meaning
this would work.
output:
html_document:
highlight: breez
It was not following my other PR.
highlight <- custom[[highlight]] %||% highlight | ||
# Check for extension or give informative error otherwise | ||
if (!identical(xfun::file_ext(highlight), "theme")) { | ||
msg <- c( | ||
sprintf("`highlight` argument must be one of %s", | ||
knitr::combine_words(c(supported, names(custom)), and = " or ", before = "`")), | ||
" or a file with extension `.theme`." | ||
) | ||
stop(msg, call. = FALSE) | ||
} | ||
highlight |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I then added that to throw early a useful message if the highlight
value is not one of the expected (either one supported theme or a file path to a .theme
file).
This makes code less simple than in the other PR but it brings back useful message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks!
This PR follows #1941 by adding support for custom highlight
.theme
file in other format like PDFthis will close #2035
It uses the same internal function as previous PR to support HTML but added a logic for non HTML format too.
I also brought back backward compatibility for partial matching of Pandoc's style name are
match.arg
was used before and also took the opportunity to add informative error message if unknown value is provided in order to error from R and not from Pandoc