@@ -461,6 +461,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
461461 -- title page
462462 tpContent <- lift $ writeHtml opts'{
463463 writerVariables = ("titlepage","true"):
464+ ("body-type", "frontmatter"):
464465 ("pagetitle", escapeStringForXML plainTitle):
465466 cssvars True ++ vars }
466467 (Pandoc meta [])
@@ -565,13 +566,28 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
565566 let chapToEntry num (Chapter mbnum bs) =
566567 mkEntry ("text/" ++ showChapter num) =<<
567568 writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum
568− , writerVariables = cssvars True ++ vars }
569− (case bs of
570− (Header _ _ xs : _) ->
569+ , writerVariables = ("body-type", bodyType) :
570+ cssvars True ++ vars } pdoc
571+ where (pdoc, bodyType) =
572+ case bs of
573+ (Header _ (_,_,kvs) xs : _) ->
571574 -- remove notes or we get doubled footnotes
572− Pandoc (setMeta "title" (walk removeNote $ fromList xs)
573− nullMeta) bs
574− _ -> Pandoc nullMeta bs)
575+ (Pandoc (setMeta "title"
576+ (walk removeNote $ fromList xs) nullMeta) bs,
577+ case lookup "epub:type" kvs of
578+ Nothing -> "bodymatter"
579+ Just x
580+ | x `elem` frontMatterTypes -> "frontmatter"
581+ | x `elem` backMatterTypes -> "backmatter"
582+ | otherwise -> "bodymatter")
583+ _ -> (Pandoc nullMeta bs, "bodymatter")
584+ frontMatterTypes = ["prologue", "abstract", "acknowledgments",
585+ "copyright-page", "dedication",
586+ "foreword", "halftitle",
587+ "introduction", "preface",
588+ "seriespage", "titlepage"]
589+ backMatterTypes = ["afterword", "appendix", "colophon",
590+ "conclusion", "epigraph"]
575591
576592 chapterEntries <- zipWithM chapToEntry [1..] chapters
577593