aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/FB2.hs
diff options
context:
space:
mode:
authorAlexander Krotov <ilabdsf@gmail.com>2018-04-04 13:45:28 +0300
committerAlexander Krotov <ilabdsf@gmail.com>2018-04-04 14:22:34 +0300
commitff3ed5c9f8ee985bb6026dd10b8c2549782c0296 (patch)
treee180708763a3c415b6c67a17e5e47acd16a4d697 /src/Text/Pandoc/Writers/FB2.hs
parent2388be648227ca041b6d7d6a79ad56f9175dc813 (diff)
downloadpandoc-ff3ed5c9f8ee985bb6026dd10b8c2549782c0296.tar.gz
FB2 writer: allow emphasis and notes in titles
Only <p> and <empty-line /> are allowed in titles, but <p> has the same type as an ordinary paragraphs. Therefore, there is no need to remove emphasis from titles. Also, don't intersperse paragraph with empty lines.
Diffstat (limited to 'src/Text/Pandoc/Writers/FB2.hs')
-rw-r--r--src/Text/Pandoc/Writers/FB2.hs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/FB2.hs b/src/Text/Pandoc/Writers/FB2.hs
index 3f90f47b1..a62cf4524 100644
--- a/src/Text/Pandoc/Writers/FB2.hs
+++ b/src/Text/Pandoc/Writers/FB2.hs
@@ -46,7 +46,7 @@ import Data.ByteString.Base64 (encode)
import qualified Data.ByteString.Char8 as B8
import Data.Char (isAscii, isControl, isSpace, toLower)
import Data.Either (lefts, rights)
-import Data.List (intercalate, intersperse, isPrefixOf, stripPrefix)
+import Data.List (intercalate, isPrefixOf, stripPrefix)
import Data.Text (Text, pack)
import Network.HTTP (urlEncode)
import Text.XML.Light
@@ -180,7 +180,7 @@ renderSection :: PandocMonad m => Int -> ([Inline], [Block]) -> FBM m Content
renderSection level (ttl, body) = do
title <- if null ttl
then return []
- else return . list . el "title" . formatTitle $ ttl
+ else list . el "title" <$> formatTitle ttl
content <- if hasSubsections body
then renderSections (level + 1) body
else cMapM blockToXml body
@@ -189,11 +189,9 @@ renderSection level (ttl, body) = do
hasSubsections = any isHeaderBlock
-- | Only <p> and <empty-line> are allowed within <title> in FB2.
-formatTitle :: [Inline] -> [Content]
+formatTitle :: PandocMonad m => [Inline] -> FBM m [Content]
formatTitle inlines =
- let lns = split isLineBreak inlines
- lns' = map (el "p" . cMap plain) lns
- in intersperse (el "empty-line" ()) lns'
+ cMapM (blockToXml . Para) $ split (== LineBreak) inlines
split :: (a -> Bool) -> [a] -> [[a]]
split _ [] = []