git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: set epub:type on body element intelligently.

epub:type of first section epub:type of body -------------------------- ------------------ prologue frontmatter abstract frontmatter acknowledgments frontmatter copyright-page frontmatter dedication frontmatter foreword frontmatter halftitle, frontmatter introduction frontmatter preface frontmatter seriespage frontmatter titlepage frontmatter afterword backmatter appendix backmatter colophon backmatter conclusion backmatter epigraph backmatter Otherwise body will have epub:type 'bodymatter'. This only affects epub3. See http://www.idpf.org/epub/profiles/edu/structure/#h.l0bzsloklt10 Closes #4823.

commit7318bc91ce58bb6c39e556e334f278e590439c3f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 28 Aug 2018, 12:34 (8 years ago) parentdac85d6
2 files changed+23−7
data/templates/default.epub3+1−1 src/Text/Pandoc/Writers/EPUB.hs+22−6
data/templates/default.epub3+1−1
@@ -26,7 +26,7 @@ $for(header-includes)$
2626 $header-includes$
2727$endfor$
2828</head>
29−<body$if(coverpage)$ id="cover"$endif$>
29+<body$if(coverpage)$ id="cover"$endif$$if(body-type)$ epub:type="$body-type$"$endif$>
3030$if(titlepage)$
3131<section epub:type="titlepage">
3232$for(title)$
src/Text/Pandoc/Writers/EPUB.hs+22−6
@@ -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