Skip to content

Commit

Permalink
make it possible to style as-is output via the chunk option attr.asis
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 9, 2024
1 parent 0e82269 commit 6e2bdbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

- Fixed a bug that when LaTeX math environments are written in raw LaTeX blocks (i.e., ```` ```{=latex}````), `mark()` will not load the math JS library such as MathJax or KaTeX unless `$ $` or `$$ $$` expressions are present in the document.

- As-is output accepts attributes via the chunk option `attr.asis` now. If provided, as-is output will be wrapped in a fenced Div with these attributes.

# CHANGES IN litedown VERSION 0.2

- A data frame (or matrix/tibble) wrapped in `I()` is fully printed to a table now by default. Without `I()`, data objects are truncated to 10 rows by default when printing to tables.
Expand Down
17 changes: 11 additions & 6 deletions R/fuse.R
Original file line number Diff line number Diff line change
Expand Up @@ -717,10 +717,10 @@ fuse_code = function(x, blocks) {
x = one_string(x)
if (opts$strip.white) x = str_trim(x)
}
if (type %in% c('output', 'asis')) {
asis = if (type %in% c('output', 'asis')) {
if (opts$results == 'hide') return()
if (any(c(opts$results, type) == 'asis')) return(x)
}
any(c(opts$results, type) == 'asis')
} else FALSE
if (type == 'warning' && !isTRUE(opts$warning)) return()
if (type == 'message' && !isTRUE(opts$message)) return()
if (type == 'plot') {
Expand All @@ -741,10 +741,14 @@ fuse_code = function(x, blocks) {
)
} else {
if (type == 'message') x = sub('\n$', '', x)
x = split_lines(x)
x = paste0(opts$comment, x) # comment out text output
if (!asis) {
x = split_lines(x)
x = paste0(opts$comment, x) # comment out text output
}
}
fenced_block(x, a, fence)
if (asis) {
if (is.null(a)) x else fenced_div(x, a)
} else fenced_block(x, a, fence)
}
})
a = opts$attr.chunk
Expand Down Expand Up @@ -904,6 +908,7 @@ reactor(
wd = NULL
)

# the R engine
eng_r = function(x, inline = FALSE, ...) {
opts = reactor()
if (inline) {
Expand Down

0 comments on commit 6e2bdbb

Please sign in to comment.