Fix spurious whitespace after inline \Sexpr[results=rd] (e.g. \doi{})#2996
Open
ms609 wants to merge 1 commit into
Open
Fix spurious whitespace after inline \Sexpr[results=rd] (e.g. \doi{})#2996ms609 wants to merge 1 commit into
ms609 wants to merge 1 commit into
Conversation
tools::parse_Rd() appends a trailing newline TEXT node when parsing a
fragment. as_html.tag_Sexpr() re-parses the result of a results=rd
\Sexpr as a fragment, so that newline rendered as whitespace between the
macro output and any following text. For inline macros such as \doi{},
this produced 'doi:... .' with a space before trailing punctuation.
Strip the single trailing newline that fragment re-parsing adds.
Author
|
Correct behaviour verified against real-world test cases. CI failures seem to reflect unrelated stochastic tests rather than new errors caused by the fix? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2809.
\doi{10.2307/2413326}.renders asdoi:10.2307/2413326 ., with a space between the link and the trailing full stop.This PR was constructed with AI assistance; I have manually reviewed the modifications.
Root cause
\doi{}is a system Rd macro that expands (via\Sexpr[results=rd]) to an\ifelse/\hreffragment. pkgdown'sas_html.tag_Sexpr()evaluates that\Sexprand re-parses the result as an Rd fragment withrd_text():tools::parse_Rd(..., fragment = TRUE)appends a trailing newlineTEXTnode to every fragment. So the re-parsed doi fragment flattens to<a ...>doi:...</a>\n, and the following.ends up on the next line:The interior
\nrenders as whitespace in HTML. R's ownRd2HTMLdoesn't hit this because it expands the macro in place during a single parse rather than re-parsing the macro output as a separate fragment.Any inline
\Sexpr[results=rd]{}followed by punctuation is affected (not just DOIs).Fix
The fix strips the trailing newline that fragment re-parsing adds, in the
rdbranch ofas_html.tag_Sexpr():This removes the node added by
parse_Rd()without touching leading whitespace or valid\Sexprcontent.Tests
test-rd-html.Rcovering both\doi{...}.and a bare\Sexpr[results=rd]{...}..\Sexprnow correctly render flush ("11") instead of being split across two lines by the newline artefact.NEWS