git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Use writerNumberFrom instead of ugly hack.
a33828fJohn MacFarlane
src/Text/Pandoc/Writers/EPUB.hs+1−8
@@ -147,9 +147,8 @@ 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
151 $ renderHtml
150 $ renderHtml
152− $ writeHtml opts'
151+ $ writeHtml opts'{ writerNumberFrom = num }
153 $ case bs of
152 $ case bs of
154 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
153 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
155 _ -> Pandoc (Meta [] [] []) bs
154 _ -> Pandoc (Meta [] [] []) bs
@@ -478,9 +477,3 @@ replaceRefs refTable = bottomUp replaceOneRef
478 Just url -> Link lab (url,tit)
477 Just url -> Link lab (url,tit)
479 Nothing -> x
478 Nothing -> x
480 replaceOneRef x = x
479 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)