diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-02-23 19:34:04 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-02-23 19:34:04 -0800 |
commit | ca6cb0450918d3981850b8dfb24b65e4ca0cc8a3 (patch) | |
tree | 9ee94cfa30f66d60eb1107dc51192d9bf0faa9a1 /src/Text | |
parent | 9c40535c4774c3b55e631f9a077b510e3ad1298d (diff) | |
download | pandoc-ca6cb0450918d3981850b8dfb24b65e4ca0cc8a3.tar.gz |
EPUB writer: more transition.
Changed toChunks to toChapters.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index aa2c21111..72262a884 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -62,6 +62,10 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml) import Text.Blaze.Renderer.Utf8 (renderHtml) #endif +-- A Chapter includes a list of blocks and maybe a display +-- number. Note, some chapters are unnumbered. The display +-- number is different from the index number, which will be used +-- in filenames, chapter0003.xhtml. data Chapter = Chapter (Maybe [Int]) [Block] -- | Produce an EPUB file from a Pandoc document. @@ -141,12 +145,12 @@ writeEPUB opts doc@(Pandoc meta _) = do let isChapterHeader (Header n _ _) = n <= chapterHeaderLevel isChapterHeader _ = False - let toChunks :: [Block] -> [[Block]] - toChunks [] = [] - toChunks (b:bs) = (b:xs) : toChunks ys - where (xs,ys) = break isChapterHeader bs + let toChapters :: [Block] -> State [Int] [Chapter] + toChapters [] = return [] + toChapters (b:bs) = (Chapter Nothing (b:xs) :) `fmap` toChapters ys + where (xs,ys) = break isChapterHeader bs - let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now + let chapters = evalState (toChapters blocks'') [0,0,0,0,0,0] let chapToEntry :: Int -> Chapter -> Entry chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num) @@ -157,7 +161,7 @@ writeEPUB opts doc@(Pandoc meta _) = do (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs _ -> Pandoc (Meta [] [] []) bs - let chapterEntries = zipWith chapToEntry [1..] chaps + let chapterEntries = zipWith chapToEntry [1..] chapters -- incredibly inefficient (TODO): let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent) |