Skip to content
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

Merged
merged 13 commits into from
Jan 14, 2022
Merged

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented Jan 14, 2022

This PR follows #1941 by adding support for custom highlight .theme file in other format like PDF

this 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

R/pandoc.R Outdated
Comment on lines 609 to 615
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)
Copy link
Collaborator Author

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.

Comment on lines +631 to +641
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
Copy link
Collaborator Author

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.

@cderv cderv requested a review from yihui January 14, 2022 14:50
Copy link
Member

@yihui yihui left a 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!

R/pandoc.R Outdated Show resolved Hide resolved
@cderv cderv merged commit fa15300 into main Jan 14, 2022
@cderv cderv deleted the pdf-highlight-theme-file branch January 14, 2022 17:48
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow to load external highlighting theme for Pandoc HTML and PDF
2 participants