r-lib / downlit

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

Autolink fails when `?` topic contains hyphen #168

Closed davidchall closed 1 year ago

davidchall commented 1 year ago

To generate a link to a topic containing a hyphen, we must use help("topic") instead of ?topic.

withr::with_options(list(downlit.attached = "vctrs"), {
  print(downlit::autolink("help('faq-compatibility-types')"))
  print(downlit::autolink("?faq-compatibility-types"))
})
#> [1] "<a href='https://vctrs.r-lib.org/reference/faq-compatibility-types.html'>help('faq-compatibility-types')</a>"
#> [1] NA

Created on 2023-04-02 with reprex v2.0.2

dmurdoch commented 1 year ago

In base R, ?faq-compatibility-types would link to the help on the subtraction operator, which is probably not what was intended. You would need to put the alias in quotes or backticks. So what downlit does is probably reasonable.

davidchall commented 1 year ago

Ah, that's a fair point. Thanks, @dmurdoch!