public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
@ 2019-07-03 16:24 Sal Migondis
       [not found] ` <a69adf22-5bde-4df3-9d43-fba2c67f4faa-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: Sal Migondis @ 2019-07-03 16:24 UTC (permalink / raw)
  To: pandoc-discuss


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

Is there any way I can customize the generated EPUB/text/cover.xhtml file 
created by pandoc?

Basically I would need to replace the default:

<div id="cover-image">
> <img src="../media/cover.png" alt="cover image" />
> </div>
>
>
By something like this:

<div id="cover-image">
> <svg xmlns="http://www.w3.org/2000/svg" 
> xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" 
> height="100%" viewBox="0 0 900 1200" preserveAspectRatio="none">
> <image width="900" height="1200" xlink:href="../media/cover.png"/>
> </svg>
> </div>
>
>
The idea is to wrap the cover image in an <svg> </svg> tag so that it 
scales to the dimensions of the e-reader.

Note that 900x1200 just happens to be the dimensions of the default covers 
I generate on my system.

I am having a problem where my covers are not correctly displayed on the 
e-reader I use (ancient Kobo glo' with 758x1024 screen). 

Thanks,

SM

-- 
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/a69adf22-5bde-4df3-9d43-fba2c67f4faa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found] ` <a69adf22-5bde-4df3-9d43-fba2c67f4faa-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-07-03 16:59   ` John MacFarlane
       [not found]     ` <871rz7m4u0.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  2019-07-03 19:50   ` Sal Migondis
  2019-07-05 22:46   ` Sal Migondis
  2 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-07-03 16:59 UTC (permalink / raw)
  To: Sal Migondis, pandoc-discuss


The cover page uses the default.epub3 (or .epub2)
template, but with the coverpage variable set to
true.  So you can use a custom template that
changes what is inserted when that variable is set.

The template variable epub-cover-image should
contain the image file name.


Sal Migondis <salmig99-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Is there any way I can customize the generated EPUB/text/cover.xhtml file 
> created by pandoc?
>
> Basically I would need to replace the default:
>
> <div id="cover-image">
>> <img src="../media/cover.png" alt="cover image" />
>> </div>
>>
>>
> By something like this:
>
> <div id="cover-image">
>> <svg xmlns="http://www.w3.org/2000/svg" 
>> xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" 
>> height="100%" viewBox="0 0 900 1200" preserveAspectRatio="none">
>> <image width="900" height="1200" xlink:href="../media/cover.png"/>
>> </svg>
>> </div>
>>
>>
> The idea is to wrap the cover image in an <svg> </svg> tag so that it 
> scales to the dimensions of the e-reader.
>
> Note that 900x1200 just happens to be the dimensions of the default covers 
> I generate on my system.
>
> I am having a problem where my covers are not correctly displayed on the 
> e-reader I use (ancient Kobo glo' with 758x1024 screen). 
>
> Thanks,
>
> SM
>
> -- 
> 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/a69adf22-5bde-4df3-9d43-fba2c67f4faa%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found]     ` <871rz7m4u0.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-07-03 17:00       ` John MacFarlane
  0 siblings, 0 replies; 8+ messages in thread
From: John MacFarlane @ 2019-07-03 17:00 UTC (permalink / raw)
  To: Sal Migondis, pandoc-discuss


One more tip: you'll want to suppress the body
variable when coverpage is set, since that's
what is usually populated by the current
div/img structure.

John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> writes:

