Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

column.width issue when using img refs #336

Closed dcomtois closed 5 years ago

dcomtois commented 5 years ago

The column widths are affected by the length of the path to images, which should not happen... For instance, if a cell contains:

![](C:\\Users\\usr1234\\AppData\\Local\\Temp\\RtmpQhs2I7\\file3a745a6e4f4f.png)

The width will try to accomodate for all these characters.

Here's a .Rmd demo:

---
title: "Untitled"
output: html_document
---

```{r, results='asis'}
devtools::install_github("dcomtois/summarytools", ref="colwidth-issue")
library(summarytools)
dfSummary(tobacco, plain.ascii = FALSE, style = "grid", 
          graph.magnif = 0.82, valid.col = FALSE)


[Rendered results here](https://htmlpreview.github.io/?https://gist.githubusercontent.com/dcomtois/631889c4b553d77cc5277ec15b6b8de3/raw/5128e7213fe0a405caca35aff8660de6b8cecbf2/pander-colwidths.html)
daroczig commented 5 years ago

I think this is a limitation of pandoc and not a pander issue, so please check with the devs there with a minimal example of a markdown file including a grid table with an image (markup) in a cell. Once we know how to do that properly in markdown, pander will be able to kick in as well.

dcomtois commented 5 years ago

Just a little update, in case someone encounters the same situation: I asked the question on the pandoc discussion group, and it is indeed a limitation in pandoc. There is an easy workaround when the column containing the images is the last one:

+-------+---------------+
| color |      Img      |
+=======+===============+
| Blue  | ![](tiny-blue-square-with-a-ridiculously-long-file-name.png) |
+-------+---------------+

... but if it's not the last column, it doesn't work.

Otherwise, here are the suggestions I got from the Pandoc discussion board:

~Only the last solution seems appropriate, at least for the moment~ (Edit: as it turns out, it also requires the use of a pandoc filter, so there is no obvious solution AFAIK.)

And it doesn't seem like there's a lot of appetite for change at this point.

daroczig commented 5 years ago

Thanks, @dcomtois, these points are really useful :+1:

dcomtois commented 5 years ago

You're welcome! Unfortunately the workaround I was putting my faith in a non-solution since it also requires a pandoc filter. Maybe an advanced Web developer could see a solution (involving Javascript, most probably), but I had to do something far from ideal to make things work: copy the images in a subdirectory and save them using short names. That way I can put in the cells something like this:

![]img/ds001.png

...and it makes the widths perfectly fine. Only (quite annoying) problem is that it leaves garbage behind.

image