git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Rationalized templates.
5914be8John MacFarlane
README+1−2
@@ -660,8 +660,7 @@ the system default templates for a given output format `FORMAT`
660by putting a file `templates/default.FORMAT` in the user data
660by putting a file `templates/default.FORMAT` in the user data
661directory (see `--data-dir`, above). *Exceptions:* For `odt` output,
661directory (see `--data-dir`, above). *Exceptions:* For `odt` output,
662customize the `default.opendocument` template. For `pdf` output,
662customize the `default.opendocument` template. For `pdf` output,
663−customize the `default.latex` template. For `epub` and `epub3` output,
663+customize the `default.latex` template.
664−customize the `epub-page.html` template.
665
664
666Templates may contain *variables*. Variable names are sequences of
665Templates may contain *variables*. Variable names are sequences of
667alphanumerics, `-`, and `_`, starting with a letter. A variable name
666alphanumerics, `-`, and `_`, starting with a letter. A variable name
pandoc.cabal+1−1
@@ -49,7 +49,7 @@ Data-Files:
49 templates/default.slideous,
49 templates/default.slideous,
50 templates/default.dzslides, templates/default.asciidoc,
50 templates/default.dzslides, templates/default.asciidoc,
51 templates/default.textile, templates/default.org,
51 templates/default.textile, templates/default.org,
52− templates/epub-page.html,
52+ templates/default.epub, templates/default.epub3,
53 -- data for ODT writer
53 -- data for ODT writer
54 reference.odt,
54 reference.odt,
55 -- data for docx writer
55 -- data for docx writer
src/Text/Pandoc/Templates.hs−2
@@ -93,8 +93,6 @@ getDefaultTemplate user writer = do
93 "native" -> return $ Right ""
93 "native" -> return $ Right ""
94 "json" -> return $ Right ""
94 "json" -> return $ Right ""
95 "docx" -> return $ Right ""
95 "docx" -> return $ Right ""
96− "epub" -> return $ Right ""
97− "epub3" -> return $ Right ""
98 "odt" -> getDefaultTemplate user "opendocument"
96 "odt" -> getDefaultTemplate user "opendocument"
99 "markdown_strict" -> getDefaultTemplate user "markdown"
97 "markdown_strict" -> getDefaultTemplate user "markdown"
100 "multimarkdown" -> getDefaultTemplate user "markdown"
98 "multimarkdown" -> getDefaultTemplate user "markdown"
src/Text/Pandoc/Writers/EPUB.hs+3−8
@@ -33,7 +33,7 @@ import Data.Maybe ( fromMaybe, isNothing )
33import Data.List ( isPrefixOf, isInfixOf, intercalate )
33import Data.List ( isPrefixOf, isInfixOf, intercalate )
34import System.Environment ( getEnv )
34import System.Environment ( getEnv )
35import Text.Printf (printf)
35import Text.Printf (printf)
36−import System.FilePath ( (</>), (<.>), takeBaseName, takeExtension, takeFileName )
36+import System.FilePath ( (</>), takeBaseName, takeExtension, takeFileName )
37import qualified Data.ByteString.Lazy as B
37import qualified Data.ByteString.Lazy as B
38import qualified Data.ByteString.Lazy.Char8 as B8
38import qualified Data.ByteString.Lazy.Char8 as B8
39import Text.Pandoc.UTF8 ( fromStringLazy )
39import Text.Pandoc.UTF8 ( fromStringLazy )
@@ -74,15 +74,12 @@ writeEPUB :: EPUBVersion
74writeEPUB version opts doc@(Pandoc meta _) = do
74writeEPUB version opts doc@(Pandoc meta _) = do
75 let epub3 = version == EPUB3
75 let epub3 = version == EPUB3
76 epochtime <- floor `fmap` getPOSIXTime
76 epochtime <- floor `fmap` getPOSIXTime
77− pageTemplate <- readDataFile (writerUserDataDir opts)
78− $ "templates" </> "epub-page" <.> "html"
79 let mkEntry path content = toEntry path epochtime content
77 let mkEntry path content = toEntry path epochtime content
80 let vars = ("epub3", if epub3 then "true" else "false")
78 let vars = ("epub3", if epub3 then "true" else "false")
81 : ("css", "stylesheet.css")
79 : ("css", "stylesheet.css")
82 : writerVariables opts
80 : writerVariables opts
83 let opts' = opts{ writerEmailObfuscation = NoObfuscation
81 let opts' = opts{ writerEmailObfuscation = NoObfuscation
84 , writerStandalone = True
82 , writerStandalone = True
85− , writerTemplate = pageTemplate
86 , writerSectionDivs = True
83 , writerSectionDivs = True
87 , writerHtml5 = epub3
84 , writerHtml5 = epub3
88 , writerTableOfContents = False -- we always have one in epub
85 , writerTableOfContents = False -- we always have one in epub
@@ -102,7 +99,7 @@ writeEPUB version opts doc@(Pandoc meta _) = do
102 Just img -> do
99 Just img -> do
103 let coverImage = "cover-image" ++ takeExtension img
100 let coverImage = "cover-image" ++ takeExtension img
104 let cpContent = renderHtml $ writeHtml opts'
101 let cpContent = renderHtml $ writeHtml opts'
105− (Pandoc meta [RawBlock "html" $ "<div id=\"cover-image\">\n<img src=\"" ++ coverImage ++ " alt=\"cover image\" />\n</div"])
102+ (Pandoc meta [RawBlock "html" $ "<div id=\"cover-image\">\n<img src=\"" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"])
106 imgContent <- B.readFile img
103 imgContent <- B.readFile img
107 return ( [mkEntry "cover.xhtml" cpContent]
104 return ( [mkEntry "cover.xhtml" cpContent]
108 , [mkEntry coverImage imgContent] )
105 , [mkEntry coverImage imgContent] )
@@ -149,9 +146,7 @@ writeEPUB version opts doc@(Pandoc meta _) = do
149 let chapToEntry :: Int -> [Block] -> Entry
146 let chapToEntry :: Int -> [Block] -> Entry
150 chapToEntry num bs = mkEntry (showChapter num)
147 chapToEntry num bs = mkEntry (showChapter num)
151 $ renderHtml
148 $ renderHtml
152− $ writeHtml opts'{ writerStandalone = True
149+ $ writeHtml opts'
153− , writerTemplate = pageTemplate
154− }
155 $ case bs of
150 $ case bs of
156 (Header 1 xs : _) -> Pandoc (Meta xs [] []) bs
151 (Header 1 xs : _) -> Pandoc (Meta xs [] []) bs
157 _ -> Pandoc (Meta [] [] []) bs
152 _ -> Pandoc (Meta [] [] []) bs
templates+1−1

Submodule changed.