> The cover page uses the default.epub3 (or .epub2)
> template, but with the coverpage variable set to
> true.  So you can use a custom template that
> changes what is inserted when that variable is set.
>
> The template variable epub-cover-image should
> contain the image file name.
>
>
> Sal Migondis <salmig99-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
>> Is there any way I can customize the generated EPUB/text/cover.xhtml file 
>> created by pandoc?
>>
>> Basically I would need to replace the default:
>>
>> <div id="cover-image">
>>> <img src="../media/cover.png" alt="cover image" />
>>> </div>
>>>
>>>
>> By something like this:
>>
>> <div id="cover-image">
>>> <svg xmlns="http://www.w3.org/2000/svg" 
>>> xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="100%" 
>>> height="100%" viewBox="0 0 900 1200" preserveAspectRatio="none">
>>> <image width="900" height="1200" xlink:href="../media/cover.png"/>
>>> </svg>
>>> </div>
>>>
>>>
>> The idea is to wrap the cover image in an <svg> </svg> tag so that it 
>> scales to the dimensions of the e-reader.
>>
>> Note that 900x1200 just happens to be the dimensions of the default covers 
>> I generate on my system.
>>
>> I am having a problem where my covers are not correctly displayed on the 
>> e-reader I use (ancient Kobo glo' with 758x1024 screen). 
>>
>> Thanks,
>>
>> SM
>>
>> -- 
>> 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/a69adf22-5bde-4df3-9d43-fba2c67f4faa%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.


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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found] ` <a69adf22-5bde-4df3-9d43-fba2c67f4faa-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-07-03 16:59   ` John MacFarlane
@ 2019-07-03 19:50   ` Sal Migondis
       [not found]     ` <37457961-7b29-4490-a5b0-70063b901ed2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-07-05 22:46   ` Sal Migondis
  2 siblings, 1 reply; 8+ messages in thread
From: Sal Migondis @ 2019-07-03 19:50 UTC (permalink / raw)
  To: pandoc-discuss


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

Thank you for prompt response. 

I copied the default.epub3 template to ~/.pandoc/templates/default.epub3 
and added the above <div><svg> ... </svg></div> and ran pandoc.

What happens is that my cover.xhtml custom code does not replace the 
default <div><img> ... </div> ... It gets inserted as expected but the 
default code is also there below it! Hence epubcheck gives me an error 
(duplicate ID 'cover-image' and there is a duplicate cover image in the 
resulting epub.

How do I "suppress" the body variable? I tried specifying "-V body=' '" 
(body="false" etc.) ... but that caused *all *the xhtml files in the epub 
to contain the same code as cover.xhtml and nothing else. 

I also tried to unset the 'body' variable directly inside the template in 
"$if(coverpage)$ ... $endif$ ... hoping the variable's content would be 
restored to its original value after leaving the if(coverpage)'s ... endif 
scope ...but this didn't seem to do anything except perhaps give me an 
error when running pandoc IIRC...

In any event, here's what I added to my default.epub3:


<body$if(coverpage)$ id="cover"$endif$>
$if(coverpage)$
<div id="cover-image">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink=
"http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" 
viewBox="0 0 900 1200" preserveAspectRatio="none">
<image width="900" height="1200" xlink:href="../media/cover.png"/>
</svg>
</div>
$endif$

Obviously I'm not doing it right but I'm not sure how I could fix this.

Thanks,

SM

-- 
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/37457961-7b29-4490-a5b0-70063b901ed2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found]     ` <37457961-7b29-4490-a5b0-70063b901ed2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-07-05 10:57       ` John MacFarlane
  0 siblings, 0 replies; 8+ messages in thread
From: John MacFarlane @ 2019-07-05 10:57 UTC (permalink / raw)
  To: Sal Migondis, pandoc-discuss


You need to restructure the template so that, in the
if(coverpage) part, the $body$ variable simply does
not appear.

A simple way would be to replace

$body$

with

$if(coverpage)$
$else$
$body$
$endif$

Sal Migondis <salmig99-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Thank you for prompt response. 
>
> I copied the default.epub3 template to ~/.pandoc/templates/default.epub3 
> and added the above <div><svg> ... </svg></div> and ran pandoc.
>
> What happens is that my cover.xhtml custom code does not replace the 
> default <div><img> ... </div> ... It gets inserted as expected but the 
> default code is also there below it! Hence epubcheck gives me an error 
> (duplicate ID 'cover-image' and there is a duplicate cover image in the 
> resulting epub.
>
> How do I "suppress" the body variable? I tried specifying "-V body=' '" 
> (body="false" etc.) ... but that caused *all *the xhtml files in the epub 
> to contain the same code as cover.xhtml and nothing else. 
>
> I also tried to unset the 'body' variable directly inside the template in 
> "$if(coverpage)$ ... $endif$ ... hoping the variable's content would be 
> restored to its original value after leaving the if(coverpage)'s ... endif 
> scope ...but this didn't seem to do anything except perhaps give me an 
> error when running pandoc IIRC...
>
> In any event, here's what I added to my default.epub3:
>
>
> <body$if(coverpage)$ id="cover"$endif$>
> $if(coverpage)$
> <div id="cover-image">
> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink=
> "http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" 
> viewBox="0 0 900 1200" preserveAspectRatio="none">
> <image width="900" height="1200" xlink:href="../media/cover.png"/>
> </svg>
> </div>
> $endif$
>
> Obviously I'm not doing it right but I'm not sure how I could fix this.
>
> Thanks,
>
> SM
>
> -- 
> 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/37457961-7b29-4490-a5b0-70063b901ed2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.


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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found] ` <a69adf22-5bde-4df3-9d43-fba2c67f4faa-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2019-07-03 16:59   ` John MacFarlane
  2019-07-03 19:50   ` Sal Migondis
@ 2019-07-05 22:46   ` Sal Migondis
       [not found]     ` <0da36f70-8fc2-4571-abc7-69fe3a24ee35-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  2 siblings, 1 reply; 8+ messages in thread
From: Sal Migondis @ 2019-07-05 22:46 UTC (permalink / raw)
  To: pandoc-discuss


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

Thanks. 

I gave it a shot and gave up after another an hour of trial and error. What 
language do the pandoc templates use? is it syntax that's pandoc-specific 
or a language whose grammar is documented some place or other?

Anyway I have given up on this and as a work-around I put together a shell 
script that:

