Skip to content

Commit

Permalink
protect the rendered meta variables in I() so they can't be possibly …
Browse files Browse the repository at this point in the history
…treated as files, e.g., title = 'a cool js library foo.js'
  • Loading branch information
yihui committed Sep 11, 2024
1 parent 88c750f commit 3a768f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: litedown
Type: Package
Title: A Lightweight Version of R Markdown
Version: 0.2.1
Version: 0.2.2
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person()
Expand Down
10 changes: 5 additions & 5 deletions R/mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
render = function(x, clean = FALSE) {
if (length(x) == 0) return(x)
res = do.call(render_fun, c(list(text = x), render_args))
if (clean) res = I(gsub('^<p[^>]*>|(</p>)?\n$', '', res))
res
if (clean) res = gsub('^<p[^>]*>|(</p>)?\n$', '', res)
I(res)
}

if (isTRUE(options[['smartypants']])) text = smartypants(text)
Expand Down Expand Up @@ -312,7 +312,7 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
for (i in top_meta) if (length(meta[[i]])) {
meta[[i]] = render(meta[[i]], clean = i != 'abstract')
# also provide *_ version of top-level meta variables, containing tags/commands
meta[[paste0(i, '_')]] = if (format == 'html') {
meta[[paste0(i, '_')]] = I(if (format == 'html') {
tag = tag_meta[i]
sprintf(
'<div class="%s">%s</div>', i, if (tag == '') meta[[i]] else sprintf(
Expand All @@ -321,7 +321,7 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
)
} else if (format == 'latex') {
sprintf(cmd_meta[i], meta[[i]])
}
})
}
# use the template (if provided) to create a standalone document
if (format %in% c('html', 'latex') && is.character(template)) {
Expand Down Expand Up @@ -375,7 +375,7 @@ build_output = function(format, options, template, meta) {
if (!name %in% names(meta)) meta[[name]] <<- value
}
set_meta('css', 'default')
set_meta('plain-title', str_trim(commonmark::markdown_text(meta[['title']])))
set_meta('plain-title', I(str_trim(commonmark::markdown_text(meta[['title']]))))
meta = set_math(meta, options, b)
meta = set_highlight(meta, options, b)
# if the class .line-numbers is present, add js/css for line numbers
Expand Down

0 comments on commit 3a768f6

Please sign in to comment.