| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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.
|
Correct behaviour verified against real-world test cases. CI failures seem to reflect unrelated stochastic tests rather than new errors caused by the fix? |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Fixes #2809.
\doi{10.2307/2413326}. renders as doi: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/\href fragment. pkgdown's as_html.tag_Sexpr() evaluates that \Sexpr and re-parses the result as an Rd fragment with rd_text():
tools::parse_Rd(..., fragment = TRUE) appends a trailing newline TEXT node 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 \n renders as whitespace in HTML. R's own Rd2HTML doesn'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 rd branch of as_html.tag_Sexpr():
This removes the node added by parse_Rd() without touching leading whitespace or valid \Sexpr content.
Tests
NEWS