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

Remove unwanted linebreaks #2247

Merged
merged 11 commits into from
May 12, 2023
Merged

Remove unwanted linebreaks #2247

merged 11 commits into from
May 12, 2023

Conversation

salim-b
Copy link
Collaborator

@salim-b salim-b commented Dec 4, 2022

Normalizes whitespace chars within content extracted from DESCRIPTION file fields.

Successor to #1543.

R/rd-html.R Outdated
@@ -49,7 +49,7 @@ flatten_para <- function(x, ...) {
split(groups) %>%
purrr::map_lgl(any)

blocks[needs_p] <- paste0("<p>", str_trim(blocks[needs_p]), "</p>")
blocks[needs_p] <- paste0("<p>", str_squish(blocks[needs_p]), "</p>")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a very broad change with a high potential for risk — what happens if the paragraph contains an Rd tag where whitespace is important?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite a while ago I was concerned with this change, thus your question leaves me a bit unsure right now. In principle, the squishing is only done to elements that are neither a) block-level tags nor b) consist of only newlines:

pkgdown/R/rd-html.R

Lines 42 to 50 in 9fc86b1

# There are three types of blocks:
# 1. Combined text and inline tags
# 2. Paragraph breaks (text containing only "\n")
# 3. Block-level tags
#
# Need to wrap 1 in <p>
needs_p <- (!(is_nl | is_block)) %>%
split(groups) %>%
purrr::map_lgl(any)

Are there inline Rd tags where whitespace semantically matters? If so, could you provide a quick example?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unfortunately the burden of proof is on you to proof that there aren't any places where this would cause a problem. IMO it doesn't seem worth the analysis (and convincing me) given that the benefit is small and not user facing (since HTML's whitespace rules already make this problem invisible).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'm not familiar enough with the subtleties of the R documentation syntax and a quick scan of the official documentation didn't lead to an answer. So I've reverted to str_trim() in 1b793c2 (with a heavy heart, of course 😩).

@hadley hadley merged commit 39083f3 into r-lib:main May 12, 2023
13 checks passed
@hadley
Copy link
Member

hadley commented May 12, 2023

Thanks for bearing with it!

@salim-b salim-b deleted the rm-linebreaks branch May 12, 2023 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants