aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2013-02-16 17:36:39 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2013-02-16 17:36:39 -0800
commiteca8c6043b1759dc6e821eb541d801421127eb61 (patch)
treed4731db8bb8321c9c6c19134a16e0aad7ee543ae
parent14b64ed46c72adbaa4c1c6ed26b10df89756e178 (diff)
downloadpandoc-eca8c6043b1759dc6e821eb541d801421127eb61.tar.gz
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.
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs9
1 files changed, 8 insertions, 1 deletions
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 "<span class=\"header-section-number\">1"
+ ("<span class=\"header-section-number\">" ++ show num)