downlit icon indicating copy to clipboard operation
downlit copied to clipboard

R6 class of local package does not get highlighted (inline)

Open pat-s opened this issue 2 years ago • 2 comments

The following works

`<pkg>::<class>$new()`

The following do not

`<class>`
`<class>$new()`

I've played around a bit with downlit::highlight() and found that

downlit::highlight("<class>$new()")

does not include the href part because packages in

https://github.com/r-lib/downlit/blob/main/R/highlight.R#L58

is empty. I've added the following to a fork

  if (is.null(packages)) {
    packages <- loadedNamespaces()
  }

which makes the href part getting added to downlit::highlight("<class>$new()") when executed directly. However, I still do not get highlighting when building a pkgdown site 🤔 (new session, fresh start with modified {downlit}).

Is there something else I am overlooking which is responsible for highlighting of local packages in {pkgdown}?

pat-s avatar Jun 06 '22 21:06 pat-s

Can you please provide a reprex using a package that's on CRAN?

hadley avatar Jun 09 '22 22:06 hadley

Reprex using mlr3 from CRAN, which I suspect is one of the reasons Patrick encountered this behavior:

library(downlit)
library(mlr3)

# Object in question: mlr3::Task

downlit::highlight("mlr3::Task$new()")
#> [1] "<span><span class='nf'>mlr3</span><span class='nf'>::</span><span class='nv'><a href='https://mlr3.mlr-org.com/reference/Task.html'>Task</a></span><span class='o'>$</span><span class='nf'>new</span><span class='o'>(</span><span class='o'>)</span></span>"

downlit::highlight("mlr3::Task")
#> [1] "<span><span class='nf'>mlr3</span><span class='nf'>::</span><span class='nv'><a href='https://mlr3.mlr-org.com/reference/Task.html'>Task</a></span></span>"

downlit::highlight("Task$new()")
#> [1] "<span><span class='nv'>Task</span><span class='o'>$</span><span class='nf'>new</span><span class='o'>(</span><span class='o'>)</span></span>"

downlit::highlight("Task")
#> [1] "<span><span class='nv'>Task</span></span>"

Created on 2022-09-14 with reprex v2.0.2

jemus42 avatar Sep 14 '22 13:09 jemus42