git.iko.soy/typeable/pandoc
on master help sign in
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.

commitd2ac2900f0936a8eae78b339e940e459120767da authorJesse Rosenthal <jrosenthal@jhu.edu> dateFri 18 Nov 2016, 06:18 (10 years ago) parentcb3c633
1 file changed+53−47
src/Text/Pandoc/Writers/FB2.hs+53−47
src/Text/Pandoc/Writers/FB2.hs+53−47
@@ -94,53 +94,59 @@ writeFB2 opts (Pandoc meta blocks) = flip evalStateT newFB $ do
9494 xlink = "http://www.w3.org/1999/xlink"
9595 in [ uattr "xmlns" xmlns
9696 , attr ("xmlns", "l") xlink ]
97− --
98− frontpage :: Meta -> FBM [Content]
99− frontpage meta' = do
100− t <- cMapM toXml . docTitle $ meta'
101− return $
102− [ el "title" (el "p" t)
103− , el "annotation" (map (el "p" . cMap plain)
104− (docAuthors meta' ++ [docDate meta']))
105− ]
106− description :: Meta -> FBM Content
107− description meta' = do
108− bt <- booktitle meta'
109− let as = authors meta'
110− dd <- docdate meta'
111− return $ el "description"
112− [ el "title-info" (bt ++ as ++ dd)
113− , el "document-info" [ el "program-used" "pandoc" ] -- FIXME: +version
114− ]
115− booktitle :: Meta -> FBM [Content]
116− booktitle meta' = do
117− t <- cMapM toXml . docTitle $ meta'
118− return $ if null t
119− then []
120− else [ el "book-title" t ]
121− authors :: Meta -> [Content]
122− authors meta' = cMap author (docAuthors meta')
123− author :: [Inline] -> [Content]
124− author ss =
125− let ws = words . cMap plain $ ss
126− email = (el "email") `fmap` (take 1 $ filter ('@' `elem`) ws)
127− ws' = filter ('@' `notElem`) ws
128− names = case ws' of
129− (nickname:[]) -> [ el "nickname" nickname ]
130− (fname:lname:[]) -> [ el "first-name" fname
131− , el "last-name" lname ]
132− (fname:rest) -> [ el "first-name" fname
133− , el "middle-name" (concat . init $ rest)
134− , el "last-name" (last rest) ]
135− ([]) -> []
136− in list $ el "author" (names ++ email)
137− docdate :: Meta -> FBM [Content]
138− docdate meta' = do
139− let ss = docDate meta'
140− d <- cMapM toXml ss
141− return $ if null d
142− then []
143− else [el "date" d]
97+
98+
99+frontpage :: Meta -> FBM [Content]
100+frontpage meta' = do
101+ t <- cMapM toXml . docTitle $ meta'
102+ return $
103+ [ el "title" (el "p" t)
104+ , el "annotation" (map (el "p" . cMap plain)
105+ (docAuthors meta' ++ [docDate meta']))
106+ ]
107+
108+description :: Meta -> FBM Content
109+description meta' = do
110+ bt <- booktitle meta'
111+ let as = authors meta'
112+ dd <- docdate meta'
113+ return $ el "description"
114+ [ el "title-info" (bt ++ as ++ dd)
115+ , el "document-info" [ el "program-used" "pandoc" ] -- FIXME: +version
116+ ]
117+
118+booktitle :: Meta -> FBM [Content]
119+booktitle meta' = do
120+ t <- cMapM toXml . docTitle $ meta'
121+ return $ if null t
122+ then []
123+ else [ el "book-title" t ]
124+
125+authors :: Meta -> [Content]
126+authors meta' = cMap author (docAuthors meta')
127+
128+author :: [Inline] -> [Content]
129+author ss =
130+ let ws = words . cMap plain $ ss
131+ email = (el "email") `fmap` (take 1 $ filter ('@' `elem`) ws)
132+ ws' = filter ('@' `notElem`) ws
133+ names = case ws' of
134+ (nickname:[]) -> [ el "nickname" nickname ]
135+ (fname:lname:[]) -> [ el "first-name" fname
136+ , el "last-name" lname ]
137+ (fname:rest) -> [ el "first-name" fname
138+ , el "middle-name" (concat . init $ rest)
139+ , el "last-name" (last rest) ]
140+ ([]) -> []
141+ in list $ el "author" (names ++ email)
142+
143+docdate :: Meta -> FBM [Content]
144+docdate meta' = do
145+ let ss = docDate meta'
146+ d <- cMapM toXml ss
147+ return $ if null d
148+ then []
149+ else [el "date" d]
144150
145151-- | Divide the stream of blocks into sections and convert to XML
146152-- representation.