|
1 | 1 | # File src/library/tools/R/Rd2HTML.R |
2 | 2 | # |
3 | | -# Copyright (C) 1995-2024 The R Core Team |
| 3 | +# Copyright (C) 1995-2025 The R Core Team |
4 | 4 | # Part of the R package, https://www.R-project.org |
5 | 5 | # |
6 | 6 | # This program is free software; you can redistribute it and/or modify |
@@ -452,16 +452,19 @@ Rd2HTML <- |
452 | 452 | } |
453 | 453 |
|
454 | 454 | skipNewline <- FALSE |
| 455 | + linestart <- TRUE |
455 | 456 | of0 <- function(...) |
456 | 457 | of1(paste0(...)) |
457 | 458 | of1 <- function(text) { |
| 459 | + force(text) # use skipNewline |
458 | 460 | if (skipNewline) { |
459 | 461 | skipNewline <<- FALSE |
460 | 462 | if (text == "\n") return() |
461 | 463 | } |
462 | 464 | if (concordance) |
463 | 465 | conc$addToConcordance(text) |
464 | 466 | writeLinesUTF8(text, con, outputEncoding, sep = "") |
| 467 | + linestart <<- endsWith(text, "\n") |
465 | 468 | } |
466 | 469 |
|
467 | 470 | pendingClose <- pendingOpen <- character() # Used for infix methods |
@@ -513,13 +516,14 @@ Rd2HTML <- |
513 | 516 | "\\verb"="⁠</code>") |
514 | 517 |
|
515 | 518 | addParaBreaks <- function(x) { |
516 | | - if (isBlankLineRd(x) && isTRUE(inPara)) { |
| 519 | + if (isTRUE(inPara) && #isBlankLineRd(x) |
| 520 | + linestart && grepl("^[[:blank:]]*\n", x)) { |
517 | 521 | inPara <<- FALSE |
518 | 522 | return("</p>\n") |
519 | 523 | } |
520 | | - ## TODO: can we get 'start col' if no srcref ? |
| 524 | + ## remove indentation (for cleaner/smaller output) |
521 | 525 | 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)) { |
523 | 527 | x <- paste0("<p>", x) |
524 | 528 | inPara <<- TRUE |
525 | 529 | } |
@@ -753,7 +757,8 @@ Rd2HTML <- |
753 | 757 | VERB = if (Rhtml && blocktag == "\\dontrun") of1(block) |
754 | 758 | else of1(vhtmlify(block, inEqn)), |
755 | 759 | 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)), |
757 | 762 | USERMACRO =, |
758 | 763 | "\\newcommand" =, |
759 | 764 | "\\renewcommand" = {}, |
@@ -807,7 +812,7 @@ Rd2HTML <- |
807 | 812 | of0(closing) |
808 | 813 | inPara <<- savePara |
809 | 814 | }, |
810 | | - "\\Sexpr"= of0(as.character.Rd(block, deparse=TRUE)), |
| 815 | + "\\Sexpr"= of1(paste(as.character.Rd(block, deparse=TRUE), collapse="")), |
811 | 816 | "\\cr" =, |
812 | 817 | "\\dots" =, |
813 | 818 | "\\ldots" =, |
|
0 commit comments