Skip to content

Struggling with {{ links #1259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lionel- opened this issue Oct 14, 2021 · 6 comments · Fixed by #1260
Closed

Struggling with {{ links #1259

lionel- opened this issue Oct 14, 2021 · 6 comments · Fixed by #1260
Labels
bug an unexpected problem or unintended behavior rd ✍️ wip work in progress

Comments

@lionel-
Copy link
Member

lionel- commented Oct 14, 2021

I'd like to hyperlink mentions of the {{ operator in the rlang doc because it is not easily searchable.

Here is a counter example with !! that works well:

gen <- function(body) {
  header <- "
#' Foo
#' @md
#' @name foo
#' @description
#'"
  text <- paste0(c(header, body, "NULL"), collapse = "\n")
  roxygen2::roc_proc_text(roxygen2::rd_roclet(), text)
}

gen("#' [`!!`][op-inject]")
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#> \code{\link[=op-inject]{!!}}
#> }

I would like to generate a similar link for {{, properly escaped:

#> \code{\link[=op-inject]{\{\{}}

Ideally [`{{`][foo] would work but here is what we get:

gen("#' [`{{`][op-embrace]")
#> Warning: [<text>:5] @description mismatched braces or quotes
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#>
#> }

Escaping { does not work (same result with \\\\{\\\\}):

gen("#' [`\\{\\{`][op-embrace]")
#> Warning: [<text>:5] @description mismatched braces or quotes
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#>
#> }

And unfortunately, trying to insert Rd manually does not work either

gen("#' \\code{\\link[=foo]{\\{\\{}}}}")
#> Warning: [<text>:5] @description mismatched braces or quotes
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#>
#> }

gen("#' \\code{\\link[=foo]{\\\\{\\\\{}}}}")
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#> \code{\link[=foo]{\\{\\{}}}}
#> }

Fixing [`{{`][foo] so that it works as expected would be great. But I'd appreciate pointers to a workaround as well.

@gaborcsardi
Copy link
Member

IDK if there is a way to write it with markdown, but this seems to work:

#' This is a link \code{\link[=foo]{\{\{}}

@gaborcsardi
Copy link
Member

You can define a function for it as well:

braces <- function() "\\code{\\link[=foo]{\\{\\{}}"

#' Foo
#' @md
#' @name foo
#' @description
#' This is a link `r braces()`.

@lionel-
Copy link
Member Author

lionel- commented Oct 14, 2021

Thanks, it seems the Rd works properly with the dev version but not the CRAN one.

@gaborcsardi
Copy link
Member

gaborcsardi commented Oct 14, 2021

Thanks, it seems the Rd works properly with the dev version but not the CRAN one.

IDK, but there seems to be no difference between CRAN and dev roxygen2 at this point, and the one with the braces() function definitely works with CRAN roxygen2 for me.

@lionel-
Copy link
Member Author

lionel- commented Oct 14, 2021

Both the Rd and the md reprexes are fixed with the dev version actually. But not with CRAN roxygen. Very weird.

@lionel-
Copy link
Member Author

lionel- commented Oct 14, 2021

Sorry that's my bad, I forgot to reset this changelist:

modified   R/markdown.R
@@ -193,7 +193,7 @@ mdxml_node_to_rd <- function(xml, state) {
     unknown = mdxml_children_to_rd(xml, state),
 
     paragraph = paste0("\n\n", mdxml_children_to_rd(xml, state)),
-    text = escape_comment(xml_text(xml)),
+    text = escape_verb(xml_text(xml)),
     emph = paste0("\\emph{", mdxml_children_to_rd(xml, state), "}"),
     strong = paste0("\\strong{", mdxml_children_to_rd(xml, state), "}"),
     softbreak = mdxml_break(state),

This explains the differences I was observing.

@hadley hadley added bug an unexpected problem or unintended behavior wip work in progress rd ✍️ labels Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior rd ✍️ wip work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants