From a7b8351d436434165c6cc70ba855322c76c102cf Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sun, 4 Nov 2012 20:53:27 -0800
Subject: [PATCH] EPUB writer: Removed need for separate epub-coverpage
 template.

The standard epub-page template is now used.
---
 README                          |  3 +--
 pandoc.cabal                    |  1 -
 src/Text/Pandoc/Writers/EPUB.hs | 16 +++++-----------
 templates                       |  2 +-
 4 files changed, 7 insertions(+), 15 deletions(-)

diff --git a/README b/README
index 5134020b0..77de7cbf4 100644
--- a/README
+++ b/README
@@ -661,8 +661,7 @@ by putting a file `templates/default.FORMAT` in the user data
 directory (see `--data-dir`, above). *Exceptions:* For `odt` output,
 customize the `default.opendocument` template.  For `pdf` output,
 customize the `default.latex` template. For `epub` and `epub3` output,
-customize the `epub-page.html`, `epub-coverimage.html`, and
-`epub-titlepage.html` templates.
+customize the `epub-page.html`, and `epub-titlepage.html` templates.
 
 Templates may contain *variables*.  Variable names are sequences of
 alphanumerics, `-`, and `_`, starting with a letter.  A variable name
diff --git a/pandoc.cabal b/pandoc.cabal
index 356b38b33..279b327b9 100644
--- a/pandoc.cabal
+++ b/pandoc.cabal
@@ -50,7 +50,6 @@ Data-Files:
                  templates/default.dzslides, templates/default.asciidoc,
                  templates/default.textile, templates/default.org,
                  templates/epub-titlepage.html, templates/epub-page.html,
-                 templates/epub-coverimage.html,
                  -- data for ODT writer
                  reference.odt,
                  -- data for docx writer
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 4effc7b2b..dabb9722b 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -74,12 +74,15 @@ writeEPUB :: EPUBVersion
 writeEPUB version opts doc@(Pandoc meta _) = do
   let epub3 = version == EPUB3
   epochtime <- floor `fmap` getPOSIXTime
+  pageTemplate <- readDataFile (writerUserDataDir opts)
+                       $ "templates" </> "epub-page" <.> "html"
   let mkEntry path content = toEntry path epochtime content
   let vars = ("epub3", if epub3 then "true" else "false")
            : ("css", "stylesheet.css")
            : writerVariables opts
   let opts' = opts{ writerEmailObfuscation = NoObfuscation
                   , writerStandalone = True
+                  , writerTemplate = pageTemplate
                   , writerSectionDivs = True
                   , writerHtml5 = epub3
                   , writerTableOfContents = False -- we always have one in epub
@@ -95,23 +98,14 @@ writeEPUB version opts doc@(Pandoc meta _) = do
   titlePageTemplate <- readDataFile (writerUserDataDir opts')
                        $ "templates" </> "epub-titlepage" <.> "html"
 
-  coverImageTemplate <- readDataFile (writerUserDataDir opts')
-                       $ "templates" </> "epub-coverimage" <.> "html"
-
-  pageTemplate <- readDataFile (writerUserDataDir opts')
-                       $ "templates" </> "epub-page" <.> "html"
-
   -- cover page
   (cpgEntry, cpicEntry) <-
                 case mbCoverImage of
                      Nothing   -> return ([],[])
                      Just img  -> do
                        let coverImage = "cover-image" ++ takeExtension img
-                       let cpContent = fromStringLazy $ writeHtmlString
-                             opts'{writerTemplate = coverImageTemplate,
-                                   writerHtml5 = epub3,
-                                   writerVariables = ("coverimage",coverImage):vars}
-                               (Pandoc meta [])
+                       let cpContent = renderHtml $ writeHtml opts'
+                               (Pandoc meta [RawBlock "html" $ "<div id=\"cover-image\">\n<img src=\"" ++ coverImage ++ " alt=\"cover image\" />\n</div"])
                        imgContent <- B.readFile img
                        return ( [mkEntry "cover.xhtml" cpContent]
                               , [mkEntry coverImage imgContent] )
diff --git a/templates b/templates
index 9fae8b31d..cd898b1d2 160000
--- a/templates
+++ b/templates
@@ -1 +1 @@
-Subproject commit 9fae8b31dd1fc3667993a35b7db6b252b85c840d
+Subproject commit cd898b1d2febb88686054e4a63690b8c7891ae03