Skip to content

Commit

Permalink
closes yihui#110 by adding a new component in patterns: inline.comment
Browse files Browse the repository at this point in the history
inline comments will be stripped off; this only happens to LaTeX currently
  • Loading branch information
yihui committed Jun 4, 2012
1 parent d32b5b4 commit 9d4970c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ print.block = function(x, ...) {

## extract inline R code fragments (as well as global options)
parse_inline = function(input) {
inline.comment = knit_patterns$get('inline.comment')
if (!is.null(inline.comment)) {
input = str_replace(input, inline.comment, '') # strip off inline comments
}
input = str_c(input, collapse = '\n') # merge into one line

locate_inline = function(input, pattern) {
Expand Down
2 changes: 2 additions & 0 deletions R/pattern.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ all_patterns = list(
`rnw` = list(chunk.begin = '^<<(.*)>>=', chunk.end = '^@\\s*%*',
inline.code = '\\\\Sexpr\\{([^}]*)\\}',
input.doc = '(^|\n) *\\\\SweaveInput\\{([^}]*)\\}',
inline.comment = '^\\s*%.*',
ref.chunk = '^\\s*<<(.*)>>\\s*$',
global.options = '\\\\SweaveOpts\\{([^}]*)\\}',
header.begin = '\n*\\s*\\\\documentclass[^}]+\\}',
Expand All @@ -21,6 +22,7 @@ all_patterns = list(
`tex` = list(chunk.begin = '^%+\\s*begin.rcode\\s*(.*)',
chunk.end = '^%+\\s*end.rcode', chunk.code = '^%+',
ref.chunk = '^%+\\s*<<(.*)>>\\s*$',
inline.comment = '^\\s*%.*',
global.options = '%+\\s*roptions\\s*([^\n]*)',
inline.code = '\\\\rinline\\{([^}]*)\\}',
header.begin = '\n*\\s*\\\\documentclass[^}]+\\}',
Expand Down

0 comments on commit 9d4970c

Please sign in to comment.