git.iko.soy/typeable/pandoc
on master help sign in
FB2 writer: convert metadata value "abstract" to book annotation
caeb963Alexander Krotov
src/Text/Pandoc/Writers/FB2.hs+4−1
@@ -118,6 +118,9 @@ description meta' = do
118 bt <- booktitle meta'
118 bt <- booktitle meta'
119 let as = authors meta'
119 let as = authors meta'
120 dd <- docdate meta'
120 dd <- docdate meta'
121+ annotation <- case lookupMeta "abstract" meta' of
122+ Just (MetaBlocks bs) -> (list . el "annotation") <$> cMapM blockToXml bs
123+ _ -> pure mempty
121 let lang = case lookupMeta "lang" meta' of
124 let lang = case lookupMeta "lang" meta' of
122 Just (MetaInlines [Str s]) -> [el "lang" $ iso639 s]
125 Just (MetaInlines [Str s]) -> [el "lang" $ iso639 s]
123 Just (MetaString s) -> [el "lang" $ iso639 s]
126 Just (MetaString s) -> [el "lang" $ iso639 s]
@@ -132,7 +135,7 @@ description meta' = do
132 Just (MetaString s) -> coverimage s
135 Just (MetaString s) -> coverimage s
133 _ -> return []
136 _ -> return []
134 return $ el "description"
137 return $ el "description"
135− [ el "title-info" (genre : (bt ++ as ++ dd ++ lang))
138+ [ el "title-info" (genre : (bt ++ annotation ++ as ++ dd ++ lang))
136 , el "document-info" (el "program-used" "pandoc" : coverpage)
139 , el "document-info" (el "program-used" "pandoc" : coverpage)
137 ]
140 ]
138
141
test/Tests/Old.hs+1
@@ -95,6 +95,7 @@ tests = [ testGroup "markdown"
95 , fb2WriterTest "images" [] "fb2/images.markdown" "fb2/images.fb2"
95 , fb2WriterTest "images" [] "fb2/images.markdown" "fb2/images.fb2"
96 , fb2WriterTest "images-embedded" [] "fb2/images-embedded.html" "fb2/images-embedded.fb2"
96 , fb2WriterTest "images-embedded" [] "fb2/images-embedded.html" "fb2/images-embedded.fb2"
97 , fb2WriterTest "math" [] "fb2/math.markdown" "fb2/math.fb2"
97 , fb2WriterTest "math" [] "fb2/math.markdown" "fb2/math.fb2"
98+ , fb2WriterTest "meta" [] "fb2/meta.markdown" "fb2/meta.fb2"
98 , fb2WriterTest "tables" [] "tables.native" "tables.fb2"
99 , fb2WriterTest "tables" [] "tables.native" "tables.fb2"
99 , fb2WriterTest "testsuite" [] "testsuite.native" "writer.fb2"
100 , fb2WriterTest "testsuite" [] "testsuite.native" "writer.fb2"
100 ]
101 ]
test/fb2/meta.fb2new file+3
@@ -0,0 +1,3 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink"><description><title-info><genre>unrecognised</genre><book-title>Book title</book-title><annotation><p>This is the abstract.</p>It consists of two paragraphs.</annotation></title-info><document-info><program-used>pandoc</program-used></document-info></description><body><title><p>Book title</p></title></body></FictionBook>
3+
test/fb2/meta.markdownnew file+7
@@ -0,0 +1,7 @@
1+---
2+title: Book title
3+abstract: |
4+ This is the abstract.
5+
6+ It consists of two paragraphs.
7+---