git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: set epub:type on body element intelligently.
7318bc9John MacFarlane
data/templates/default.epub3+1−1
@@ -26,7 +26,7 @@ $for(header-includes)$
26 $header-includes$
26 $header-includes$
27$endfor$
27$endfor$
28</head>
28</head>
29−<body$if(coverpage)$ id="cover"$endif$>
29+<body$if(coverpage)$ id="cover"$endif$$if(body-type)$ epub:type="$body-type$"$endif$>
30$if(titlepage)$
30$if(titlepage)$
31<section epub:type="titlepage">
31<section epub:type="titlepage">
32$for(title)$
32$for(title)$
src/Text/Pandoc/Writers/EPUB.hs+22−6
@@ -461,6 +461,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
461 -- title page
461 -- title page
462 tpContent <- lift $ writeHtml opts'{
462 tpContent <- lift $ writeHtml opts'{
463 writerVariables = ("titlepage","true"):
463 writerVariables = ("titlepage","true"):
464+ ("body-type", "frontmatter"):
464 ("pagetitle", escapeStringForXML plainTitle):
465 ("pagetitle", escapeStringForXML plainTitle):
465 cssvars True ++ vars }
466 cssvars True ++ vars }
466 (Pandoc meta [])
467 (Pandoc meta [])
@@ -565,13 +566,28 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
565 let chapToEntry num (Chapter mbnum bs) =
566 let chapToEntry num (Chapter mbnum bs) =
566 mkEntry ("text/" ++ showChapter num) =<<
567 mkEntry ("text/" ++ showChapter num) =<<
567 writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum
568 writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum
569+ , writerVariables = ("body-type", bodyType) :
568− , writerVariables = cssvars True ++ vars }
570+ cssvars True ++ vars } pdoc
571+ where (pdoc, bodyType) =
569− (case bs of
572+ case bs of
570− (Header _ _ xs : _) ->
573+ (Header _ (_,_,kvs) xs : _) ->
571 -- remove notes or we get doubled footnotes
574 -- remove notes or we get doubled footnotes
575+ (Pandoc (setMeta "title"
572− Pandoc (setMeta "title" (walk removeNote $ fromList xs)
576+ (walk removeNote $ fromList xs) nullMeta) bs,
573− 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")
574− _ -> Pandoc nullMeta bs)
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"]
575
591
576 chapterEntries <- zipWithM chapToEntry [1..] chapters
592 chapterEntries <- zipWithM chapToEntry [1..] chapters
577
593