Created
May 27, 2021 14:20
-
-
Save cderv/19d746aededd599a9402895e866247cc to your computer and use it in GitHub Desktop.
List format and extensions from Pandoc in R
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pandoc_list_extension <- function(format = "markdown") { | |
res <- processx::run(rmarkdown::pandoc_exec(), c("--list-extension", format)) | |
tmp_file <- tempfile() | |
on.exit(unlink(tmp_file)) | |
brio::write_file(res$stdout, tmp_file) | |
ext <- brio::read_lines(tmp_file) | |
tibble::tibble( | |
format = format, | |
extensions = gsub("^[-+]", "", extensions), | |
default = ifelse(gsub("^([-+]{1}).*", "\\1", ext) == "+", TRUE, FALSE) | |
) | |
} | |
pandoc_list_format <- function(type = c("input", "output")) { | |
rlang::arg_match(type) | |
flag <- sprintf("--list-%s-formats", type) | |
res <- processx::run(rmarkdown::pandoc_exec(), flag) | |
tmp_file <- tempfile() | |
on.exit(unlink(tmp_file)) | |
brio::write_file(res$stdout, tmp_file) | |
formats <- brio::read_lines(tmp_file) | |
tibble::tibble( | |
type = type, | |
formats = formats | |
) | |
} | |
gfm <- pandoc_list_extension("gfm") | |
markdown <- pandoc_list_extension("markdown") | |
# all formats | |
input_formats <- pandoc_list_format("input") | |
all_extensions <- purrr::map_df(input_formats$formats, pandoc_list_extension) | |
all_extensions %>% | |
filter(default) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment