Comments (6)
I agree this would be very nice to have.
from knitrbootstrap.
I had a closer look at the code for this and ran some tests. I think I have a better understanding of the underlying issues now but I'm unsure how to best resolve them.
As I see it the problem is the way the output generated by knitrBootstrap is interpreted by pandoc. To get a figure with caption the corresponding markdown has to appear in a paragraph by itself (see pandoc documentation) but knitrBootstrap generates additional HTML in the same paragraph. As a result pandoc produces an inline figure instead.
Of course it is pretty straightforward to just add some additional line breaks around the ![]()
element to ensure the figure caption is generated. Unfortunately this doesn't play nice with the thumbnail code because pandoc ends up wrapping <a href="#" class="thumbnail">
in a p
element, which breaks whole thing. Adding the extra line breaks works fine when using bootstrap.thumbnail=FALSE
.
It would be nice to have both though. One option would be to just generate the HTML for the figure directly to bypass any pandoc related issues but that isn't very elegant. It will be harder to maintain if pandoc's behaviour (and expectations of what the output should be) changes in the future (not sure how likely that is). The other problem is that it will make the generated markdown file useless for conversion to other formats but I think that is already the case because of the way code blocks are handled so this may be acceptable.
@jimhester, I'd be happy to contribute a pull request that addresses this in some way, either along the lines discussed above or some better solution if one is suggested. It would be good if we could agree on what approach should be implemented beforehand though. Based on the discussion above my proposal would be to basically implement both solutions, using the (knitr generated) markdown with extra line breaks if no thumbnails are used and generate the HTML directly otherwise.
from knitrbootstrap.
@humburg I haven't looked at this as recently as you, but I think what you propose is correct.
Embedded html is part of the markdown "spec", so generating the html in there will technically be fine.
I think generating the HTML directly when bootstrap.thumbnail = TRUE
and relying on pandoc's caption generation when bootstrap.thumbnail = FALSE
is the way to go here.
bootstrap.thumbnail = TRUE
implies we are doing our own thing with the thumbnails so if the behavior ends up deviating from pandoc in the future that should be ok, (but we can always change it to match if needed).
You can take a look at knitr:::hook_plot_md()
, knitr:::hook_plot_md_base()
and knitr:::hook_plot_html()
if you need some examples of doing the full HTML generation.
@humburg I also granted you write permissions for this repo, feel free to continue to send pull requests if you'd like (and I can review them), but you can also commit directly to it as well. Thank you for your interest in this project!
from knitrbootstrap.
@jimhester Thanks, I've created a branch to work on this. I think this basically works as long as there is only one plot per chunk. For multiple plots it is following the logic used by knitr to not ad captions if the plots are held until the end of the chunk but to add them otherwise. Not sure whether that is the best behaviour but at least it is consistent.
I've created a Gist with a simple file for testing here: https://gist.github.com/humburg/f39efe7597d4004a92a3
from knitrbootstrap.
I merged the changes into #68. Captions should now be available for individual figures whether they use the thumbnails or not. When using thumbnails the popup view of the image will also have the caption. Chunks that produce multiple figures with fig.show="hold"
won't get any captions.
from knitrbootstrap.
Looks good! Thanks for working on this!
from knitrbootstrap.
Related Issues (20)
- Allow knitrBootstrap to be used as a vignette engine HOT 3
- Using bootstrap.thumnail HOT 1
- Scrolling of the menu / table of contents HOT 1
- Add support for "self_contained" document option HOT 9
- Title in YAML header HOT 18
- Rendering datatable() from DT package fails HOT 1
- General package documentation listed as primerTree HOT 1
- d3heatmap with knitrBootstrap doesn't work HOT 1
- Allow additional pandoc options HOT 1
- No produce figures in base64
- What are the code styling options? HOT 1
- Line breaks are gone in R code and output HOT 5
- Can knitrBootstrap make slide decks (ioslides/slidy)? HOT 5
- rpivotTable is not getting drawn with this HOT 3
- No title and table of content
- leaflet maps do not show up when using knitrBootstrap::bootstrap_document:
- custom css HOT 1
- Renders VERY narrow HOT 3
- maptools archived
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from knitrbootstrap.