Skip to content

Commit

Permalink
Gobble longest common whitespace (yihui#1391)
Browse files Browse the repository at this point in the history
* Gobble longest common whitespace

* Update DESCRIPTION and NEWS.md
  • Loading branch information
thisirs authored and yihui committed Apr 13, 2017
1 parent 6f166e2 commit 082204f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Authors@R: c(
person("Sebastian", "Meyer", role = "ctb"),
person("Sietse", "Brouwer", role = "ctb"),
person(c("Simon", "de"), "Bernard", role = "ctb"),
person("Sylvain", "Rousseau", role = "ctb"),
person("Taiyun", "Wei", role = "ctb"),
person("Thibaut", "Assus", role = "ctb"),
person("Thibaut", "Lamadon", role = "ctb"),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- added a wrapper function `knit2pandoc()`, and reStructuredText vignettes will be compiled through Pandoc instead of rst2pdf (thanks, @trevorld, #1386)

- longest common whitespace prefix in code chunks is now stripped off along with the eventual prefix (see #1391)

## MAJOR CHANGES

- a warning will be emitted when the chunk option `fig.show='hold'` and the output format is Word (https://github.com/rstudio/bookdown/issues/249); `fig.show='hold'` will be changed to `'asis'` at the same time
Expand Down
6 changes: 5 additions & 1 deletion R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ knit_code = new_defaults()

# strip the pattern in code
strip_block = function(x, prefix = NULL) {
if (!is.null(prefix) && (length(x) > 1)) x[-1L] = sub(prefix, '', x[-1L])
if (!is.null(prefix) && (length(x) > 1)) {
x[-1L] = sub(prefix, '', x[-1L])
spaces = min(attr(regexpr("^ *", x[-1L]), "match.length"))
if (spaces > 0) x[-1L] = substring(x[-1L], spaces + 1)
}
x
}

Expand Down

0 comments on commit 082204f

Please sign in to comment.