Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paragraph breaks are lost in subsections #991

Closed
gustavdelius opened this issue Apr 3, 2019 · 10 comments

Comments

@gustavdelius
Copy link
Contributor

commented Apr 3, 2019

The following roxygen block illustrates the issue. This leads to a two-paragraph subsection in the Rd file, but pkgdown removes the paragraph break when converting this to html, where both are put on the same line as "First paragraph Second paragraph".

#' Testing subsections
#' 
#' @section A section:
#' \subsection{A subsection}{
#'   First paragraph
#'   
#'   Second paragraph
#' }
#' @name testing
@jayhesselberth

This comment was marked as resolved.

Copy link
Collaborator

commented Apr 4, 2019

Possibly related to #819.

@gustavdelius

This comment has been minimized.

Copy link
Contributor Author

commented Apr 5, 2019

It is indeed related to #819. In fact, any paragraph break within braces is removed by pkgdown. For example

#' Hello
#'
#' testing
#'
#' \strong{One paragraph
#'
#' another paragraph}

Gives two bold paragraphs in the .Rd file but only one bold line in the .html file produced by pkgdown.

@kevinushey

This comment was marked as resolved.

Copy link

commented Apr 9, 2019

Perhaps related, but line breaks are also lost within pre-formatted code chunks, e.g.

#' \preformatted{
#' line 1
#'
#' line 2
#'
#' line 3
#' }

Instead, each newline is indented:

Screen Shot 2019-04-09 at 4 35 52 PM

@hadley

This comment has been minimized.

Copy link
Member

commented May 17, 2019

Would someone mind creating some minimal reprexes using rd2html()?

@hadley hadley added this to the pkgdown 1.4 milestone May 17, 2019

@jayhesselberth

This comment was marked as outdated.

Copy link
Collaborator

commented May 18, 2019

Here are some reprexes. rd2html messes with newlines, so the lower level view may be helpful. Not sure why the last example generates a warning.

library(pkgdown)
library(magrittr)

# rd2html strips newlines, use low-level funcs too
rd_text <- pkgdown:::rd_text
as_html <- pkgdown:::as_html

# example 1 --------------------------------------

x <- "
Hello

testing

\\strong{para 1

para 2}"

rd2html(x)
#> [1] "Hello"           ""                "testing"         ""               
#> [5] "<strong>para 1"  ""                "para 2</strong>"
rd_text(x) %>% as_html()
#> [1] "\nHello\n\ntesting\n\n<strong>para 1\n\npara 2</strong>\n"

# example 2 --------------------------------------

x <- "\\preformatted{
line 1

line 2

line 3
}"

rd2html(x)
#> [1] "<pre>"  "line 1" ""       "line 2" ""       "line 3" "</pre>"
rd_text(x) %>% as_html()
#> [1] "<pre>\nline 1\n\nline 2\n\nline 3\n</pre>\n"

# example 3 --------------------------------------

x <- "\\section{A section}{
\\subsection{A subsection}{
  First para
  
  Second para
}
}"

rd2html(x)
#> Warning in tools::parse_Rd(con, fragment = fragment, encoding = "UTF-8"):
#> <connection>:1: unexpected section header '\section'
#> [1] "A section"             "<h3>A subsection</h3>" ""                     
#> [4] "First para"            ""                      "Second para"
rd_text(x) %>% as_html()
#> Warning in tools::parse_Rd(con, fragment = fragment, encoding = "UTF-8"):
#> <connection>:1: unexpected section header '\section'
#> [1] "A section\n<h3>A subsection</h3>\n\n  First para\n  \n  Second para\n\n\n"

Created on 2019-05-18 by the reprex package (v0.3.0)

@gustavdelius

This comment was marked as resolved.

Copy link
Contributor Author

commented Jun 12, 2019

You can also see this in the documentation of pkgdown itself. Take a look at how this is rendered here

@jayhesselberth

This comment has been minimized.

Copy link
Collaborator

commented Jul 3, 2019

Rendering of verbatim blocks was fixed in #1076, but this doesn't fix subsection rendering.

@jayhesselberth

This comment has been minimized.

Copy link
Collaborator

commented Jul 3, 2019

tag_subsection blocks need to be handled specially in flatten_para.

The current HTML output looks like:

<h3>A subsection</h3>
 
First paragraph

Second paragraph

but needs to look like:

<h3>A subsection</h3>
<p>
First paragraph
</p>

<p>
Second paragraph
</p>
@hadley

This comment has been minimized.

Copy link
Member

commented Aug 27, 2019

Minimal reprex:

x <- "\\subsection{A subsection}{
  First para
  
  Second para
}"

writeLines(pkgdown:::rd2html(x))
#> <h3>A subsection</h3>
#> 
#> First para
#> 
#> Second para

Created on 2019-08-27 by the reprex package (v0.3.0)

@hadley

This comment has been minimized.

Copy link
Member

commented Aug 27, 2019

Ooops, this was actually an easy one: as_html.tag_subsection() needs to call flatten_para(), not flatten_text()

@hadley hadley closed this in ccb2410 Aug 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.