diff --git a/R/markdown.R b/R/markdown.R
index 9b63b406..1fe34ef0 100644
--- a/R/markdown.R
+++ b/R/markdown.R
@@ -267,6 +267,7 @@ mdxml_code_block <- function(xml, state) {
info <- xml_attr(xml, "info")[1]
if (is.na(info) || nchar(info[1]) == 0) info <- NA_character_
paste0(
+ "\n\n",
if (!is.na(info)) paste0("\\if{html}{\\out{
}}"),
"\\preformatted{",
escape_verb(xml_text(xml)),
diff --git a/R/object-defaults.R b/R/object-defaults.R
index d66a5b6a..1559af78 100644
--- a/R/object-defaults.R
+++ b/R/object-defaults.R
@@ -44,7 +44,7 @@ object_defaults.package <- function(x, block) {
description <- package_url_parse(description)
logo_path <- file.path(x$value$path, "man", "figures", "logo.png")
if (file.exists(logo_path)) {
- fig <- "\\if{html}{\\figure{logo.png}{options: align='right' alt='logo' width='120'}}"
+ fig <- "\\if{html}{\\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}"
description <- paste0(fig, "\n\n", description)
}
diff --git a/R/object-r6.R b/R/object-r6.R
index 38667440..83be191e 100644
--- a/R/object-r6.R
+++ b/R/object-r6.R
@@ -68,6 +68,7 @@ extract_r6_methods <- function(x) {
methods <- data.frame(
stringsAsFactors = FALSE,
type = if (length(method_loc)) "method" else character(),
+ class = if (length(method_loc)) x$classname %||% NA_character_ else character(),
name = unname(method_nms),
file = unname(method_fnm),
line = unname(method_loc),
@@ -91,6 +92,7 @@ add_default_method_data <- function(obj, methods) {
rec <- data.frame(
stringsAsFactors = FALSE,
type = defaults[[mname]]$type %||% "method",
+ class = defaults[[mname]]$class %||% obj$classname %||% "unknown",
name = defaults[[mname]]$name %||% mname,
file = defaults[[mname]]$file %||% NA_character_,
line = defaults[[mname]]$line %||% NA_integer_,
@@ -108,6 +110,7 @@ extract_r6_fields <- function(x) {
stringsAsFactors = FALSE,
type = rep("field", length(field_nms)),
name = as.character(field_nms),
+ class = rep(x$classname %||% NA_character_, length(field_nms)),
file = rep(NA, length(field_nms)),
line = rep(NA, length(field_nms)),
formals = I(replicate(length(field_nms), NULL))
@@ -120,6 +123,7 @@ extract_r6_bindings <- function(x) {
stringsAsFactors = FALSE,
type = if (length(bind_nms)) "active" else character(),
name = as.character(bind_nms),
+ class = rep(x$classname %||% NA_character_, length(bind_nms)),
file = rep(NA, length(bind_nms)),
line = rep(NA, length(bind_nms)),
formals = I(replicate(length(bind_nms), NULL))
diff --git a/R/rd-r6.R b/R/rd-r6.R
index a953872e..a5d9593d 100644
--- a/R/rd-r6.R
+++ b/R/rd-r6.R
@@ -238,7 +238,8 @@ r6_method_list <- function(block, methods) {
c("\\subsection{Public methods}{",
"\\itemize{",
sprintf(
- "\\item \\href{#method-%s}{\\code{%s$%s()}}",
+ "\\item \\href{#method-%s-%s}{\\code{%s$%s()}}",
+ methods$class,
nms,
block$object$alias,
nms
@@ -261,34 +262,34 @@ r6_inherited_method_list <- function(block, r6data) {
super_meth <- super_meth[rev(seq_len(nrow(super_meth))), ]
details <- paste0(
- "
Inherited methods
"
)
- c("\\if{html}{",
- paste0("\\out{", details, "}"),
- "\\itemize{",
+ c("\\if{html}{\\out{", details,
+ "",
sprintf(
paste0(
- "\\item \\out{}",
- "\\href{../../%s/html/%s.html#method-%s}{\\code{%s::%s$%s()}}",
- "\\out{}"
+ "- ",
+ "",
+ "
%s::%s$%s()
",
+ " "
),
super_meth$package,
super_meth$classname,
super_meth$name,
super_meth$package,
super_meth$classname,
+ super_meth$classname,
super_meth$name,
super_meth$package,
super_meth$classname,
super_meth$name
),
- "}",
- "\\out{
}",
- "}"
+ "",
+ "",
+ "}}"
)
}
@@ -296,8 +297,8 @@ r6_method_begin <- function(block, method) {
nm <- r6_show_name(method$name)
c(
"\\if{html}{\\out{
}}",
- paste0("\\if{html}{\\out{
}}"),
- paste0("\\if{latex}{\\out{\\hypertarget{method-", nm, "}{}}}"),
+ paste0("\\if{html}{\\out{
}}"),
+ paste0("\\if{latex}{\\out{\\hypertarget{method-", method$class, "-", nm, "}{}}}"),
paste0("\\subsection{Method \\code{", nm, "()}}{")
)
}
diff --git a/man/load.Rd b/man/load.Rd
index dc9834da..c4c5247a 100644
--- a/man/load.Rd
+++ b/man/load.Rd
@@ -37,6 +37,8 @@ outside of roxygen2.
You can change the default strategy for your function with roxygen2 \code{load}
option. Override the default off \code{pkgload} to use the \code{source} or
-\code{installed} strategies:\preformatted{Roxygen: list(load = "source")
+\code{installed} strategies:
+
+\preformatted{Roxygen: list(load = "source")
}
}
diff --git a/man/load_options.Rd b/man/load_options.Rd
index 5aaa95ce..4eaf5b40 100644
--- a/man/load_options.Rd
+++ b/man/load_options.Rd
@@ -38,10 +38,14 @@ Options in \code{man/roxygen/meta.R} override those present in \code{DESCRIPTION
\section{How to set}{
-Either set in \code{DESCRIPTION}:\preformatted{Roxygen: list(markdown = TRUE, load = "installed")
+Either set in \code{DESCRIPTION}:
+
+\preformatted{Roxygen: list(markdown = TRUE, load = "installed")
}
-Or if longer, you can put in \verb{/man/roxygen/meta.R}:\preformatted{list(
+Or if longer, you can put in \verb{/man/roxygen/meta.R}:
+
+\preformatted{list(
markdown = TRUE,
load = "installed"
)
diff --git a/man/markdown_pass1.Rd b/man/markdown_pass1.Rd
index 44d95164..917ed8e6 100644
--- a/man/markdown_pass1.Rd
+++ b/man/markdown_pass1.Rd
@@ -29,19 +29,29 @@ function, and this is \code{TRUE}: TRUE.
To insert the name of the current package: roxygen2.
The \code{iris} data set has 5 columns:
-\code{Sepal.Length}, \code{Sepal.Width}, \code{Petal.Length}, \code{Petal.Width}, \code{Species}.\if{html}{\out{
}}\preformatted{# Code block demo
+\code{Sepal.Length}, \code{Sepal.Width}, \code{Petal.Length}, \code{Petal.Width}, \code{Species}.
+
+\if{html}{\out{
}}\preformatted{# Code block demo
x + 1
-}\if{html}{\out{
}}\preformatted{## [1] 101
+}\if{html}{\out{
}}
+
+\preformatted{## [1] 101
}
-Chunk options:\if{html}{\out{
}}\preformatted{names(mtcars)
+Chunk options:
+
+\if{html}{\out{
}}\preformatted{names(mtcars)
nrow(mtcars)
-}\if{html}{\out{
}}\preformatted{## [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear"
+}\if{html}{\out{
}}
+
+\preformatted{## [1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear"
## [11] "carb"
## [1] 32
}
-Plots:\if{html}{\out{
}}\preformatted{plot(1:10)
+Plots:
+
+\if{html}{\out{
}}\preformatted{plot(1:10)
}\if{html}{\out{
}}
\figure{test-figure-1.png}
diff --git a/man/roxygen2-package.Rd b/man/roxygen2-package.Rd
index 606bcddc..85b50d5c 100644
--- a/man/roxygen2-package.Rd
+++ b/man/roxygen2-package.Rd
@@ -6,7 +6,7 @@
\alias{roxygen2-package}
\title{roxygen2: In-Line Documentation for R}
\description{
-\if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}}
+\if{html}{\figure{logo.png}{options: style='float: right' alt='logo' width='120'}}
Generate your Rd documentation, 'NAMESPACE' file, and collation field using specially formatted comments. Writing documentation in-line with code makes it easier to keep your documentation up-to-date as your requirements change. 'Roxygen2' is inspired by the 'Doxygen' system for C++.
}
diff --git a/tests/testthat/_snaps/markdown.md b/tests/testthat/_snaps/markdown.md
index d906f493..52c6f7e5 100644
--- a/tests/testthat/_snaps/markdown.md
+++ b/tests/testthat/_snaps/markdown.md
@@ -1,3 +1,21 @@
+# code blocks work
+
+ Before
+
+ \preformatted{x \%in\% 1:10
+ }
+
+ After
+
+# code block with language creates HTML tag
+
+ Before
+
+ \if{html}{\out{
}}\preformatted{x \%in\% 1:10
+ }\if{html}{\out{
}}
+
+ After
+
# can convert table to Rd
Code
diff --git a/tests/testthat/roxygen-block-3-A.Rd b/tests/testthat/roxygen-block-3-A.Rd
index ecfb0971..1d520084 100644
--- a/tests/testthat/roxygen-block-3-A.Rd
+++ b/tests/testthat/roxygen-block-3-A.Rd
@@ -49,15 +49,15 @@ Class A details
\section{Methods}{
\subsection{Public methods}{
\itemize{
-\item \href{#method-meth1}{\code{A$meth1()}}
-\item \href{#method-meth2}{\code{A$meth2()}}
-\item \href{#method-meth3}{\code{A$meth3()}}
-\item \href{#method-clone}{\code{A$clone()}}
+\item \href{#method-A-meth1}{\code{A$meth1()}}
+\item \href{#method-A-meth2}{\code{A$meth2()}}
+\item \href{#method-A-meth3}{\code{A$meth3()}}
+\item \href{#method-A-clone}{\code{A$clone()}}
}
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth1}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-A-meth1}{}}}
\subsection{Method \code{meth1()}}{
A method 1.
\subsection{Usage}{
@@ -81,8 +81,8 @@ A method 1.
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth2}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-A-meth2}{}}}
\subsection{Method \code{meth2()}}{
Method 2 description.
\subsection{Usage}{
@@ -112,8 +112,8 @@ Method 2 details.
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth3}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-A-meth3}{}}}
\subsection{Method \code{meth3()}}{
\subsection{Usage}{
\if{html}{\out{
}}\preformatted{A$meth3(duplicate, missing)}\if{html}{\out{
}}
@@ -137,8 +137,8 @@ twice.
}
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-clone}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-A-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
diff --git a/tests/testthat/roxygen-block-3-B.Rd b/tests/testthat/roxygen-block-3-B.Rd
index 8c8844c9..79bd7c79 100644
--- a/tests/testthat/roxygen-block-3-B.Rd
+++ b/tests/testthat/roxygen-block-3-B.Rd
@@ -36,22 +36,22 @@ Class B details.
\section{Methods}{
\subsection{Public methods}{
\itemize{
-\item \href{#method-meth1}{\code{B$meth1()}}
-\item \href{#method-meth4}{\code{B$meth4()}}
-\item \href{#method-clone}{\code{B$clone()}}
-}
-}
-\if{html}{
-\out{
Inherited methods
}
-\itemize{
-\item \out{}\href{../../roxygen2/html/A.html#method-meth2}{\code{roxygen2::A$meth2()}}\out{}
-\item \out{}\href{../../roxygen2/html/A.html#method-meth3}{\code{roxygen2::A$meth3()}}\out{}
-}
-\out{}
-}
+\item \href{#method-B-meth1}{\code{B$meth1()}}
+\item \href{#method-B-meth4}{\code{B$meth4()}}
+\item \href{#method-B-clone}{\code{B$clone()}}
+}
+}
+\if{html}{\out{
+
Inherited methods
+
+
+}}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth1}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-B-meth1}{}}}
\subsection{Method \code{meth1()}}{
B method 1.
\subsection{Usage}{
@@ -67,8 +67,8 @@ B method 1.
}
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth4}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-B-meth4}{}}}
\subsection{Method \code{meth4()}}{
A method 4.
\subsection{Usage}{
@@ -77,8 +77,8 @@ A method 4.
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-clone}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-B-clone}{}}}
\subsection{Method \code{clone()}}{
The objects of this class are cloneable with this method.
\subsection{Usage}{
diff --git a/tests/testthat/roxygen-block-3-C.Rd b/tests/testthat/roxygen-block-3-C.Rd
index b0eeeb69..ba92fc87 100644
--- a/tests/testthat/roxygen-block-3-C.Rd
+++ b/tests/testthat/roxygen-block-3-C.Rd
@@ -46,23 +46,23 @@ Classs C details.
\section{Methods}{
\subsection{Public methods}{
\itemize{
-\item \href{#method-meth2}{\code{C$meth2()}}
-\item \href{#method-meth5}{\code{C$meth5()}}
-\item \href{#method-undocumented_method}{\code{C$undocumented_method()}}
-}
-}
-\if{html}{
-\out{
Inherited methods
}
-\itemize{
-\item \out{}\href{../../roxygen2/html/A.html#method-meth3}{\code{roxygen2::A$meth3()}}\out{}
-\item \out{}\href{../../roxygen2/html/B.html#method-meth1}{\code{roxygen2::B$meth1()}}\out{}
-\item \out{}\href{../../roxygen2/html/B.html#method-meth4}{\code{roxygen2::B$meth4()}}\out{}
-}
-\out{}
-}
+\item \href{#method-C-meth2}{\code{C$meth2()}}
+\item \href{#method-C-meth5}{\code{C$meth5()}}
+\item \href{#method-C-undocumented_method}{\code{C$undocumented_method()}}
+}
+}
+\if{html}{\out{
+
Inherited methods
+
+
+}}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth2}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-C-meth2}{}}}
\subsection{Method \code{meth2()}}{
C method 2.
\subsection{Usage}{
@@ -80,8 +80,8 @@ C method 2.
}
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-meth5}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-C-meth5}{}}}
\subsection{Method \code{meth5()}}{
C method 5.
\subsection{Usage}{
@@ -90,8 +90,8 @@ C method 5.
}
\if{html}{\out{
}}
-\if{html}{\out{
}}
-\if{latex}{\out{\hypertarget{method-undocumented_method}{}}}
+\if{html}{\out{
}}
+\if{latex}{\out{\hypertarget{method-C-undocumented_method}{}}}
\subsection{Method \code{undocumented_method()}}{
\subsection{Usage}{
\if{html}{\out{
}}\preformatted{C$undocumented_method()}\if{html}{\out{
}}
diff --git a/tests/testthat/test-markdown.R b/tests/testthat/test-markdown.R
index bfd35302..6e1ac668 100644
--- a/tests/testthat/test-markdown.R
+++ b/tests/testthat/test-markdown.R
@@ -19,60 +19,46 @@ test_that("code blocks work", {
out1 <- roc_proc_text(rd_roclet(), "
#' Title
#'
- #' Description
- #'
- #' Details with a code block:
+ #' @description
+ #' Before
#' ```
- #' x <- 1:10 %>%
- #' multiply_by(10) %>%
- #' add(42)
+ #' x %in% 1:10
#' ```
- #' Normal text again.
+ #' After
#' @md
foo <- function() {}")[[1]]
+ expect_snapshot_output(cat(out1$get_value("description")))
+
+ # And check that extra empty paragraphs don't affect the output
out2 <- roc_proc_text(rd_roclet(), "
#' Title
#'
- #' Description
+ #' @description
+ #' Before
#'
- #' Details with a code block:\\preformatted{x <- 1:10 \\%>\\%
- #' multiply_by(10) \\%>\\%
- #' add(42)
- #' }
+ #' ```
+ #' x %in% 1:10
+ #' ```
#'
- #' Normal text again.
+ #' After
+ #' @md
foo <- function() {}")[[1]]
- expect_equivalent_rd(out1, out2)
+ expect_equal(out1$get_value("description"), out2$get_value("description"))
})
test_that("code block with language creates HTML tag", {
out1 <- roc_proc_text(rd_roclet(), "
#' Title
#'
- #' Description
- #'
- #' Details with a code block:
+ #' @description
+ #' Before
#' ```r
- #' x <- 1:10 %>%
- #' multiply_by(10) %>%
- #' add(42)
+ #' x %in% 1:10
#' ```
- #' Normal text again.
+ #' After
#' @md
foo <- function() {}")[[1]]
- out2 <- roc_proc_text(rd_roclet(), "
- #' Title
- #'
- #' Description
- #'
- #' Details with a code block:\\if{html}{\\out{
}}\\preformatted{x <- 1:10 \\%>\\%
- #' multiply_by(10) \\%>\\%
- #' add(42)
- #' }\\if{html}{\\out{
}}
- #'
- #' Normal text again.
- foo <- function() {}")[[1]]
- expect_equivalent_rd(out1, out2)
+ expect_snapshot_output(cat(out1$get_value("description")))
})
test_that("inline code escapes %", {