Code Monkey home page Code Monkey logo

Comments (12)

jjallaire avatar jjallaire commented on July 19, 2024

@yihui Is there a straightforward way for us to add this capability to Radix?

from distill.

yihui avatar yihui commented on July 19, 2024

Those xxx2 formats in bookdown are extensible: https://bookdown.org/yihui/bookdown/a-single-document.html You may try a different base_format:

output:
  bookdown::html_document2:
    base_format: ANOTHER_HTML_FORMAT

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

Is there a way we could pull the code out of html_document2? (so that these dependencies and format specification conventions aren't required?)

from distill.

yihui avatar yihui commented on July 19, 2024

The relevant had been factored out to bookdown:::resolve_refs_html: https://github.com/rstudio/bookdown/blob/dda5f5a220058271a43ba8b81c6e6859ae3b9815/R/html.R#L136

Instead of letting other package authors use this function in their output formats (in the post-processors), I think it may be easier for users to specify a base_format in bookdown::html_document2.

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

It's just not super-intuitive to explain to users that in order to add this feature they should not use the format you've documented extensively elsewhere but instead "switch to bookdown" and specify a base format.

Would it be enough to just export the resolve_refs_html() function? Alternatively, I wonder if radix_article could just do the base_format composition itself under the hood?

from distill.

yihui avatar yihui commented on July 19, 2024

Yes, I can export the function. Then you will have to call it in your post-processor.

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

Okay, that would be great!

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

@yihui A reminder to export the resolve_refs_html() function from bookdown.

from distill.

yihui avatar yihui commented on July 19, 2024

Done.

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

I am trying to use this and am not getting the results I expect. Specifically, when I run the radix generated HTML through the function it fails to find the figure labels. I've attempted to simplify this to a minimal reproducible case as follows:

html <- '
<div class="figure">
<img src="plot.png" alt="Cars analysis" width="672" />
<p class="caption">
Cars analysis
</p>
</div>

<p>See Figure @ref(fig:plot1).</p>
'

cat(bookdown:::resolve_refs_html(html, global = TRUE))
## Warning: The label(s) fig:plot1 not found

## 
## <div class="figure">
## <img src="plot.png" alt="Cars analysis" width="672" />
## <p class="caption">
## Cars analysis
## </p>
## </div>
## 
## <p>See Figure <a href="#fig:plot1"><strong>??</strong></a>.</p>

This appears to be correctly handled with html_document2 (i.e. the span with id is inserted within the figure div) but the same HTML appears to not work here.

I am speculating that there might be some additional side effects of rendering that resolve_refs_html() is relying upon? (e.g. a lookup table of chunk labels).

from distill.

yihui avatar yihui commented on July 19, 2024

After this line: https://github.com/rstudio/radix/blob/27b482a21b6cba1c21752abdcd6b55ff5e083218/R/radix_article.R#L69

Try to add:

knitr_options$opts_knit$bookdown.internal.label <- TRUE

I guess that should work.

from distill.

jjallaire avatar jjallaire commented on July 19, 2024

Yes, that does indeed work!

This has now been implemented here: rstudio/radix@1179466

Docs are here: https://rstudio.github.io/radix/figures.html#cross-references

from distill.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.