-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
extra_dependencies order in bookdown::gitbook #1101
Comments
Thanks for the report @linogaliana ! I agree it would be more intuitive to have the extra dependencies sets after gitbook's one in Lines 28 to 31 in 2b7830f
because it is not easy to know what will be the effect of Gitbook deps on the extra deps, but the otherway around is usually known. However, doing so could maybe break some existing book 🤔 @yihui some thoughts on this ?
You can provide the css in you special format. You have a css file in your package, you set it as html_document <- function(extra_dependencies = list(),
css = NULL, ...) {
extra_dependencies <- c(
pkg_resource('rmarkdown/templates/utilitr/skeleton/style.css'),
extra_dependencies
)
css <- c("utilitr.css", css)
bookdown::gitbook(extra_dependencies = extra_dependencies,
css = css, ...)
} did that not work ? I believe it should.
The scripts are moved to bottom not copied, so they are not duplicated. But it indeed mean they will apply after your custom dependencies. What exactly do you want to override or remove in the template ? Are you willing to keep gitbook feature ? you can also create your HTML template from scratch if you don't want gitbook feature. I am trying to better understand the use case and the need to see if there are some more flexibility in customisation that we could provide. For example, you can already deactivate gitbook table css if you want to use bootstrap one. Thanks for this by all means - it is very nice to know better the experience for a custom template. If it is not smooth enough, we can look into how to improve it. |
@cderv If swapping The JS files need to be moved to the end of the HTML document (unless we use something like an onload event of the document). If you needs to execute JS code after the gitbook scripts, one hack is to name the dependencies to start with P.S. I didn't read all the links mentioned in the above issue, so I don't fully understand what @linogaliana was trying to achieve. |
Thanks a lot to both of you for your answers. Regarding my use case, I think I will move to Regarding the issue, I think this would be more consistent to swap the order of dependencies but you know better the breaking changes this could bring. Regarding the JS files moved to the end, I think the naming convention proposed by @yihui is fine (this was the hack I had in mind). |
Yes I think switching could worth it and I don't think this should be harmful.
Yes
This is a project I have in mind too. If you finish it and you agree to contribute, it would be a nice addition. |
@cderv : we have just finished implementing the print button in the All the codes are available in the
Tell me if I can be of any help in the development of a more general solution. |
I opened a new issue to track this : #1117 |
Another idea would be to replace
with
This won't break the old behaviour. And it gives users the choice wheter to import the dependencies before and/or after the gitbook dependencies. |
This would introduce a new argument and I don't like that. I don't think this is necessary. I don't see why gitbook deps needs to be after |
@ThierryO @linogaliana can you test #1249 on your projects and see if you encounter any obvious weird behavior ? remotes::install_github("rstudio/bookdown#1249")
# or
pak::pak("rstudio/bookdown#1249")
# or any other function of your choice.
```
Thank you! |
I get an error Here is the relevant part of the traceback
|
I am puzzled about the version of bookdown installed and used. This error means that an incorrect version of bookdown is used. last CRAN version of bookdown is now using jquerylib and the PR also. So, if I may, something is wrong with how you are testing. See the
Can you try reinstalling from the PR and restart your session before retesting ? You need to restart after an installation usually. |
I reinstalled the new version. Now it works. The stylesheets from my custom extra_dependencies are listed between the gitbook dependencies and those from packages I use in the code (e.g. DT, crosstalk, ...)
|
Great ! If you see no obvious problem with how gitbook() is working, then it should be fine. I leave the PR open a bit, waiting for @linogaliana feedback so that we confirm than switching the order is ok. @linogaliana do you have time to give a try too ? |
I guess it should be good. I just merged the PR, and @linogaliana can test with |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
Context
I am trying to make a custom output format that adds a few features to the default
gitbook
output (repository here). The examples provided here all come from Github Actions build from this repositoryAmong the things I do, I add some
extra_dependencies
using some custom CSS and JS files (I have very limited knowledge in these two languages. I hope I will not state the obvious). This is there. However, when looking at the source code of the generated HTML (an example deployed with Netlify here ), I see that the order isthis means that some elements in our stylesheets might be overriden by elements defined in some stylesheets included in the
bookdown
package. I made an example there where I put some elements to define toc appearance in a CSS that is called inextra_dependencies
(code there). Customized elements, e.g. text color in the TOC, are ignored (when looking at the output in Firefox).The fix I found to force rendering is to put some elements in a
style.css
stylesheet called in the_output.yml
. I used this fix to generate the aforementioned webpage where I modify the appareance of the TOC.In my opinion, using the
_output.yml
file is not ideal when developping a format within a package. This makes it complicated, for instance, to modify the behavior of thegitbook
table of content within the package (one cannot assume that the user of the package always add a CSS in the_output.yml
YAML).Why it matters ? (in my opinion, I am open to discussion)
I think the order of the dependencies matter because, when using a custom output format, one would expect the classes or properties defined in a few custom CSS to override some default
bookdown/gitbook
classes. Some attributes could still be set as!important
but I am not sure this would always work.A potential solution ?
I think a partial solution would be to change the order of
extra_dependencies
inbookdown::gitbook
(here) like this is done inbookdown::bs4_book
(here):Regarding scripts in
extra_dependencies
However, I think this does not solve everything regarding JS. Some scripts are present at two locations in the generated HTML. When matching the following pattern, scripts are copied at the bottom of the HTML (source here):
The scripts that I would define in
extra_dependencies
will not be duplicated (unless adopting a naming convention, which might be fine). This means you cannot override some functions if you want to change, let's say, the toolbar at the top.Extra
Before posting the issue, I have followed the recommendations ;
formatted your issue so it is easier for us to read?
included a minimal, self-contained, and reproducible example?
The text was updated successfully, but these errors were encountered: