Skip to content

Commit b4890d5

Browse files
committed
need to normalize the output formats when reading _litedown.yml for books/sites
1 parent c7a61e5 commit b4890d5

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.5.2
4+
Version: 0.5.3
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),

R/format.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,18 @@ map_args = function(
9999
list(meta = meta, options = opts, ...)
100100
}
101101

102-
# split YAML and body from text input, and normalize rmarkdown output formats in
103-
# YAML to litedown's formats
102+
# split YAML and body from text input
104103
yaml_body = function(text, ...) {
105104
res = xfun::yaml_body(text, use_yaml = FALSE, ...)
106-
if (!length(out <- res$yaml[['output']])) {
105+
if (!is.null(yaml <- normalize_yaml(res$yaml))) res$yaml = yaml
106+
res
107+
}
108+
109+
# normalize (rmarkdown) output formats in YAML to litedown's formats
110+
normalize_yaml = function(x) {
111+
if (!length(out <- x[['output']])) {
107112
# if the key 'format' is provided, normalize it to 'output'
108-
if (length(out <- res$yaml[['format']])) res$yaml$format = NULL else return(res)
113+
if (length(out <- x[['format']])) x$format = NULL else return()
109114
}
110115
if (is.character(out)) out = set_names(vector('list', length(out)), out)
111116
if (!is.list(out))
@@ -117,8 +122,8 @@ yaml_body = function(text, ...) {
117122
}
118123
# normalize format names `(lite|mark)down::*_format` to `*`
119124
names(out) = gsub('^(lite|mark)down::+([^_]+)_.*', '\\2', names(out))
120-
res$yaml$output = out
121-
res
125+
x$output = out
126+
x
122127
}
123128

124129
# get metadata from a certain field under an output format

R/site.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,11 @@ fuse_book = function(input = '.', output = NULL, envir = parent.frame()) {
261261

262262
# read the config file _litedown.yml
263263
yml_config = function(d) {
264-
if (file_exists(cfg <- file.path(d, '_litedown.yml'))) xfun::taml_file(cfg)
264+
if (file_exists(cfg <- file.path(d, '_litedown.yml'))) {
265+
yaml = xfun::taml_file(cfg)
266+
if (!is.null(yaml2 <- normalize_yaml(yaml))) yaml = yaml2
267+
yaml
268+
}
265269
}
266270

267271
site_pattern = '[.][Rq]?md$'

0 commit comments

Comments
 (0)