@@ -27,7 +27,6 @@ import qualified Data.ByteString.Lazy as B
2727import qualified Data.ByteString.Lazy.Char8 as B8
2828import Data.Char (isAlphaNum, isAscii, isDigit, toLower)
2929import Data.List (isInfixOf, isPrefixOf)
30−import Data.List.Split (splitWhen)
3130import qualified Data.Map as M
3231import Data.Maybe (fromMaybe, isNothing, mapMaybe, isJust)
3332import qualified Data.Set as Set
@@ -60,11 +59,8 @@ import Text.XML.Light (Attr (..), Element (..), Node (..), QName (..),
6059 ppElement, showElement, strContent, unode, unqual)
6160import Text.Pandoc.XML (escapeStringForXML)
6261
63−-- A Chapter includes a list of blocks and maybe a section
64−-- number offset. Note, some chapters are unnumbered. The section
65−-- number is different from the index number, which will be used
66−-- in filenames, chapter0003.xhtml.
67−data Chapter = Chapter (Maybe [Int]) [Block]
62+-- A Chapter includes a list of blocks.
63+data Chapter = Chapter [Block]
6864
6965data EPUBState = EPUBState {
7066 stMediaPaths :: [(FilePath, (FilePath, Maybe Entry))]
@@ -519,16 +515,16 @@ pandocToEPUB version opts doc = do
519515
520516 let secsToChapters :: [Block] -> [Chapter]
521517 secsToChapters [] = []
522− secsToChapters (d@(Div (_,"section":_,_) bs) : rest)
523− | isChapterHeader d =
524− Chapter mbnum [d] : secsToChapters rest
525− where mbnum = case bs of
526− (Header _ (_,_,kvs) _ : _) ->
527− map (fromMaybe 0 . safeRead) .
528− splitWhen (=='.') <$> lookup "number" kvs
529− _ -> Nothing
518+ secsToChapters (d@(Div attr@(_,"section":_,_)
519+ (h@(Header lvl _ _) : bs)) : rest)
520+ | chapterHeaderLevel == lvl =
521+ Chapter [d] : secsToChapters rest
522+ | chapterHeaderLevel > lvl =
523+ Chapter [Div attr (h:xs)] :
524+ secsToChapters ys ++ secsToChapters rest
525+ where (xs, ys) = break isChapterHeader bs
530526 secsToChapters bs =
531− Chapter Nothing xs : secsToChapters ys
527+ Chapter xs : secsToChapters ys
532528 where (xs, ys) = break isChapterHeader bs
533529
534530 let chapters' = secsToChapters $ makeSections True Nothing blocks'
@@ -545,7 +541,7 @@ pandocToEPUB version opts doc = do
545541 | not (null ident) = [(ident, showChapter num ++ ('#':ident))]
546542 extractLinkURL num b = query (extractLinkURL' num) b
547543
548− let reftable = concat $ zipWith (\(Chapter _ bs) num ->
544+ let reftable = concat $ zipWith (\(Chapter bs) num ->
549545 query (extractLinkURL num) bs)
550546 chapters' [1..]
551547
@@ -559,11 +555,11 @@ pandocToEPUB version opts doc = do
559555 -- internal reference IDs change when we chunk the file,
560556 -- so that '#my-header-1' might turn into 'chap004.xhtml#my-header'.
561557 -- this fixes that:
562− let chapters = map (\(Chapter mbnum bs) ->
563− Chapter mbnum $ walk fixInternalReferences bs)
558+ let chapters = map (\(Chapter bs) ->
559+ Chapter $ walk fixInternalReferences bs)
564560 chapters'
565561
566− let chapToEntry num (Chapter _ bs) =
562+ let chapToEntry num (Chapter bs) =
567563 mkEntry ("text/" ++ showChapter num) =<<
568564 writeHtml opts'{ writerVariables = ("body-type", bodyType) :
569565 ("pagetitle", showChapter num) :