From 9c40535c4774c3b55e631f9a077b510e3ad1298d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 23 Feb 2013 18:51:58 -0800 Subject: EPUB writer: Temporary step towards a better system for numbering. With this change, `--number-sections` won't work. This will be fixed later. --- src/Text/Pandoc/Writers/EPUB.hs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 048f90da1..aa2c21111 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -62,6 +62,8 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml) import Text.Blaze.Renderer.Utf8 (renderHtml) #endif +data Chapter = Chapter (Maybe [Int]) [Block] + -- | Produce an EPUB file from a Pandoc document. writeEPUB :: WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert @@ -144,17 +146,18 @@ writeEPUB opts doc@(Pandoc meta _) = do toChunks (b:bs) = (b:xs) : toChunks ys where (xs,ys) = break isChapterHeader bs - let chunks = toChunks blocks'' + let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now - let chapToEntry :: Int -> [Block] -> Entry - chapToEntry num bs = mkEntry (showChapter num) + let chapToEntry :: Int -> Chapter -> Entry + chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num) $ renderHtml - $ writeHtml opts'{ writerNumberOffset = [num - 1] } + $ writeHtml opts'{ writerNumberOffset = + maybe [] (map (\x -> x - 1)) mbnum } $ case bs of (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs _ -> Pandoc (Meta [] [] []) bs - let chapterEntries = zipWith chapToEntry [1..] chunks + let chapterEntries = zipWith chapToEntry [1..] chaps -- incredibly inefficient (TODO): let containsMathML ent = "