Skip to content

Commit

Permalink
ignore the knitr.unbalanced.chunk option and strictly prohibit unba…
Browse files Browse the repository at this point in the history
…lanced chunk fences
  • Loading branch information
yihui committed Sep 18, 2024
1 parent 7bcec09 commit 450c466
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

- In-chunk references of the form `<<label>>` should not be resolved if `label` is not found in the document (thanks, @jennybc @gadenbuie, #2360).

## MAJOR CHANGES

- Unbalanced chunk delimiters (fences) in R Markdown documents are strictly prohibited now.

# CHANGES IN knitr VERSION 1.48

## BUG FIXES
Expand Down
5 changes: 1 addition & 4 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,14 @@ match_chunk_end = function(pattern, line, i, b, lines) {
if (!any(match_chunk_begin(pattern, lines[i + 1:(k - 1)], '^\\1`*\\\\{')))
return(FALSE)
}
# TODO: clean up the exceptions here (although perhaps some may never update again)
signal = if (getOption('knitr.unbalanced.chunk', FALSE)) warning2 else stop2
signal(
stop2(
'The closing fence on line ', i, ' ("', line, '") in ', current_input(),
' does not match the opening fence "',
gsub('\\^(\\s*`+).*', '\\1', pattern), '" on line ', b, '. You are recommended to ',
'fix either the opening or closing fence of the code chunk to use exactly ',
'the same numbers of backticks and same level of indentation (or blockquote). ',
'See https://yihui.org/en/2021/10/unbalanced-delimiters/ for more info.'
)
TRUE
}

#' Get all chunk labels in a document
Expand Down

0 comments on commit 450c466

Please sign in to comment.