Skip to content

Commit

Permalink
Merge remote branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ramnathv committed Apr 11, 2012
2 parents 289619e + 90e5667 commit 67ae3a0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
3 changes: 2 additions & 1 deletion R/defaults.R
Expand Up @@ -109,7 +109,8 @@ all_patterns =
ref.label = '^## @knitr (.*)$'),

`md` = list(chunk.begin = '^``` \\{r(.*)\\}\\s*$',
chunk.end = '^````\\s*$',
chunk.end = '^```\\s*$',
chunk.end.is.terminator = TRUE,
ref.chunk = '^\\s*<<(.*)>>\\s*$',
inline.code = '`r\\s+([^`]*)\\s*`',
global.options = '`ro\\s+([^`]*)\\s+or`',
Expand Down
20 changes: 20 additions & 0 deletions R/parser.R
Expand Up @@ -16,6 +16,8 @@ split_file = function(path, lines = readLines(path, warn = FALSE), set.preamble

blks = str_detect(lines, chunk.begin)
txts = str_detect(lines, chunk.end)
if (isTRUE(as.logical(knit_patterns$get('chunk.end.is.terminator'))))
txts = filter_chunk_end(blks, txts)

tmp = logical(n); tmp[blks | txts] = TRUE; lines[txts] = ''

Expand Down Expand Up @@ -271,3 +273,21 @@ parse_chunk = function(x) {
}), use.names = FALSE)
x
}

## filter chunk.end lines that don't actually end a chunk
filter_chunk_end = function(chunk.begin, chunk.end) {
in.chunk = FALSE
fun = function(is.begin, is.end) {
if (in.chunk && is.end) {
in.chunk <<- FALSE
return(TRUE)
}
else if (!in.chunk && is.begin) {
in.chunk <<- TRUE
return(FALSE)
}
else
return(FALSE)
}
mapply(fun, chunk.begin, chunk.end)
}
3 changes: 2 additions & 1 deletion R/pattern.R
@@ -1,5 +1,6 @@
## initial pattern list
.pat.init = list(chunk.begin = NULL, chunk.end = NULL, chunk.code = NULL,
.pat.init = list(chunk.begin = NULL, chunk.end = NULL,
chunk.end.is.terminator = NULL, chunk.code = NULL,
inline.code = NULL, global.options = NULL, input.doc = NULL,
ref.chunk = NULL, header.begin = NULL, document.begin = NULL,
ref.label = NULL)
Expand Down

0 comments on commit 67ae3a0

Please sign in to comment.