diff --git a/DESCRIPTION b/DESCRIPTION index 92893d0..c35ef1a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: litedown Type: Package Title: A Lightweight Version of R Markdown -Version: 0.5.2 +Version: 0.5.3 Authors@R: c( person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")), person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")), diff --git a/R/format.R b/R/format.R index 135b996..8fec9a3 100644 --- a/R/format.R +++ b/R/format.R @@ -99,13 +99,18 @@ map_args = function( list(meta = meta, options = opts, ...) } -# split YAML and body from text input, and normalize rmarkdown output formats in -# YAML to litedown's formats +# split YAML and body from text input yaml_body = function(text, ...) { res = xfun::yaml_body(text, use_yaml = FALSE, ...) - if (!length(out <- res$yaml[['output']])) { + if (!is.null(yaml <- normalize_yaml(res$yaml))) res$yaml = yaml + res +} + +# normalize (rmarkdown) output formats in YAML to litedown's formats +normalize_yaml = function(x) { + if (!length(out <- x[['output']])) { # if the key 'format' is provided, normalize it to 'output' - if (length(out <- res$yaml[['format']])) res$yaml$format = NULL else return(res) + if (length(out <- x[['format']])) x$format = NULL else return() } if (is.character(out)) out = set_names(vector('list', length(out)), out) if (!is.list(out)) @@ -117,8 +122,8 @@ yaml_body = function(text, ...) { } # normalize format names `(lite|mark)down::*_format` to `*` names(out) = gsub('^(lite|mark)down::+([^_]+)_.*', '\\2', names(out)) - res$yaml$output = out - res + x$output = out + x } # get metadata from a certain field under an output format diff --git a/R/site.R b/R/site.R index 7f6c412..17b9525 100644 --- a/R/site.R +++ b/R/site.R @@ -261,7 +261,11 @@ fuse_book = function(input = '.', output = NULL, envir = parent.frame()) { # read the config file _litedown.yml yml_config = function(d) { - if (file_exists(cfg <- file.path(d, '_litedown.yml'))) xfun::taml_file(cfg) + if (file_exists(cfg <- file.path(d, '_litedown.yml'))) { + yaml = xfun::taml_file(cfg) + if (!is.null(yaml2 <- normalize_yaml(yaml))) yaml = yaml2 + yaml + } } site_pattern = '[.][Rq]?md$'