jimhester / knitrBootstrap

A framework to create bootstrap styled HTML reports from knitr Rmarkdown.
Other
274 stars 61 forks source link

Add support for "self_contained" document option #172

Open khughitt opened 9 years ago

khughitt commented 9 years ago

Hi Jim,

Do you think it would be much work to add support for the self_contained option that is available for rmarkdown html_documents?

http://rmarkdown.rstudio.com/html_document_format.html#document-dependencies

This would be useful for having images saved separately.

jimhester commented 9 years ago

I would like to however there are bugs in pandoc that prevent it from working properly with the Bootswatch themes. In particular retrieving the fonts if I recall correctly.

I attempted to try and get this fixed with https://github.com/jgm/pandoc/issues/1477, which was resolved. However my example I sent to him must not have reproduced the exact problem properly, because the issue still occurs after that change.

khughitt commented 9 years ago

Sounds good. If I have the chance, I will try and look into the pandoc issue as well, but I don't think it's likely to happen in the near future. Perhaps we can just keep this open as a reminder for now and see how things are going after a few new versions of pandoc?

lcolladotor commented 9 years ago

I believe that this works now. Or at least it doesn't show an error like before. I just reinstalled haskell, cabal-install, pandoc and pandoc-citeproc.

I saved the example html from https://github.com/jgm/pandoc/issues/1477 in test-pandoc-bug.html then ran:

$ pandoc <test-pandoc-bug.html --standalone --self-contained
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Style-Type" content="text/css" />
  <meta name="generator" content="pandoc" />
  <title></title>
  <style type="text/css">code{white-space: pre;}</style>
</head>
<body>
<html>
<head>
<pre><code>&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;http://bootswatch.com/amelia/bootstrap.css&quot;&gt;</code></pre>
</head>
</html>
</body>
</html>

I saved the output in test-pandoc-bug-output.html.

Reproducibility info

$ pandoc --version
pandoc 1.13.2.1
Compiled with texmath 0.8.1, highlighting-kate 0.5.14.
Syntax highlighting is supported for the following languages:
    abc, actionscript, ada, agda, apache, asn1, asp, awk, bash, bibtex, boo, c,
    changelog, clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css,
    curry, d, diff, djangotemplate, dockerfile, dot, doxygen, doxygenlua, dtd,
    eiffel, email, erlang, fasm, fortran, fsharp, gcc, glsl, gnuassembler, go,
    haskell, haxe, html, idris, ini, isocpp, java, javadoc, javascript, json,
    jsp, julia, latex, lex, lilypond, literatecurry, literatehaskell, lua, m4,
    makefile, mandoc, markdown, mathematica, matlab, maxima, mediawiki,
    metafont, mips, modelines, modula2, modula3, monobasic, nasm, noweb,
    objectivec, objectivecpp, ocaml, octave, opencl, pascal, perl, php, pike,
    postscript, prolog, pure, python, r, relaxng, relaxngcompact, rest, rhtml,
    roff, ruby, rust, scala, scheme, sci, sed, sgml, sql, sqlmysql,
    sqlpostgresql, tcl, tcsh, texinfo, verilog, vhdl, xml, xorg, xslt, xul,
    yacc, yaml, zsh
Default user data directory: /Users/lcollado/.pandoc
Copyright (C) 2006-2014 John MacFarlane
Web:  http://johnmacfarlane.net/pandoc
This is free software; see the source for copying conditions.
There is no warranty, not even for merchantability or fitness
for a particular purpose.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.3

$ pandoc-citeproc --version
pandoc-citeproc 0.6.0.1
jimhester commented 9 years ago

Yeah the reproducible example I originally gave works, however the example didn't reproduce the problem correctly, as I still get errors trying to use self_contained = FALSE with knitrBootstrap. Do you still get an error if you change R/knit_bootstrap.R#L90 to TRUE? I believe you will.

humburg commented 8 years ago

I'm wondering whether this is still an issue. In my fork I removed the hard coded self_contained=FALSE in R/knit_bootstrap.R#L91 and that seems to work fine if I then call render with output_options=list(self_contained=TRUE) (using pandoc 1.16.0.2).

I've only tested this with fairly simple bootstrap_document. It would be great if someone else could confirm this with a document that previously failed.

Edit: That should be self_contained not stand_alone

jimhester commented 8 years ago

Still broken, with https://github.com/jimhester/knitrBootstrap/tree/standalone I get the following error

render("vignettes/cars.Rmd")
output file: cars.knit.md

/usr/local/bin/pandoc +RTS -K512m -RTS cars.utf8.md --to html --from markdown-hard_line_breaks+superscript+tex_math_dollars+raw_html+markdown_in_html_blocks-implicit_figures --output cars.html -H /var/folders/dt/r5s12t392tb5sk181j3gs4zw0000gn/T//Rtmp2MsiIp/knitr_bootstrap_full.html --self-contained
pandoc: Could not fetch //fonts.googleapis.com/css?family=Lobster|Cabin:400,700
InvalidUrlException "//fonts.googleapis.com/css?family=Lobster%7CCabin:400,700" "Invalid URL"
Error: pandoc document conversion failed with error 67
pandoc --version
pandoc 1.16.0.2

Trying to process a file with only the following in it produces the same error and seems to be a good minimal reproducible example.

echo '<link rel="alternate stylesheet" type="text/css" href="https://netdna.bootstrapcdn.com/bootswatch/3.0.0/amelia/bootstrap.min.css" title="Amelia" media="screen"></link>' > test.md
pandoc test.md --to html --from  markdown --self-contained --output out.html
# pandoc: Could not fetch //fonts.googleapis.com/css?family=Lobster|Cabin:400,700
# InvalidUrlException "//fonts.googleapis.com/css?family=Lobster%7CCabin:400,700" "Invalid URL"

I would encourage you to open a pandoc issue with the preceding block if you are interested in getting this fixed.

humburg commented 8 years ago

Thanks @jimhester. While that example indeed breaks with pandoc 1.16.0.2 it doesn't seem to be an issue with the vignettes using the _rmarkdowntemplate branch. I successfully generated all the examples as self contained web pages: https://rawgit.com/humburg/knitrBootstrap/stand_alone/vignettes/cars.html

humburg commented 8 years ago

Reading #68 again I realise that this presumably only works because of the workaround (using a local dependency). I've reported the issue (jgm/pandoc#2737) using your reproducible example.

humburg commented 8 years ago

Investigating this in some more detail it seems that rmarkdown doesn't support remote dependencies (unless I'm misunderstanding this: html_dependencies.R#L139-L140). So sticking with the local dependencies may be the way forward (regardless of what happens with the pandoc related issue).