1. runs pandoc to create the epub
2. unzips the epub
3. runs some standard *nix tools to fix the cover.xhtml file (head, cat, 
sed…) and add "properties=svg" to its <item> reference in the content.opf 
"manifest"
4. zips back the epub
5. runs epubcheck to verify the resulting epub's conformity.

qwick and dirty... not flexible.. works for me…

In any case, since programs that specialize in epub editing/handling such 
as sigil or calibre appear to use this svg wrapper strategy in order to 
ensure that the cover image is scaled to cover the entire display area of 
the e-reader's screen, my feeling about this is that when the 
--epub-cover-image option is used… perhaps pandoc should do likewise and 
generate this type of code *BY DEFAULT*... rather than via a custom 
template...? 

Thanks,

SM

On Wednesday, July 3, 2019 at 12:24:42 PM UTC-4, Sal Migondis wrote:
>
> Is there any way I can customize the generated EPUB/text/cover.xhtml file 
> created by pandoc?
>
> Basically I would need to replace the default:
>
> <div id="cover-image">
>> <img src="../media/cover.png" alt="cover image" />
>> </div>
>>
>>
> By something like this:
>
> <div id="cover-image">
>> <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="
>> http://www.w3.org/1999/xlink" version="1.1" width="100%" height="100%" 
>> viewBox="0 0 900 1200" preserveAspectRatio="none">
>> <image width="900" height="1200" xlink:href="../media/cover.png"/>
>> </svg>
>> </div>
>>
>>
> The idea is to wrap the cover image in an <svg> </svg> tag so that it 
> scales to the dimensions of the e-reader.
>
> Note that 900x1200 just happens to be the dimensions of the default covers 
> I generate on my system.
>
> I am having a problem where my covers are not correctly displayed on the 
> e-reader I use (ancient Kobo glo' with 758x1024 screen). 
>
> Thanks,
>
> SM
>

-- 
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/0da36f70-8fc2-4571-abc7-69fe3a24ee35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found]     ` <0da36f70-8fc2-4571-abc7-69fe3a24ee35-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2019-07-07 15:55       ` John MacFarlane
       [not found]         ` <87imsdg7qa.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 8+ messages in thread
From: John MacFarlane @ 2019-07-07 15:55 UTC (permalink / raw)
  To: Sal Migondis, pandoc-discuss

Sal Migondis <salmig99-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> Thanks. 
>
> I gave it a shot and gave up after another an hour of trial and error. What 
> language do the pandoc templates use? is it syntax that's pandoc-specific 
> or a language whose grammar is documented some place or other?

It is pandoc-specific: it is documented in the
Templates section of the manual. See also

https://github.com/jgm/doctemplates

In both places the documentation could be more
complete. Looking at the existing templates as
examples may help.

> In any case, since programs that specialize in epub editing/handling such 
> as sigil or calibre appear to use this svg wrapper strategy in order to 
> ensure that the cover image is scaled to cover the entire display area of 
> the e-reader's screen, my feeling about this is that when the 
> --epub-cover-image option is used… perhaps pandoc should do likewise and 
> generate this type of code *BY DEFAULT*... rather than via a custom 
> template...? 

It's a good suggestion probably.  Why don't you open
up an enhancement request issue on our GitHub
repository, jgm/pandoc, suggesting this and giving
the basic code that is required?

-- 
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/87imsdg7qa.fsf%40johnmacfarlane.net.
For more options, visit https://groups.google.com/d/optout.


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

* Re: pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml
       [not found]         ` <87imsdg7qa.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2019-07-09 18:43           ` Sal Migondis
  0 siblings, 0 replies; 8+ messages in thread
From: Sal Migondis @ 2019-07-09 18:43 UTC (permalink / raw)
  To: pandoc-discuss


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

Opened issue #5638 on jgm/pandoc as per your request.

Please let me know if it's suitable.

Thanks,

SM

On Sunday, July 7, 2019 at 11:55:24 AM UTC-4, John MacFarlane wrote:

>
> It's a good suggestion probably.  Why don't you open 
> up an enhancement request issue on our GitHub 
> repository, jgm/pandoc, suggesting this and giving 
> the basic code that is required? 
>

-- 
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/7d96dc6d-dc62-41e1-aac4-605ecacac79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

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

end of thread, other threads:[~2019-07-09 18:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 16:24 pandoc markdown to epub conversion - customize EPUB/text/cover.xhtml Sal Migondis
     [not found] ` <a69adf22-5bde-4df3-9d43-fba2c67f4faa-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-03 16:59   ` John MacFarlane
     [not found]     ` <871rz7m4u0.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-07-03 17:00       ` John MacFarlane
2019-07-03 19:50   ` Sal Migondis
     [not found]     ` <37457961-7b29-4490-a5b0-70063b901ed2-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-05 10:57       ` John MacFarlane
2019-07-05 22:46   ` Sal Migondis
     [not found]     ` <0da36f70-8fc2-4571-abc7-69fe3a24ee35-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2019-07-07 15:55       ` John MacFarlane
     [not found]         ` <87imsdg7qa.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2019-07-09 18:43           ` Sal Migondis

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).