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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ rmarkdown 2.7

- Eliminated the unnecessary padding in code blocks in the `html_document` output with Bootstrap 4 themes (thanks, @atusy, #2019).

- `github_document()` will produce a working TOC even if some headers start with number (#2039)

rmarkdown 2.6
================================================================================

Expand Down
4 changes: 4 additions & 0 deletions R/github_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ github_document <- function(toc = FALSE,
"--atx-headers", pandoc_args
)

if (toc && !isTRUE(grepl("gfm_auto_identifiers", md_extensions))) {
md_extensions <- c(md_extensions, "+gfm_auto_identifiers")
}

format <- md_document(
variant = variant, toc = toc, toc_depth = toc_depth,
number_sections = number_sections, fig_width = fig_width,
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/_snaps/github_document/github-atx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# title 1

## title 2

### title 3

#### title 4

##### title 5
11 changes: 11 additions & 0 deletions tests/testthat/_snaps/github_document/github-toc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

- [10 Section](#10-section)
- [Header](#header)

# 10 Section

Sentence.

# Header

Sentence
17 changes: 17 additions & 0 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
local_rmd_file <- function(..., .env = parent.frame()) {
path <- withr::local_tempfile(envir = .env, fileext = ".Rmd")
xfun::write_utf8(c(...), path)
path
}

skip_if_not_pandoc <- function(ver) {
if (!pandoc_available(ver)) {
skip(sprintf("Version of Pandoc is lower than %s.", ver))
}
}

skip_if_pandoc <- function(ver) {
if (pandoc_available(ver)) {
skip(sprintf("Version of Pandoc is greater than %s.", ver))
}
}
23 changes: 23 additions & 0 deletions tests/testthat/test-github_document.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

test_that("toc has correct identifier", {
local_edition(3)
skip_on_cran() # avoid pandoc issue on CRAN
skip_if_not_pandoc("2.10.1") # changes in gfm writer break this test for earlier versions
tmp_file <- local_rmd_file(
c("# 10 Section","","Sentence.","", "# Header","","Sentence ")
)
res <- render(tmp_file, github_document(toc = TRUE, html_preview = FALSE))
expect_snapshot_file(res, "github-toc.md", binary = FALSE)
})


test_that("github_document produces atx-header", {
local_edition(3)
skip_on_cran() # avoid pandoc issue on CRAN
h <- paste0(Reduce(paste0, rep("#", 5), accumulate = TRUE), " title ", 1:5, "\n\n")
tmp_file <- local_rmd_file(h)
res <- render(tmp_file, github_document(html_preview = FALSE))
expect_snapshot_file(res, "github-atx.md", binary = FALSE)
})


8 changes: 3 additions & 5 deletions tests/testthat/test-lua-filters.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
.generate_md_and_convert <- function(content, output_format) {
input_file <- tempfile(fileext = ".Rmd")
output_file <- tempfile()
on.exit(unlink(c(input_file, output_file)), add = TRUE)
xfun::write_utf8(c("---\ntitle: Test\n---\n", content), input_file)
input_file <- local_rmd_file(c("---\ntitle: Test\n---\n", content))
output_file <- withr::local_tempfile()
res <- rmarkdown::render(input_file, output_format = output_format, output_file = output_file, quiet = TRUE)
xfun::read_utf8(res)
}

# Lua filters exists only since pandoc 2.0
skip_if_not(rmarkdown::pandoc_available("2.0"))
skip_if_not_pandoc("2.0")

test_that("pagebreak Lua filters works", {
rmd <- "# HEADER 1\n\\newpage\n# HEADER 2\n\\pagebreak\n# HEADER 3"
Expand Down