git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: more transition.
ca6cb04John MacFarlane
src/Text/Pandoc/Writers/EPUB.hs+10−6
@@ -62,6 +62,10 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
62import Text.Blaze.Renderer.Utf8 (renderHtml)
62import Text.Blaze.Renderer.Utf8 (renderHtml)
63#endif
63#endif
64
64
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.
65data Chapter = Chapter (Maybe [Int]) [Block]
69data Chapter = Chapter (Maybe [Int]) [Block]
66
70
67-- | Produce an EPUB file from a Pandoc document.
71-- | Produce an EPUB file from a Pandoc document.
@@ -141,12 +145,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
141 let isChapterHeader (Header n _ _) = n <= chapterHeaderLevel
145 let isChapterHeader (Header n _ _) = n <= chapterHeaderLevel
142 isChapterHeader _ = False
146 isChapterHeader _ = False
143
147
144− let toChunks :: [Block] -> [[Block]]
148+ let toChapters :: [Block] -> State [Int] [Chapter]
145− toChunks [] = []
149+ toChapters [] = return []
146− toChunks (b:bs) = (b:xs) : toChunks ys
150+ toChapters (b:bs) = (Chapter Nothing (b:xs) :) `fmap` toChapters ys
147− where (xs,ys) = break isChapterHeader bs
151+ where (xs,ys) = break isChapterHeader bs
148
152
149− let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now
153+ let chapters = evalState (toChapters blocks'') [0,0,0,0,0,0]
150
154
151 let chapToEntry :: Int -> Chapter -> Entry
155 let chapToEntry :: Int -> Chapter -> Entry
152 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
156 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
@@ -157,7 +161,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
157 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
161 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
158 _ -> Pandoc (Meta [] [] []) bs
162 _ -> Pandoc (Meta [] [] []) bs
159
163
160− let chapterEntries = zipWith chapToEntry [1..] chaps
164+ let chapterEntries = zipWith chapToEntry [1..] chapters
161
165
162 -- incredibly inefficient (TODO):
166 -- incredibly inefficient (TODO):
163 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)
167 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)