Skip to content
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

Use of inline HTML is not currently supported #1115

Closed
lionel- opened this issue Jun 15, 2020 · 4 comments · Fixed by #1116
Closed

Use of inline HTML is not currently supported #1115

lionel- opened this issue Jun 15, 2020 · 4 comments · Fixed by #1116
Labels
bug an unexpected problem or unintended behavior markdown ⬇️

Comments

@lionel-
Copy link
Member

lionel- commented Jun 15, 2020

The lifecycle badges produce correct output but with warnings:

roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
  #' Foo
  #' @name foo
  #' @md
  #' @description
  #' `r lifecycle::badge('stable')`
  NULL
")
#> Warning: [<text>:5] @description Use of inline HTML is not currently supported
#> Warning: [<text>:5] @description Use of inline HTML is not currently supported
#> Warning: [<text>:5] @description Use of inline HTML is not currently supported
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{Foo}
#> \description{
#> \ifelse{html}{\out{<a href='https://www.tidyverse.org/lifecycle/#stable'><img src='figures/lifecycle-stable.svg' alt='Stable lifecycle'></a>}}{\strong{Stable}}
#> }

Needed for r-lib/lifecycle#17.

@gaborcsardi
Copy link
Member

gaborcsardi commented Jun 15, 2020

Yeah, I guess the contents of \out{} should not be parsed as markdown. So that is a bug.

EDIT: actually, it is not parsed as markdown, but it seems that we'll need to do some more escaping after the inline substitutions.

Btw. why not use \figure{} for this? Or its markdown equivalent?

@gaborcsardi gaborcsardi added the bug an unexpected problem or unintended behavior label Jun 15, 2020
@lionel-
Copy link
Member Author

lionel- commented Jun 15, 2020

I'm not sure I remember well, but I think it had to do with having a clickable link. Does that make sense?

@gaborcsardi
Copy link
Member

This seems to work well:

badge <-'\\ifelse{html}{[![](stable.svg "Stable")](https://www.tidyverse.org)}{Stable}'

The \ifelse{} is only needed because R does not format the alt text nicely.

@gaborcsardi
Copy link
Member

More minimal reprex below. So it seems that we'll have to do another round of escaping to protect the fragile tags that were potentially inserted by inline code.

var <- "\\out{<span></span>}"
roxygen2::roc_proc_text(roxygen2::rd_roclet(), "
  #' @name foo
  #' @title `r .GlobalEnv$var`
  #' @md
  NULL
  ")
#> Warning: [<text>:3] @title Use of inline HTML is not currently supported

#> Warning: [<text>:3] @title Use of inline HTML is not currently supported
#> $foo.Rd
#> % Generated by roxygen2: do not edit by hand
#> % Please edit documentation in ./<text>
#> \name{foo}
#> \alias{foo}
#> \title{\out{<span></span>}}
#> \description{
#> \out{<span></span>}
#> }

Created on 2020-06-15 by the reprex package (v0.3.0)

gaborcsardi added a commit that referenced this issue Jun 15, 2020
Before this, we evaluated dynamic after the fragile tags
were removed (set aside temporarily). This is problematic,
because these tags were also removed from within inline
code and code blocks, and more importantly, you could
not reliably return fragile tags from the dynamic code.

After this patch the order is this:
1. Parse the tag as markdown, find the inline code
   and the code blocks, execute them, substitute
   back the result.
2. Set aside the fragile tags, temporarily.
3. Parse as markdown again, generate Rd.
4. Put back the fragile tags.

This is a breaking change in theory, however dynamic
code is relatively recent, and the affected documentation
is somewhat obscure, so we can probably get away with it.
The potentially affected cases are:
* People having dynamic code in fragile tags. E.g.

    #' blah \out{`r expression`} blah

  This will now evaluate the expression.
* People generating fragile tags dynamically. E.g. as in
  the original post of #1115
  We actually improve this use case with this patch.

Closes #1115.
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 markdown ⬇️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants