Skip to content

Commit

Permalink
55575cd was buggy; shouldn't add fences to <pre>, because <pre> might…
Browse files Browse the repository at this point in the history
… be inside fences already
  • Loading branch information
yihui committed Apr 21, 2024
1 parent 9e2a061 commit 4a0200e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: xfun
Type: Package
Title: Supporting Functions for Packages Maintained by 'Yihui Xie'
Version: 0.43.5
Version: 0.43.6
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre", "cph"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person("Wush", "Wu", role = "ctb"),
Expand Down
14 changes: 9 additions & 5 deletions R/markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@
#' prose_index(c('a', '```', 'b', '```', 'c'))
#' prose_index(c('a', '````', '```r', '1+1', '```', '````', 'c'))
prose_index = function(x, warn = TRUE) {
idx = NULL
# if raw HTML <pre></pre> exists, it should be treated as code block
if (any(grepl('^<pre>', x))) {
fence = make_fence(x)
i = grep('^<pre>|</pre>$', x)
x[i] = paste(fence, x[i])
inside_pre = if (length(p1 <- grep('<pre>', x))) {
p2 = grep('</pre>', x)
if (length(p1) == length(p2)) {
idx = rbind(p1, p2)
function(i) any(i > p1 & i < p2)
}
}
idx = NULL; r = '^(\\s*```+).*'; s = ''
r = '^(\\s*```+).*'; s = ''
# shouldn't match ``` ``text``` ```, which is inline code, not code block
i1 = grepl(r, x); i2 = !grepl('^\\s*```+\\s+`', x); i3 = !grepl('-->\\s*$', x)
for (i in which(i1 & i2 & i3)) {
if (is.function(inside_pre) && inside_pre(i)) next
if (s == '') {
s = gsub(r, '\\1', x[i]); idx = c(idx, i); next
}
Expand Down
2 changes: 1 addition & 1 deletion man/yaml_body.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a0200e

Please sign in to comment.