git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Temporary step towards a better system for numbering.
9c40535John MacFarlane
src/Text/Pandoc/Writers/EPUB.hs+8−5
@@ -62,6 +62,8 @@ 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+data Chapter = Chapter (Maybe [Int]) [Block]
66+
65-- | Produce an EPUB file from a Pandoc document.
67-- | Produce an EPUB file from a Pandoc document.
66writeEPUB :: WriterOptions -- ^ Writer options
68writeEPUB :: WriterOptions -- ^ Writer options
67 -> Pandoc -- ^ Document to convert
69 -> Pandoc -- ^ Document to convert
@@ -144,17 +146,18 @@ writeEPUB opts doc@(Pandoc meta _) = do
144 toChunks (b:bs) = (b:xs) : toChunks ys
146 toChunks (b:bs) = (b:xs) : toChunks ys
145 where (xs,ys) = break isChapterHeader bs
147 where (xs,ys) = break isChapterHeader bs
146
148
147− let chunks = toChunks blocks''
149+ let chaps = map (Chapter Nothing) $ toChunks blocks'' -- TODO For now
148
150
149− let chapToEntry :: Int -> [Block] -> Entry
151+ let chapToEntry :: Int -> Chapter -> Entry
150− chapToEntry num bs = mkEntry (showChapter num)
152+ chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
151 $ renderHtml
153 $ renderHtml
152− $ writeHtml opts'{ writerNumberOffset = [num - 1] }
154+ $ writeHtml opts'{ writerNumberOffset =
155+ maybe [] (map (\x -> x - 1)) mbnum }
153 $ case bs of
156 $ case bs of
154 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
157 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
155 _ -> Pandoc (Meta [] [] []) bs
158 _ -> Pandoc (Meta [] [] []) bs
156
159
157− let chapterEntries = zipWith chapToEntry [1..] chunks
160+ let chapterEntries = zipWith chapToEntry [1..] chaps
158
161
159 -- incredibly inefficient (TODO):
162 -- incredibly inefficient (TODO):
160 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)
163 let containsMathML ent = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)