coatless / quarto-webr

Community developed Quarto Extension to Embed webR for HTML Documents, RevealJS, Websites, Blogs, and Books.
https://quarto-webr.thecoatlessprofessor.com/
395 stars 19 forks source link

[Bug]: Disable automatic rendering of links in webR code cell output #115

Closed gvelasq closed 11 months ago

gvelasq commented 12 months ago

Bug description

Thank you for this excellent extension. @ivelasq and I are planning to use it for her Quarto blog. When running the following code in a webR code cell in a Quarto HTML document, the output is automatically rendered into a live hyperlink, which is unexpected behavior. The desired behavior is for the HTML code (not the live hyperlink) to be displayed as output, as it is in the 1) R console in RStudio, 2) in the webR REPL demo, 3) the webR website's interactive console, or in 4/5) .qmd/.Rmd files that are rendered/knit in RStudio.

# This function converts a markdown link into HTML
"[Posit](https://posit.co)" |> (\(.) {
  text <- sub("\\].*", "", sub(".*\\[", "", .))
  url <- sub("\\).*", "", sub(".*\\(", "", .))

  writeLines(noquote(paste0('<a href="', url, '" target = "_blank">', text, '</a>')))
})()

Steps to reproduce

  1. (Unexpected) To reproduce, copy/paste the code above into a webR code block in this draft blog post, and click 'Run Code'. The code for the blog post can be found here.

Rather than the output of the code cell being a line of HTML code created by writeLines(noquote(paste0(...))), the output is instead a clickable hyperlink to the Posit website. Ideally, there could be a option (at the code chunk level, not at the YAML header level) to disable/enable this behavior. We tried #| output: asis but that did not work.

Screenshot 2023-12-04 at 11 28 29 PM

Below for reference are examples that do display the expected behavior:

  1. (Expected) Copy/paste the code above into the webR REPL demo:

    Screenshot 2023-12-05 at 11 54 58 PM
  2. (Expected) Copy/paste the code above into the webR website's interactive console:

    Screenshot 2023-12-04 at 11 26 43 PM
  3. (Expected) Copy/paste the code above into a blank .qmd and render the document:

    Screenshot 2023-12-04 at 11 22 50 PM
  4. (Expected) Copy/paste the code above into a blank .Rmd and knit the document:

    Screenshot 2023-12-04 at 11 22 17 PM

Your environment

Quarto check output

Usage:   quarto 
  Version: 1.4.504
coatless commented 12 months ago

Thanks for the detailed issue!

We're using innerHTML instead of innerText to update the document for output to provide annotation to differentiate between STDOUT and STDERR (black/red text). Specifically, we're doing it at:

https://github.com/coatless/quarto-webr/blob/f81f1b51a3c620841602eb0bc429f8f45df3d84a/_extensions/webr/webr-context-interactive.html#L234-L237

This likely requires a modification in the mapping code to return output as an untouched HTML element.

https://github.com/coatless/quarto-webr/blob/f81f1b51a3c620841602eb0bc429f8f45df3d84a/_extensions/webr/webr-context-interactive.html#L187-L193


Aside

We do not have any of the built-in Quarto code cell options yet. That's why you're seeing the output: 'asis' not change anything.

coatless commented 11 months ago

@gvelasq thanks again for the detailed report. I've merged in a fix (#116) alongside a new test case.

https://quarto-webr.thecoatlessprofessor.com/tests/qwebr-test-escape-html-output-characters.html

Please update to the latest development version by typing into Terminal while in the Quarto's project working directory:

quarto add coatless/quarto-webr
ivelasq commented 11 months ago

Thank you so much, @coatless ! 🎉

gvelasq commented 11 months ago

@coatless we really appreciate your prompt reply and fix!

coatless commented 10 months ago

Just an FYI @gvelasq & @ivelasq, in #141 some features of results (not output) are now available.

>>> There would be no changes required if you update to the PR/future version. <<<

For those who stumble upon this issue ticket, if you wanted to allow for the original behavior of having the text become a hyperlink, then this is now possible by specifying inside the code cell: results: 'asis'