From eca8c6043b1759dc6e821eb541d801421127eb61 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 16 Feb 2013 17:36:39 -0800 Subject: EPUB writer: Fix section numbering. Previously the numbering restarted from 1 in each chapter (with `--number-sections`), though the numbers in the table of contents were correct. Note that this fix is a bit hackish and possibly fragile: if the rendering of section numbers in HTML changes in the future, it may break. But it works, without needing changes in other modules. --- src/Text/Pandoc/Writers/EPUB.hs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 58a1308f2..d58d05f08 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -147,6 +147,7 @@ writeEPUB opts doc@(Pandoc meta _) = do let chapToEntry :: Int -> [Block] -> Entry chapToEntry num bs = mkEntry (showChapter num) + $ fixSectionNumbers num $ renderHtml $ writeHtml opts' $ case bs of @@ -230,7 +231,7 @@ writeEPUB opts doc@(Pandoc meta _) = do let navPointNode :: (Int -> String -> String -> [Element] -> Element) -> Shared.Element -> State Int Element - navPointNode formatter (Sec _ nums (ident,classes,keyvals) ils children) = do + navPointNode formatter (Sec _ nums (ident,_,_) ils children) = do n <- get modify (+1) let showNums :: [Int] -> String @@ -477,3 +478,9 @@ replaceRefs refTable = bottomUp replaceOneRef Just url -> Link lab (url,tit) Nothing -> x replaceOneRef x = x + +-- This is ugly and inefficient. +fixSectionNumbers :: Int -> B8.ByteString -> B8.ByteString +fixSectionNumbers num = B8.pack . go . B8.unpack + where go = substitute "1" + ("" ++ show num) -- cgit v1.2.3