public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Adding images to pandoc.mediabag
@ 2019-01-08 12:25 Tom McLean
       [not found] ` <2466a754-96ab-4b5e-a887-5dba4d486867-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Tom McLean @ 2019-01-08 12:25 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 2581 bytes --]

Hello!

I have a problem the documentation doesn't seem to help with.

I am creating an epub from markdown, but I want to replace the titlepage 
with a pre-made image.

The approach I thought I would take was this:

1)  I can't quite work out how to get at the titlepage from a filter, since 
that's specific to the epub writer.  So instead I use a custom template for 
epub3 output and replace the default titlepage with the following: 


[...]
$if(titlepage)$
<section epub:type="titlepage">
<img src="../media/titlepage.png"/>
</section>
[...]


 2) Run pandoc with a key 'epub_title_page_image' in the metadata, pointing 
to the pre-made image. I thought that by using this lua filter, the image 
would be added to the mediabag.


function Meta (meta)
  local titlepage_path = 
pandoc.utils.stringify(meta["epub_title_page_image"])
  local mimetype, contents = pandoc.mediabag.fetch(titlepage_path, ".")
  pandoc.mediabag.insert("titlepage.png", mimetype, contents)
  return meta
end


This doesn't seem to work. Checking with asserts, the image exists and is 
found by pandoc.mediabag.fetch. Then it is successfully added to the 
mediabag.

But the output epub doesn't have 'titlepage.png' included in the media 
directory.

The only clue that I can find in the documentation is that 'the 
pandoc.mediabag <https://pandoc.org/lua-filters.html#module-pandoc.mediabag>
 module allows access to the “mediabag,” which stores binary content such 
as images that *may* be included in the final document.'

My best guess is that the epub writer checks to see if files in the 
mediabag are being used, and finding no apparent use here, discards 
titlepage.png. But I can't read Haskell, and I haven't seen such checks in 
my attempts to understand at the writer source.

Is it instead something to do with returning an unchanged value for meta in 
the filter?

If so, or if not, does anyone happen to know a good way to manage this?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2466a754-96ab-4b5e-a887-5dba4d486867%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 5647 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found] ` <2466a754-96ab-4b5e-a887-5dba4d486867-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-08 12:47   ` Tom McLean
       [not found]     ` <5b2d2f89-3c03-4f7d-b591-5eadd075671c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Tom McLean @ 2019-01-08 12:47 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 744 bytes --]

P.S. oddly enough, adding the command line option --extract-media=DIR does 
result in titlepage.png being written to the specified directory (but still 
not the epub file)

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5b2d2f89-3c03-4f7d-b591-5eadd075671c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1461 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]     ` <5b2d2f89-3c03-4f7d-b591-5eadd075671c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-08 20:20       ` John MacFarlane
       [not found]         ` <yh480k5zuyyk9a.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-01-08 20:20 UTC (permalink / raw)
  To: Tom McLean, pandoc-discuss


The mediabag is only consulted (or filled) when the
document contains an image.  So, instead of

---
epub-titlepage-image: myimage.png
---

in your metadata, you could try something like

---
epub-titlepage-image: '![Alt text](myimage.png)'
---

You could then modify the custom template to have this
whole thing inserted (it will be converted to an HTML
img tag) instead of hardcoding the image tag.


Tom McLean <thomasowenmclean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> P.S. oddly enough, adding the command line option --extract-media=DIR does 
> result in titlepage.png being written to the specified directory (but still 
> not the epub file)
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5b2d2f89-3c03-4f7d-b591-5eadd075671c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]         ` <yh480k5zuyyk9a.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-08 20:46           ` Tom McLean
       [not found]             ` <ccffdc0d-7db4-4f5b-9e35-83e2d1e632b9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Tom McLean @ 2019-01-08 20:46 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1078 bytes --]

Thanks for this! There's definite progress in that now the image goes in to 
the media dir without a filter being needed. However, it gets renamed in 
the process (to file0.png) and I'm a bit stuck on the question of how to 
refer to that embedded file in the image tag.

That is, the image tag looks like <img src="titlepage.png" alt="Alt text" 
/> when ideally it would, of course, be <img src="../media/file0.png" 
alt="Alt text"/>.

I'll keep experimenting but would be grateful for any further tips!


