git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Fix section numbering.
eca8c60John MacFarlane
src/Text/Pandoc/Writers/EPUB.hs+8−1
@@ -147,6 +147,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
147
147
148 let chapToEntry :: Int -> [Block] -> Entry
148 let chapToEntry :: Int -> [Block] -> Entry
149 chapToEntry num bs = mkEntry (showChapter num)
149 chapToEntry num bs = mkEntry (showChapter num)
150+ $ fixSectionNumbers num
150 $ renderHtml
151 $ renderHtml
151 $ writeHtml opts'
152 $ writeHtml opts'
152 $ case bs of
153 $ case bs of
@@ -230,7 +231,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
230
231
231 let navPointNode :: (Int -> String -> String -> [Element] -> Element)
232 let navPointNode :: (Int -> String -> String -> [Element] -> Element)
232 -> Shared.Element -> State Int Element
233 -> Shared.Element -> State Int Element
233− navPointNode formatter (Sec _ nums (ident,classes,keyvals) ils children) = do
234+ navPointNode formatter (Sec _ nums (ident,_,_) ils children) = do
234 n <- get
235 n <- get
235 modify (+1)
236 modify (+1)
236 let showNums :: [Int] -> String
237 let showNums :: [Int] -> String
@@ -477,3 +478,9 @@ replaceRefs refTable = bottomUp replaceOneRef
477 Just url -> Link lab (url,tit)
478 Just url -> Link lab (url,tit)
478 Nothing -> x
479 Nothing -> x
479 replaceOneRef x = x
480 replaceOneRef x = x
481+
482+-- This is ugly and inefficient.
483+fixSectionNumbers :: Int -> B8.ByteString -> B8.ByteString
484+fixSectionNumbers num = B8.pack . go . B8.unpack
485+ where go = substitute "<span class=\"header-section-number\">1"
486+ ("<span class=\"header-section-number\">" ++ show num)