git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Extract title even from structured title.

Added docTitle'.

commit01b795781280018323e176b9540de7bf3599f9ac authorJohn MacFarlane <jgm@berkeley.edu> dateSun 31 Aug 2014, 14:47 (12 years ago) parent5459b22
1 file changed+21−7
src/Text/Pandoc/Writers/EPUB.hs+21−7
src/Text/Pandoc/Writers/EPUB.hs+21−7
@@ -406,7 +406,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
406406 $ case blocks of
407407 (Header 1 _ _ : _) -> blocks
408408 _ -> Header 1 ("",["unnumbered"],[])
409− (docTitle meta) : blocks
409+ (docTitle' meta) : blocks
410410
411411 let chapterHeaderLevel = writerEpubChapterLevel opts
412412 -- internal reference IDs change when we chunk the file,
@@ -484,7 +484,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
484484 [("id", toId $ eRelativePath ent),
485485 ("href", eRelativePath ent),
486486 ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ ()
487− let plainTitle = case docTitle meta of
487+ let plainTitle = case docTitle' meta of
488488 [] -> case epubTitle metadata of
489489 [] -> "UNTITLED"
490490 (x:_) -> titleText x
@@ -524,9 +524,10 @@ writeEPUB opts doc@(Pandoc meta _) = do
524524 Just _ -> [ unode "itemref" !
525525 [("idref", "cover_xhtml"),("linear","no")] $ () ]
526526 ++ ((unode "itemref" ! [("idref", "title_page_xhtml")
527− ,("linear", if null (docTitle meta)
528− then "no"
529− else "yes")] $ ()) :
527+ ,("linear",
528+ case lookupMeta "title" meta of
529+ Just _ -> "yes"
530+ Nothing -> "no")] $ ()) :
530531 (unode "itemref" ! [("idref", "nav")
531532 ,("linear", if writerTableOfContents opts
532533 then "yes"
@@ -578,7 +579,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
578579 ] ++ subs
579580
580581 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
581− [ unode "navLabel" $ unode "text" (stringify $ docTitle meta)
582+ [ unode "navLabel" $ unode "text" (stringify $ docTitle' meta)
582583 , unode "content" ! [("src","title_page.xhtml")] $ () ]
583584
584585 let tocData = UTF8.fromStringLazy $ ppTopElement $
@@ -597,7 +598,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
597598 Nothing -> []
598599 Just img -> [unode "meta" ! [("name","cover"),
599600 ("content", toId img)] $ ()]
600− , unode "docTitle" $ unode "text" $ plainTitle
601+ , unode "docTitle'" $ unode "text" $ plainTitle
601602 , unode "navMap" $
602603 tpNode : evalState (mapM (navPointNode navMapFormatter) secs) 1
603604 ]
@@ -1192,3 +1193,16 @@ relatorMap =
11921193 ,("writer of added text", "wat")
11931194 ]
11941195
1196+docTitle' :: Meta -> [Inline]
1197+docTitle' meta = fromMaybe [] $ go <$> lookupMeta "title" meta
1198+ where go (MetaString s) = [Str s]
1199+ go (MetaInlines xs) = xs
1200+ go (MetaBlocks [Para xs]) = xs
1201+ go (MetaBlocks [Plain xs]) = xs
1202+ go (MetaMap m) =
1203+ case M.lookup "type" m of
1204+ Just x | stringify x == "main" ->
1205+ maybe [] go $ M.lookup "text" m
1206+ _ -> []
1207+ go (MetaList xs) = concatMap go xs
1208+ go _ = []