-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/ccffdc0d-7db4-4f5b-9e35-83e2d1e632b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1627 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]             ` <ccffdc0d-7db4-4f5b-9e35-83e2d1e632b9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-08 21:50               ` John MacFarlane
       [not found]                 ` <yh480kwonex1ih.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-01-08 21:50 UTC (permalink / raw)
  To: Tom McLean, pandoc-discuss

Tom McLean <thomasowenmclean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Thanks for this! There's definite progress in that now the image goes in to 
> the media dir without a filter being needed. However, it gets renamed in 
> the process (to file0.png) and I'm a bit stuck on the question of how to 
> refer to that embedded file in the image tag.

If you do as I suggested, it should all be automatic.
Don't include a raw HTML img tag. Instead, put the
variable where you want the img tag, and it will be
filled with the HTML for the image, with the name corrected.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]                 ` <yh480kwonex1ih.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-08 23:09                   ` Tom McLean
       [not found]                     ` <86608167-1d83-4d8e-a78b-3fe602e2b075-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Tom McLean @ 2019-01-08 23:09 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1507 bytes --]

I'm afraid that's not the case, unless I've somehow got things very wrong. 
Sorry to be such a bother.

Using a yaml metadata block to set $my-variable$ as ''![Alt 
text](titlepage.png)', the output for $my-variable$ within title_page.xhtml 
is '<img src="titlepage.png" alt="Alt text" />'. The image is bundled with 
the epub as file0.png. (Setting from the command line rather than using a 
metadata block, $my-variable$ remains exactly as set, which seems to be a 
whole other issue).

I have attached a MWE for reproducing this.

To reproduce: after unzipping, change to the directory. Run 'pandoc -t 
epub3 -f markdown -o test.epub --template=test_template.epub3 test.md'. 
Unzip the resulting epub file and examine 'EPUB/text/title_page.xhtml'.

Would you like me to write this up properly and file as a bug report, or am 
I somehow being an idiot in a way that will be painfully apparent to me 
about five minutes from now?





-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/86608167-1d83-4d8e-a78b-3fe602e2b075%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2161 bytes --]

[-- Attachment #2: pandoc_mwe.zip --]
[-- Type: application/zip, Size: 1439 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]                     ` <86608167-1d83-4d8e-a78b-3fe602e2b075-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-01-09  0:29                       ` John MacFarlane
       [not found]                         ` <yh480kmuoawu5j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-01-09  0:29 UTC (permalink / raw)
  To: Tom McLean, pandoc-discuss


Aha! I see why it didn't do what I thought it would.
I've just pushed a commit that fixes this, if you can
compile from source (verified on your mwe).

Tom McLean <thomasowenmclean-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I'm afraid that's not the case, unless I've somehow got things very wrong. 
> Sorry to be such a bother.
>
> Using a yaml metadata block to set $my-variable$ as ''![Alt 
> text](titlepage.png)', the output for $my-variable$ within title_page.xhtml 
> is '<img src="titlepage.png" alt="Alt text" />'. The image is bundled with 
> the epub as file0.png. (Setting from the command line rather than using a 
> metadata block, $my-variable$ remains exactly as set, which seems to be a 
> whole other issue).
>
> I have attached a MWE for reproducing this.
>
> To reproduce: after unzipping, change to the directory. Run 'pandoc -t 
> epub3 -f markdown -o test.epub --template=test_template.epub3 test.md'. 
> Unzip the resulting epub file and examine 'EPUB/text/title_page.xhtml'.
>
> Would you like me to write this up properly and file as a bug report, or am 
> I somehow being an idiot in a way that will be painfully apparent to me 
> about five minutes from now?


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Adding images to pandoc.mediabag
       [not found]                         ` <yh480kmuoawu5j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-01-09  0:42                           ` Tom McLean
  0 siblings, 0 replies; 8+ messages in thread
From: Tom McLean @ 2019-01-09  0:42 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 750 bytes --]

Grand! Thanks very much for your responsiveness and patience -- and now to 
look at the commit and continue my doomed project of trying to understand 
Haskell.
Thanks again,
Tom

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/32202a71-715c-4450-8b86-9002528be85d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 1180 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-01-09  0:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-08 12:25 Adding images to pandoc.mediabag Tom McLean
     [not found] ` <2466a754-96ab-4b5e-a887-5dba4d486867-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-08 12:47   ` Tom McLean
     [not found]     ` <5b2d2f89-3c03-4f7d-b591-5eadd075671c-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-08 20:20       ` John MacFarlane
     [not found]         ` <yh480k5zuyyk9a.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-08 20:46           ` Tom McLean
     [not found]             ` <ccffdc0d-7db4-4f5b-9e35-83e2d1e632b9-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-08 21:50               ` John MacFarlane
     [not found]                 ` <yh480kwonex1ih.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-08 23:09                   ` Tom McLean
     [not found]                     ` <86608167-1d83-4d8e-a78b-3fe602e2b075-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-01-09  0:29                       ` John MacFarlane
     [not found]                         ` <yh480kmuoawu5j.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-01-09  0:42                           ` Tom McLean

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).