Skip to content

Commit

Permalink
Increment subsection heading level when nested
Browse files Browse the repository at this point in the history
Fixes #1377
  • Loading branch information
hadley committed Aug 20, 2020
1 parent a6ea4fa commit 6f908a6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# pkgdown (development version)

* Nested `\subsection{}`s now generate appropriate heading levels
(h3, h4, h5 etc) (#1377).

* HTML is automatically stripped from the page title (#1318).

* pkgdown now uses the new downlit package for all syntax highlighting and
Expand Down
8 changes: 5 additions & 3 deletions R/rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ as_html.COMMENT <- function(x, ...) {
as_html.USERMACRO <- function(x, ...) ""

#' @export
as_html.tag_subsection <- function(x, ...) {
as_html.tag_subsection <- function(x, ..., subsection_level = 3L) {

h <- paste0("h", subsection_level)
paste0(
"<h3>", flatten_text(x[[1]], ...), "</h3>\n",
flatten_para(x[[2]], ...)
"<", h, ">", flatten_text(x[[1]], ...), "</", h, ">\n",
flatten_para(x[[2]], ..., subsection_level = subsection_level + 1L)
)
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-rd-html.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ test_that("subsection generates h3", {
p2
}"), c("<h3>A</h3>", "<p>p1</p>", "<p>p2</p>"))
})
test_that("nested subsection generates h4", {
expect_equal(
rd2html("\\subsection{H3}{\\subsection{H4}{}}"),
c("<h3>H3</h3>", "<h4>H4</h4>")
)
})

test_that("if generates html", {
expect_equal(rd2html("\\if{html}{\\bold{a}}"), "<b>a</b>")
Expand Down

0 comments on commit 6f908a6

Please sign in to comment.