@@ -62,8 +62,8 @@ import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
62import Text.Blaze.Renderer.Utf8 (renderHtml)
62import Text.Blaze.Renderer.Utf8 (renderHtml)
65−-- A Chapter includes a list of blocks and maybe a display
65+-- A Chapter includes a list of blocks and maybe a section
66−-- number. Note, some chapters are unnumbered. The display
66+-- number offset. Note, some chapters are unnumbered. The section
67-- number is different from the index number, which will be used
67-- number is different from the index number, which will be used
68-- in filenames, chapter0003.xhtml.
68-- in filenames, chapter0003.xhtml.
69data Chapter = Chapter (Maybe [Int]) [Block]
69data Chapter = Chapter (Maybe [Int]) [Block]
@@ -147,16 +147,33 @@ writeEPUB opts doc@(Pandoc meta _) = do
148 let toChapters :: [Block] -> State [Int] [Chapter]
148 let toChapters :: [Block] -> State [Int] [Chapter]
149 toChapters [] = return []
149 toChapters [] = return []
150+ toChapters (Header n attr@(_,classes,_) ils : bs) = do
152+ mbnum <- if "unnumbered" `elem` classes
154+ else case splitAt (n - 1) nums of
156+ let nums' = ks ++ [m+1]
158+ return $ Just (ks ++ [m])
159+ -- note, this is the offset not the sec number
161+ let nums' = ks ++ [1]
164+ let (xs,ys) = break isChapterHeader bs
150− toChapters (b:bs) = (Chapter Nothing (b:xs) :) `fmap` toChapters ys
165+ (Chapter mbnum (Header n attr ils : xs) :) `fmap` toChapters ys
166+ toChapters (b:bs) = do
151− where (xs,ys) = break isChapterHeader bs
167+ let (xs,ys) = break isChapterHeader bs
152−
168+ (Chapter Nothing (b:xs) :) `fmap` toChapters ys
153− let chapters = evalState (toChapters blocks'') [0,0,0,0,0,0]
170+ let chapters = evalState (toChapters blocks'') []
155 let chapToEntry :: Int -> Chapter -> Entry
172 let chapToEntry :: Int -> Chapter -> Entry
156 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
173 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
157 $ renderHtml
174 $ renderHtml
158 $ writeHtml opts'{ writerNumberOffset =
175 $ writeHtml opts'{ writerNumberOffset =
159− maybe [] (map (\x -> x - 1)) mbnum }
176+ maybe [] id mbnum }
160 $ case bs of
177 $ case bs of
161 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
178 (Header _ _ xs : _) -> Pandoc (Meta xs [] []) bs
162 _ -> Pandoc (Meta [] [] []) bs
179 _ -> Pandoc (Meta [] [] []) bs