Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: bookdown
Type: Package
Title: Authoring Books and Technical Documents with R Markdown
Version: 0.20.5
Version: 0.20.6
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("JJ", "Allaire", role = "ctb"),
Expand Down Expand Up @@ -61,7 +61,7 @@ License: GPL-3
Imports:
htmltools (>= 0.3.6),
knitr (>= 1.22),
rmarkdown (>= 2.3),
rmarkdown (>= 2.3.5),
xfun (>= 0.13),
tinytex (>= 0.12)
Suggests:
Expand All @@ -80,3 +80,4 @@ SystemRequirements: Pandoc (>= 1.17.2)
LazyData: TRUE
RoxygenNote: 7.1.1
Encoding: UTF-8
Remotes: rstudio/rmarkdown
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGES IN bookdown VERSION 0.21

## NEW FEATURES

- Add the `number_sections` argument to `markdown_document2()` and its family. This allows to have now figure references numbered by chapters in these formats, like `word_document2()` or `odt_document2()` for example (thanks, @atusy, #756).

## BUG FIXES

- Correctly encode the document title when creating the twitter sharing link from a bookdown chapter (thanks, @maelle, #934).
Expand Down
9 changes: 5 additions & 4 deletions R/word.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#' @rdname html_document2
#' @export
markdown_document2 = function(
fig_caption = TRUE, md_extensions = NULL, pandoc_args = NULL, ...,
base_format = rmarkdown::md_document
number_sections = TRUE, fig_caption = TRUE, md_extensions = NULL,
pandoc_args = NULL, ..., base_format = rmarkdown::md_document
) {
from = rmarkdown::from_rmarkdown(fig_caption, md_extensions)

config = get_base_format(base_format, list(
fig_caption = fig_caption, md_extensions = md_extensions, pandoc_args = pandoc_args, ...
number_sections = number_sections, fig_caption = fig_caption,
md_extensions = md_extensions, pandoc_args = pandoc_args, ...
))
pre = config$pre_processor
config$pre_processor = function(metadata, input_file, ...) {
# Pandoc does not support numbered sections for Word, so figures/tables have
# to be numbered globally from 1 to n
process_markdown(input_file, from, pandoc_args, TRUE)
process_markdown(input_file, from, pandoc_args, !number_sections)
if (is.function(pre)) pre(metadata, input_file, ...)
}
post = config$post_processor
Expand Down
1 change: 1 addition & 0 deletions man/html_document2.Rd

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

27 changes: 27 additions & 0 deletions tests/rmd/number-sections.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: "A Book"
author: "Frida Gomam"
output:
bookdown::markdown_document2:
number_sections: true
---

# Section 1

Some content

## subsection 1

Hello.

See chapter 2 now at \@ref(section-2)

# Section 2

## subsection 2 {#sub2}

```{r iris-plot, fig.cap = "A plot"}
plot(iris)
```

See figure \@ref(fig:iris-plot)
6 changes: 6 additions & 0 deletions tests/test-rmd.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,10 @@ if (Sys.getenv('NOT_CRAN') == 'true') local({
!any(grepl('id="fn3"', readLines('rmd/subsection-footnotes-1.html')))) {
stop('Failed to move the footnotes back to subsection 1 in parse_footnotes.Rmd')
}

# number sections now works in markdown_document2
if (!any(readLines("rmd/number-sections.md") == "1.1 subsection 1") ||
!any(grepl("<a href=.*>2.1</a>", readLines("rmd/number-sections.md")))) {
stop("Something wrong in number_sections.Rmd")
}
})