Reputation:
am using pandoc to convert epub files to html but am having trouble with certain epub books who use /images folder for images and or other media.
Example:
pandoc -s --extract-media=bw_files bw.epub -o bw.html -M document-css=false
would create an bw_files folder with extracted images folder in it but goal is to move them and change location for them in outputted html document to / so the image files are properly referenced.
Upvotes: 1
Views: 951
Reputation: 22544
The images go into pandoc's "mediabag" during conversion. Their filenames
can be modified there, as can the links to the images. The Lua filter
below does just that; save the filter to a file, then pass that file to pandoc
via --lua-filter
.
local mediabag = require 'pandoc.mediabag'
-- Delete image files and re-insert under new name
for fp, mt, contents in mediabag.items() do
mediabag.delete(fp)
mediabag.insert(fp:gsub('images/', ''), mt, contents)
end
-- adjust path to image file
function Image (img)
img.src = img.src:gsub('images/', '')
return img
end
This is a copy of an answer which I gave on the pandoc mailing list.
Upvotes: 2
Reputation: 7260
The following call may help you:
pandoc -s --extract-media=. bw.epub -o bw.html -c my-style.css
Please note that the subfolder bw_files
from your example will not be created. But the structure of the .epub file will be extracted. The result depends on the internal structure of the .epub file.
For further information please have a look at Wikipedia EPUB.
Upvotes: 2