jgm / pandoc

Universal markup converter
https://pandoc.org
Other
34.44k stars 3.37k forks source link

Adding media files to ePub referenced only from stylesheet #1941

Open nkalvi opened 9 years ago

nkalvi commented 9 years ago

In ePub writer, would you consider adding an option to add media files that are referenced only the style sheet, but not in the source documents?

https://groups.google.com/forum/#!topic/pandoc-discuss/BRqy-SEjBiQ

jgm commented 9 years ago

I think this ought to be the default, actually, not something you have to set an option for.

Note: (undocument feature) I think you can actually specify any media file to be included in the epub using --epub-embed-font. None of the code processing that is actually font-specific. (I haven't tried it, though.)

nkalvi commented 9 years ago

Aha - adding via 'embed-font' worked very well - thank you!

jgm commented 9 years ago

Maybe this should remain open, since ideally the epub writer would scan the CSS for linked files and include them automatically...

+++ nkalvi [Feb 14 15 16:24 ]:

Closed #1941.


Reply to this email directly or view it on GitHub: https://github.com/jgm/pandoc/issues/1941#event-235913023

nkalvi commented 9 years ago

I agree.

mpickering commented 9 years ago

@jgm How are you envisaging supporting this? Do we currently depend on a library which can parse CSS or should we roll our own?

jgm commented 9 years ago

@jgm How are you envisaging supporting this? Do we currently depend on a library which can parse CSS or should we roll our own?

@mpickering, I hadn't thought about it much. SelfContained currently has something that does limited looking through CSS files for external references; maybe that could be adapted? We don't depend on a CSS parsing library.

ghost commented 8 years ago

Another option is to make either --epub-embed-resource or --epub-embed-image.

The former could allow including any type of file (video, image, font, stylesheet).

The latter would be an alias for --epub-embed-font.

Meanwhile, for anyone looking for a quick fix to automate this:

#!/bin/bash

FILENAME=filename.epub
CSS=style.css
IMAGES_DIR=images

for url in $(grep image $CSS | grep url | sed 's/.*url( *\(.*\) *).*/\1/g'); do
  EMBED="$EMBED --epub-embed-font=$IMAGES_DIR/$url"
done

pandoc \
  --smart \
  --epub-cover-image=cover/cover.png \
  --epub-metadata=metadata.xml \
  --epub-stylesheet=$CSS \
  --epub-embed-font=fonts/EmbeddedFont.ttf \
  $EMBED \
  -t epub -o $FILENAME output/*.md
codelabor commented 3 years ago

I tried '--epub-embed-font' like this:

--epub-embed-font ../images/icon/facebook-icon.png

And I found image file under 'Images' directory not 'Fonts' like this:

\Images\facebook-icon.png

But in content.opf, item href is like this:

    <item id="facebook-icon_png" href="fonts/facebook-icon.png" media-type="image/png"/>

Please make another options. :cry:

DazEdword commented 2 years ago

hi @jgm

I'm using pandoc 2.18 to convert from html + css -> epub and it'd be great to have this feature, since I'm having the same issue as described in the first message (url("my_media.png") in css will be ignored).

As a workaround I have tried to add the media as a font (--epub-embed-font my_image.png), but then I need to manually edit the css anyway).

Any chance we could add an --epub-embed-image option? Many thanks!

jgm commented 2 years ago

A possible workaround: add a dummy metadata field (e.g. extra_images) with the extra images. That should be enough to get them included.

alerque commented 2 years ago

In a tweet presumably inspired by this issue, here is the exact syntax for the workaround:

https://twitter.com/pandoc_tips/status/1533719290289041408