@@ -62,6 +62,8 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
6262import Text.Blaze.Renderer.Utf8 (renderHtml)
6363#endif
6464
65+data Chapter = Chapter (Maybe [Int]) [Block]
66+
6567-- | Produce an EPUB file from a Pandoc document.
6668writeEPUB :: WriterOptions -- ^ Writer options
6769 -> Pandoc -- ^ Document to convert
@@ -144,17 +146,18 @@ writeEPUB opts doc@(Pandoc meta _) = do
144146 toChunks (b:bs) = (b:xs) : toChunks ys
145147 where (xs,ys) = break isChapterHeader bs
146148
147− let chunks = toChunks blocks''
149+ let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now
148150
149− let chapToEntry :: Int -> [Block] -> Entry
150− chapToEntry num bs = mkEntry (showChapter num)
151+ let chapToEntry :: Int -> Chapter -> Entry
152+ chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
151153 $ renderHtml
152− $ writeHtml opts'{ writerNumberOffset = [num - 1] }
154+ $ writeHtml opts'{ writerNumberOffset =
155+ maybe [] (map (\x -> x - 1)) mbnum }
153156 $ case bs of
154157 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
155158 _ -> Pandoc (Meta [] [] []) bs
156159
157− let chapterEntries = zipWith chapToEntry [1..] chunks
160+ let chapterEntries = zipWith chapToEntry [1..] chaps
158161
159162 -- incredibly inefficient (TODO):
160163 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)