Skip to content

Commit f9529fe

Browse files
author
smeyer
committed
fix para breaks in Rd2HTML(): handle indented \Sexpr, skip inactive #ifdef
git-svn-id: https://svn.r-project.org/R/trunk@88476 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent dcb4a98 commit f9529fe

File tree

5 files changed

+18
-51
lines changed

5 files changed

+18
-51
lines changed

src/library/tools/R/Rd2HTML.R

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# File src/library/tools/R/Rd2HTML.R
22
#
3-
# Copyright (C) 1995-2024 The R Core Team
3+
# Copyright (C) 1995-2025 The R Core Team
44
# Part of the R package, https://www.R-project.org
55
#
66
# This program is free software; you can redistribute it and/or modify
@@ -452,16 +452,19 @@ Rd2HTML <-
452452
}
453453

454454
skipNewline <- FALSE
455+
linestart <- TRUE
455456
of0 <- function(...)
456457
of1(paste0(...))
457458
of1 <- function(text) {
459+
force(text) # use skipNewline
458460
if (skipNewline) {
459461
skipNewline <<- FALSE
460462
if (text == "\n") return()
461463
}
462464
if (concordance)
463465
conc$addToConcordance(text)
464466
writeLinesUTF8(text, con, outputEncoding, sep = "")
467+
linestart <<- endsWith(text, "\n")
465468
}
466469

467470
pendingClose <- pendingOpen <- character() # Used for infix methods
@@ -513,13 +516,14 @@ Rd2HTML <-
513516
"\\verb"="&#8288;</code>")
514517

515518
addParaBreaks <- function(x) {
516-
if (isBlankLineRd(x) && isTRUE(inPara)) {
519+
if (isTRUE(inPara) && #isBlankLineRd(x)
520+
linestart && grepl("^[[:blank:]]*\n", x)) {
517521
inPara <<- FALSE
518522
return("</p>\n")
519523
}
520-
## TODO: can we get 'start col' if no srcref ?
524+
## remove indentation (for cleaner/smaller output)
521525
if (utils:::getSrcByte(x) == 1L) x <- psub("^\\s+", "", x)
522-
if (isFALSE(inPara) && !all(grepl("^[[:blank:]\n]*$", x, perl = TRUE))) {
526+
if (isFALSE(inPara) && !isBlankRd(x)) {
523527
x <- paste0("<p>", x)
524528
inPara <<- TRUE
525529
}
@@ -753,7 +757,8 @@ Rd2HTML <-
753757
VERB = if (Rhtml && blocktag == "\\dontrun") of1(block)
754758
else of1(vhtmlify(block, inEqn)),
755759
RCODE = if (Rhtml) of1(block) else of1(vhtmlify(block)),
756-
TEXT = of1(if(doParas && !inAsIs) addParaBreaks(htmlify(block)) else vhtmlify(block)),
760+
TEXT = of1(if (doParas && !inAsIs && !skipNewline) addParaBreaks(htmlify(block))
761+
else vhtmlify(block)),
757762
USERMACRO =,
758763
"\\newcommand" =,
759764
"\\renewcommand" = {},
@@ -807,7 +812,7 @@ Rd2HTML <-
807812
of0(closing)
808813
inPara <<- savePara
809814
},
810-
"\\Sexpr"= of0(as.character.Rd(block, deparse=TRUE)),
815+
"\\Sexpr"= of1(paste(as.character.Rd(block, deparse=TRUE), collapse="")),
811816
"\\cr" =,
812817
"\\dots" =,
813818
"\\ldots" =,

src/library/tools/R/RdConv2.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RdTags <- function(Rd) {
2525
isBlankRd <- function(x)
2626
length(grep("^[[:blank:]]*\n?$", x, perl = TRUE)) == length(x) # newline optional
2727

28+
## not suitable for \Sexpr-generated Rd where the srcref refers to the \Sexpr
2829
isBlankLineRd <- function(x) {
2930
utils:::getSrcByte(x) == 1L &&
3031
length(grep("^[[:blank:]]*\n", x, perl = TRUE)) == length(x) # newline required

src/library/tools/R/RdHelpers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function(x)
192192
paste(sprintf("\\if{html}{\u2060\\out{<span id=\"reference+%s\">}}%s\\if{html}{\\out{</span>}}",
193193
string2id(unlist(y$key, use.names = FALSE)),
194194
toRd(y)),
195-
collapse = "\\if{html}{\\out{</p>}}\n\n\\if{html}{\\out{<p>}}")
195+
collapse = "\n\n")
196196
}
197197

198198
Rd_expr_bibcite_keys_cited <- local({

tests/Pkgs/exSexpr/man/a.Rd

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/testit.html.save

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ foo(<var>x</var>, <var>y</var>, ...)
4949
<p>Included
5050

5151
conditional content.
52-
</p>
53-
<p>End(<code style="white-space: pre;">&#8288;#ifdef&#8288;</code>).
52+
End(<code style="white-space: pre;">&#8288;#ifdef&#8288;</code>).
5453
</p>
5554
<p>Escaped backslash <code>\x</code>.
5655
</p>
@@ -105,10 +104,10 @@ output
105104
</p>
106105
<p>Georgi Boshnakov's example of generated paragraphs:
107106
a
108-
109-
b
110-
111-
c
107+
</p>
108+
<p>b
109+
</p>
110+
<p>c
112111
</p>
113112

114113

0 commit comments

Comments
 (0)