-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
Specify that htmltools::htmlPreserve()
should use the pandoc raw attribute
#1965
Conversation
…tribute rather than preservation tokens when pandoc >= v2.0. Note that this option will have the intended effect only for versions of htmltools >= 0.5.0.9003. This causes 1 test to fail b/c it's testing for htmlPreserve output that no longer conforms. The test will pass/fail depending on which version of htmltools is installed, so we may want to make it conditional.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
Addressed the failing test by skipping it if htmltools >= v0.5.0.9003 (since in that case there is nothing to test b/c we won't be using the traditional token-based htmlPreserve) |
@kevinushey We now take advantage of a new htmltools option to preserve html using pandoc raw attributes rather than tokens (this among other things includes more of the actual output in keep_md, will be faster for larger documents/widgets, and enables pandoc filters to see the actual content rather than just a preservation token). Here is the code in htmltools: https://github.com/rstudio/htmltools/blob/master/R/tags.R#L1063-L1080 Does this have any implications for the R Notebook in RStudio or does it have a parallel universe that it fully controls? |
First a question: is the aim to replace all occurrences of rmarkdown/R/shiny_prerendered.R Lines 623 to 632 in 4e1661d
Maybe we should use On the notebook side, I know we are using <!-- rnb-htmlwidget-begin <base64-encoded-meta> -->
```{=html}
<div id="htmlwidget-dd56a28903c66375acb6">
(...)
</div>
<script type=\"application/json\" data-for=\"htmlwidget-dd56a28903c66375acb6\">
(...)
</script>
```
<!-- rnb-htmlwidget-end --> I think this is why the test is failing because notebook annotations for htmlwidgets are expecting currently htmlwidget output using token-based htmlPreserve, to add some Depending on what we need for |
I think this will break some reverse dependencies such as flextable and gt.
reprex
|
@kevinushey Will understand that notebook case better than I do -- let's wait to hear from him on that. AFAIK it would be fine for the shiny prerendered code to also call htmltools::htmlPreserve (it's really just doing that get around pandoc's treatment of >= 4-space indented HTML, which |
Yes, those hacks are quite unfortunate! Happily there is a way out, in gt we now only do the hack if we know that flextable would need a similar conditional check here: https://github.com/davidgohel/flextable/pull/205/files#diff-d6c591de630faf206d4ebf004627d738a92c808a424f916ea3af4fd84407e9caR14 We certainly don't want to cause breakage but using |
@jjallaire Great to have a workaround! Thanks! I definitely agree Pandoc's raw attribute is the better solution in general. |
Interestingly, the original motivation for this was to make it easier for bookdown to cross reference tables expressed as raw html. While it's great that gt and flextable found an ingenious workaround, we definitely don't want to require every R function that emits a table to do the same. cc @davidgohel |
@jjallaire Yes. I also had the same motivation but gave up when I implemented the cross referencing feature in flextable. Thanks again. |
I'm trying to recall why
My only guess is that the intention here was to ensure that the R Notebook comment headers + footers could live within the Whereas the change now restores the old preserved chunk as-is: All that said ... it looks like this ultimately works regardless of how we try to arrange the HTML comment fences here. In addition, since these hooks just modify the generated Markdown (which is then later processed by Pandoc) it should be totally fine for the new-style Pandoc raw blocks to be left as-is. tl;dr: I think (but haven't confirmed) we might actually be able to get rid of the whole preserve-unpreserve dance in |
@kevinushey Thanks for taking a closer look. It sounds like while there may be some related changes to make in |
…en this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293
Merge branch 'master' of https://github.com/rstudio/rmarkdown * 'master' of https://github.com/rstudio/rmarkdown: (111 commits) get rid of names, otherwise the returned vector will have names like this: Only run testrmd if pandoc is available Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017) Add shiny to remotes (rstudio#2014) file.path.ci is too loose with file matching (rstudio#2012) improve error messages for the new theme argument behavior Add Bootstrap 4 support (rstudio#1706) amend rstudio#1965: do not force `options(htmltools.preserve.raw = TRUE)` when this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293 htmltools 0.5.1 is on CRAN now remove download stats use on.exit to remove file (rstudio#2001) use only the TinyTeX-1 version in CI (rstudio#1998) Cache should work on Windows with recent version of R (rstudio#1997) exclude renv folder from render_site() copied resources (rstudio#1996) Update CI to last Pandoc 2.11.3.1 (rstudio#1992) Revert "return div not nil for non-qualifying latex div" Add missing NEWS item for v2.6 release return div not nil for non-qualifying latex div Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989) Improvements to latex-div (rstudio#1984) ... # Conflicts: # NEWS.md # R/render.R # man/render.Rd
* master: (111 commits) get rid of names, otherwise the returned vector will have names like this: Only run testrmd if pandoc is available Warn that cropping is disabled if pdfcrop or ghostscript are not found. (rstudio#2017) Add shiny to remotes (rstudio#2014) file.path.ci is too loose with file matching (rstudio#2012) improve error messages for the new theme argument behavior Add Bootstrap 4 support (rstudio#1706) amend rstudio#1965: do not force `options(htmltools.preserve.raw = TRUE)` when this option has been set, otherwise it is impossible for other packages to turn this option off, e.g., yihui/xaringan#293 htmltools 0.5.1 is on CRAN now remove download stats use on.exit to remove file (rstudio#2001) use only the TinyTeX-1 version in CI (rstudio#1998) Cache should work on Windows with recent version of R (rstudio#1997) exclude renv folder from render_site() copied resources (rstudio#1996) Update CI to last Pandoc 2.11.3.1 (rstudio#1992) Revert "return div not nil for non-qualifying latex div" Add missing NEWS item for v2.6 release return div not nil for non-qualifying latex div Add `output_format_filter` function to `default_site_generator()`. (rstudio#1989) Improvements to latex-div (rstudio#1984) ...
Rather than using preservation tokens (only when pandoc >= v2.0, which is required for the raw attribute)
Note that this option will have the intended effect only for versions of htmltools >= 0.5.0.9003.
This causes 1 test to fail b/c it's testing for htmlPreserve output that no longer conforms. The test will pass/fail depending on which version of htmltools is installed, so we may want to make it conditional.
cc @jcheng5 @cpsievert