r-lib / downlit

Syntax Highlighting and Automatic Linking
https://downlit.r-lib.org
Other
90 stars 22 forks source link

fill() links to wrong topic #135

Closed hadley closed 2 years ago

hadley commented 2 years ago
downlit::highlight("
  library(tidyverse)
  fill()"
)
#> [1] "\n  <span class='kr'><a href='https://rdrr.io/r/base/library.html'>library</a></span><span class='o'>(</span><span class='nv'><a href='https://tidyverse.tidyverse.org'>tidyverse</a></span><span class='o'>)</span>\n  <span class='nf'><a href='https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html'>fill</a></span><span class='o'>(</span><span class='o'>)</span>"

Created on 2022-04-27 by the reprex package (v2.0.1)

Should prefer function over floating topic

hadley commented 2 years ago

Minimal reprex:

options(downlit.attached = c("ggplot2", "tidyr"))
downlit::href_topic("fill")
#> [1] "https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html"

Created on 2022-06-18 by the reprex package (v2.0.1)

hadley commented 2 years ago

I think we'll need either href_function() or href_topic(only_function = TRUE). But then how do we establish whether a topic is for a function or not? Maybe can just check package namespace for presence of function?

hadley commented 2 years ago

Better reprex:

options(downlit.attached = c("ggplot2", "tidyr"))

downlit::highlight("fill()")
#> [1] "<span class='nf'><a href='https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html'>fill</a></span><span class='o'>(</span><span class='o'>)</span>"
downlit:::href_expr(quote(fill()))
#> [1] "https://ggplot2.tidyverse.org/reference/aes_colour_fill_alpha.html"

Created on 2022-06-22 by the reprex package (v2.0.1)