FB2 writer: bring functions to toplevel.

This is the first of a number of changes to bring the FB2 writer a bit
closer to the idioms used elsewhere in pandoc, so it can be more easily
converted to using the pure functions from Free.
This commit is contained in:
Jesse Rosenthal 2016-11-18 06:18:12 -05:00 committed by John MacFarlane
parent 9ac1303660
commit d97fb5f3c6

View file

@ -94,17 +94,19 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
xlink = "http://www.w3.org/1999/xlink" xlink = "http://www.w3.org/1999/xlink"
in [ uattr "xmlns" xmlns in [ uattr "xmlns" xmlns
, attr ("xmlns", "l") xlink ] , attr ("xmlns", "l") xlink ]
--
frontpage :: Meta -> FBM [Content]
frontpage meta' = do frontpage :: Meta -> FBM [Content]
frontpage meta' = do
t <- cMapM toXml . docTitle $ meta' t <- cMapM toXml . docTitle $ meta'
return $ return $
[ el "title" (el "p" t) [ el "title" (el "p" t)
, el "annotation" (map (el "p" . cMap plain) , el "annotation" (map (el "p" . cMap plain)
(docAuthors meta' ++ [docDate meta'])) (docAuthors meta' ++ [docDate meta']))
] ]
description :: Meta -> FBM Content
description meta' = do description :: Meta -> FBM Content
description meta' = do
bt <- booktitle meta' bt <- booktitle meta'
let as = authors meta' let as = authors meta'
dd <- docdate meta' dd <- docdate meta'
@ -112,16 +114,19 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
[ el "title-info" (bt ++ as ++ dd) [ el "title-info" (bt ++ as ++ dd)
, el "document-info" [ el "program-used" "pandoc" ] -- FIXME: +version , el "document-info" [ el "program-used" "pandoc" ] -- FIXME: +version
] ]
booktitle :: Meta -> FBM [Content]
booktitle meta' = do booktitle :: Meta -> FBM [Content]
booktitle meta' = do
t <- cMapM toXml . docTitle $ meta' t <- cMapM toXml . docTitle $ meta'
return $ if null t return $ if null t
then [] then []
else [ el "book-title" t ] else [ el "book-title" t ]
authors :: Meta -> [Content]
authors meta' = cMap author (docAuthors meta') authors :: Meta -> [Content]
author :: [Inline] -> [Content] authors meta' = cMap author (docAuthors meta')
author ss =
author :: [Inline] -> [Content]
author ss =
let ws = words . cMap plain $ ss let ws = words . cMap plain $ ss
email = (el "email") `fmap` (take 1 $ filter ('@' `elem`) ws) email = (el "email") `fmap` (take 1 $ filter ('@' `elem`) ws)
ws' = filter ('@' `notElem`) ws ws' = filter ('@' `notElem`) ws
@ -134,8 +139,9 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
, el "last-name" (last rest) ] , el "last-name" (last rest) ]
([]) -> [] ([]) -> []
in list $ el "author" (names ++ email) in list $ el "author" (names ++ email)
docdate :: Meta -> FBM [Content]
docdate meta' = do docdate :: Meta -> FBM [Content]
docdate meta' = do
let ss = docDate meta' let ss = docDate meta'
d <- cMapM toXml ss d <- cMapM toXml ss
return $ if null d return $ if null d