aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-02-23 18:51:58 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-02-23 18:51:58 -0800
commit9c40535c4774c3b55e631f9a077b510e3ad1298d (patch)
treefb265625049eb47d6bc8876d1860bedd88fa12aa /src
parent8b8c8cfed928a2429a8640213694c82635039c5a (diff)
downloadpandoc-9c40535c4774c3b55e631f9a077b510e3ad1298d.tar.gz
EPUB writer: Temporary step towards a better system for numbering.
With this change, `--number-sections` won't work. This will be fixed later.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs13
1 files changed, 8 insertions, 5 deletions
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 = "<math" `isInfixOf` (B8.unpack $ fromEntry ent)