The reason why this fails: R tries to interpret this as valid R code:
expr <- parse(text = "ls *t??ne.pdb")
expr[[1]] # R thinks we are looking for the ls * t type in the ne.pdb topic
#> `?`(ls * t, `?`(ne.pdb))
as.character(expr[[1]][[2]]) # `ls * t` parses as a three-element character vector, which is then passed to href_topic()
#> [1] "*" "ls" "t"
Problem
href_topic()
assumes that the topic is length 1, but this is not always the case if you try to use parsed BASH code with wildcards.I ran into an interesting issue when trying to parse the following markdown list:
Downlit threw this error:
Reprex
The error is reproducible via
downlit::downlit_html_node()
, but I found that this is best explained starting atdownlit:::href_expr()
:Created on 2022-05-16 by the reprex package (v2.0.1)
The reason why this fails: R tries to interpret this as valid R code:
Created on 2022-05-16 by the reprex package (v2.0.1)
Solution
I think this can be fixed by checking that the topic is length 1 in
href_topic
and returningNA_character_
if it's greater than length 1:https://github.com/r-lib/downlit/blob/4011b2f470750dc51a8001eaa739dbcff257ffb1/R/link.R#L151-L157