aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-02-23 19:34:04 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-02-23 19:34:04 -0800
commitca6cb0450918d3981850b8dfb24b65e4ca0cc8a3 (patch)
tree9ee94cfa30f66d60eb1107dc51192d9bf0faa9a1 /src
parent9c40535c4774c3b55e631f9a077b510e3ad1298d (diff)
downloadpandoc-ca6cb0450918d3981850b8dfb24b65e4ca0cc8a3.tar.gz
EPUB writer: more transition.
Changed toChunks to toChapters.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs16
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)