Skip to content

Commit

Permalink
use html_escape() in xfun 0.48
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Oct 4, 2024
1 parent 2dc1e4a commit 0f59bba
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 14 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: knitr
Type: Package
Title: A General-Purpose Package for Dynamic Report Generation in R
Version: 1.48.5
Version: 1.48.6
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Abhraneel", "Sarma", role = "ctb"),
Expand Down Expand Up @@ -120,7 +120,7 @@ Imports:
highr (>= 0.11),
methods,
tools,
xfun (>= 0.44),
xfun (>= 0.48),
yaml (>= 2.1.19)
Suggests:
bslib,
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import(utils)
importFrom(xfun,attr)
importFrom(xfun,file_ext)
importFrom(xfun,file_string)
importFrom(xfun,html_escape)
importFrom(xfun,is_R_CMD_check)
importFrom(xfun,is_abs_path)
importFrom(xfun,is_windows)
Expand Down
2 changes: 1 addition & 1 deletion R/highlight.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ hilight_source = function(x, format, options) {
} else {
res = try(highr::hi_andre(x, options$engine, format))
if (inherits(res, 'try-error')) {
if (format == 'html') highr:::escape_html(x) else highr:::escape_latex(x)
if (format == 'html') html_escape(x) else highr:::escape_latex(x)
} else {
highlight_header()
n = length(res)
Expand Down
4 changes: 2 additions & 2 deletions R/hooks-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ hook_animation = function(options) {
if (length(cap) == 0) cap = ''
if (alt) {
alt = options$fig.alt %n% cap
return(if (escape) escape_html(alt) else alt)
return(if (escape) html_escape(alt) else alt)
}
if (is_blank(cap)) return(cap)
paste0(create_label(
Expand Down Expand Up @@ -255,7 +255,7 @@ hooks_html = function() {
if (name == 'output' && output_asis(x, options)) return(x)
x = if (name == 'source') {
c(hilight_source(x, 'html', options), '')
} else escape_html(x)
} else html_escape(x)
x = one_string(x)
sprintf('<div class="%s"><pre class="knitr %s">%s</pre></div>\n', name, tolower(options$engine), x)
}
Expand Down
4 changes: 2 additions & 2 deletions R/hooks-md.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ hooks_jekyll = function(highlight = c('pygments', 'prettify', 'none'), extra = '
}, prettify = {
hook.r = function(x, options) {
paste0(
'\n\n<pre><code class="prettyprint ', extra, '">', escape_html(x),
'\n\n<pre><code class="prettyprint ', extra, '">', html_escape(x),
'</code></pre>\n\n'
)
}
hook.t = function(x, options) paste0(
'\n\n<pre><code>', escape_html(x), '</code></pre>\n\n'
'\n\n<pre><code>', html_escape(x), '</code></pre>\n\n'
)
})
source = function(x, options) {
Expand Down
2 changes: 1 addition & 1 deletion R/output.R
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ sew.knit_embed_url = function(x, options = opts_chunk$get(), inline = FALSE, ...
if (length(extra <- options$out.extra)) extra = paste('', extra, collapse = '')
add_html_caption(options, sprintf(
'<iframe src="%s" width="%s" height="%s" data-external="1"%s></iframe>',
escape_html(x$url), options$out.width %n% '100%', x$height %n% '400px',
html_escape(x$url), options$out.width %n% '100%', x$height %n% '400px',
extra %n% ''
))
}
Expand Down
2 changes: 1 addition & 1 deletion R/package.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' \code{knit} + \code{R} (while \code{Sweave} = \code{S} + \code{weave}).
#' @references Full documentation and demos: \url{https://yihui.org/knitr/};
#' FAQ's: \url{https://yihui.org/knitr/faq/}
#' @importFrom xfun attr file_ext is_windows loadable parse_only
#' @importFrom xfun attr file_ext html_escape is_windows loadable parse_only
#' sans_ext try_silent with_ext read_utf8 write_utf8 file_string
#' is_R_CMD_check is_abs_path
'_PACKAGE'
Expand Down
4 changes: 2 additions & 2 deletions R/table.R
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,11 @@ kable_html = function(
}
if (identical(caption, NA)) caption = NULL
cap = if (length(caption)) sprintf('\n<caption>%s</caption>', caption) else ''
if (escape) x = escape_html(x)
if (escape) x = html_escape(x)
one_string(c(
sprintf('<table%s>%s', table.attr, cap),
if (!is.null(cn <- colnames(x))) {
if (escape) cn = escape_html(cn)
if (escape) cn = html_escape(cn)
c(' <thead>', ' <tr>', sprintf(' <th%s> %s </th>', align, cn), ' </tr>', ' </thead>')
},
'<tbody>',
Expand Down
3 changes: 0 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -677,9 +677,6 @@ escape_latex = function(x, newlines = FALSE, spaces = FALSE) {
x
}

# escape special HTML chars
escape_html = highr:::escape_html

#' Read source code from R-Forge
#'
#' This function reads source code from the SVN repositories on R-Forge.
Expand Down

0 comments on commit 0f59bba

Please sign in to comment.