git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: more transition.

Changed toChunks to toChapters.

commitca6cb0450918d3981850b8dfb24b65e4ca0cc8a3 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 23 Feb 2013, 19:34 (14 years ago) parent9c40535
1 file changed+10−6
src/Text/Pandoc/Writers/EPUB.hs+10−6
src/Text/Pandoc/Writers/EPUB.hs+10−6
@@ -62,6 +62,10 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
6262import Text.Blaze.Renderer.Utf8 (renderHtml)
6363#endif
6464
65+-- A Chapter includes a list of blocks and maybe a display
66+-- number. Note, some chapters are unnumbered. The display
67+-- number is different from the index number, which will be used
68+-- in filenames, chapter0003.xhtml.
6569data Chapter = Chapter (Maybe [Int]) [Block]
6670
6771-- | Produce an EPUB file from a Pandoc document.
@@ -141,12 +145,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
141145 let isChapterHeader (Header n _ _) = n <= chapterHeaderLevel
142146 isChapterHeader _ = False
143147
144− let toChunks :: [Block] -> [[Block]]
145− toChunks [] = []
146− toChunks (b:bs) = (b:xs) : toChunks ys
147− where (xs,ys) = break isChapterHeader bs
148+ let toChapters :: [Block] -> State [Int] [Chapter]
149+ toChapters [] = return []
150+ toChapters (b:bs) = (Chapter Nothing (b:xs) :) `fmap` toChapters ys
151+ where (xs,ys) = break isChapterHeader bs
148152
149− let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now
153+ let chapters = evalState (toChapters blocks'') [0,0,0,0,0,0]
150154
151155 let chapToEntry :: Int -> Chapter -> Entry
152156 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
@@ -157,7 +161,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
157161 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
158162 _ -> Pandoc (Meta [] [] []) bs
159163
160− let chapterEntries = zipWith chapToEntry [1..] chaps
164+ let chapterEntries = zipWith chapToEntry [1..] chapters
161165
162166 -- incredibly inefficient (TODO):
163167 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)