git.iko.soy/typeable/pandoc
on master help sign in
EPUB writer: Use stringify instead of custom plainify.
a7daf29John MacFarlane
src/Text/Pandoc/Writers/EPUB.hs+10−16
@@ -55,7 +55,6 @@ import Control.Monad.State
55import Text.XML.Light hiding (ppTopElement)
55import Text.XML.Light hiding (ppTopElement)
56import Text.Pandoc.UUID
56import Text.Pandoc.UUID
57import Text.Pandoc.Writers.HTML
57import Text.Pandoc.Writers.HTML
58−import Text.Pandoc.Writers.Markdown ( writePlain )
59import Data.Char ( toLower, isDigit, isAlphaNum )
58import Data.Char ( toLower, isDigit, isAlphaNum )
60import Network.URI ( unEscapeString )
59import Network.URI ( unEscapeString )
61import Text.Pandoc.MIME (getMimeType)
60import Text.Pandoc.MIME (getMimeType)
@@ -124,20 +123,15 @@ dcNode = node . dcName
124opfName :: String -> QName
123opfName :: String -> QName
125opfName n = QName n Nothing (Just "opf")
124opfName n = QName n Nothing (Just "opf")
126
125
127−plainify :: [Inline] -> String
128−plainify t =
129− trimr $ writePlain def{ writerStandalone = False }
130− $ Pandoc nullMeta [Plain $ walk removeNote t]
131−
132−removeNote :: Inline -> Inline
133−removeNote (Note _) = Str ""
134−removeNote x = x
135−
136toId :: FilePath -> String
126toId :: FilePath -> String
137toId = map (\x -> if isAlphaNum x || x == '-' || x == '_'
127toId = map (\x -> if isAlphaNum x || x == '-' || x == '_'
138 then x
128 then x
139 else '_') . takeFileName
129 else '_') . takeFileName
140
130
131+removeNote :: Inline -> Inline
132+removeNote (Note _) = Str ""
133+removeNote x = x
134+
141getEPUBMetadata :: WriterOptions -> Meta -> IO EPUBMetadata
135getEPUBMetadata :: WriterOptions -> Meta -> IO EPUBMetadata
142getEPUBMetadata opts meta = do
136getEPUBMetadata opts meta = do
143 let md = metadataFromMeta opts meta
137 let md = metadataFromMeta opts meta
@@ -172,7 +166,7 @@ getEPUBMetadata opts meta = do
172 if any (\c -> creatorRole c == Just "aut") $ epubCreator m
166 if any (\c -> creatorRole c == Just "aut") $ epubCreator m
173 then return m
167 then return m
174 else do
168 else do
175− let authors' = map plainify $ docAuthors meta
169+ let authors' = map stringify $ docAuthors meta
176 let toAuthor name = Creator{ creatorText = name
170 let toAuthor name = Creator{ creatorText = name
177 , creatorRole = Just "aut"
171 , creatorRole = Just "aut"
178 , creatorFileAs = Nothing }
172 , creatorFileAs = Nothing }
@@ -221,8 +215,8 @@ addMetadataFromXML _ md = md
221
215
222metaValueToString :: MetaValue -> String
216metaValueToString :: MetaValue -> String
223metaValueToString (MetaString s) = s
217metaValueToString (MetaString s) = s
224−metaValueToString (MetaInlines ils) = plainify ils
218+metaValueToString (MetaInlines ils) = stringify ils
225−metaValueToString (MetaBlocks bs) = plainify $ query (:[]) bs
219+metaValueToString (MetaBlocks bs) = stringify bs
226metaValueToString (MetaBool b) = show b
220metaValueToString (MetaBool b) = show b
227metaValueToString _ = ""
221metaValueToString _ = ""
228
222
@@ -468,7 +462,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
468 [] -> case epubTitle metadata of
462 [] -> case epubTitle metadata of
469 [] -> "UNTITLED"
463 [] -> "UNTITLED"
470 (x:_) -> titleText x
464 (x:_) -> titleText x
471− x -> plainify x
465+ x -> stringify x
472 let uuid = case epubIdentifier metadata of
466 let uuid = case epubIdentifier metadata of
473 (x:_) -> identifierText x -- use first identifier as UUID
467 (x:_) -> identifierText x -- use first identifier as UUID
474 [] -> error "epubIdentifier is null" -- shouldn't happen
468 [] -> error "epubIdentifier is null" -- shouldn't happen
@@ -535,7 +529,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
535 modify (+1)
529 modify (+1)
536 let showNums :: [Int] -> String
530 let showNums :: [Int] -> String
537 showNums = intercalate "." . map show
531 showNums = intercalate "." . map show
538− let tit' = plainify ils
532+ let tit' = stringify ils
539 let tit = if writerNumberSections opts && not (null nums)
533 let tit = if writerNumberSections opts && not (null nums)
540 then showNums nums ++ " " ++ tit'
534 then showNums nums ++ " " ++ tit'
541 else tit'
535 else tit'
@@ -558,7 +552,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
558 ] ++ subs
552 ] ++ subs
559
553
560 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
554 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
561− [ unode "navLabel" $ unode "text" (plainify $ docTitle meta)
555+ [ unode "navLabel" $ unode "text" (stringify $ docTitle meta)
562 , unode "content" ! [("src","title_page.xhtml")] $ () ]
556 , unode "content" ! [("src","title_page.xhtml")] $ () ]
563
557
564 let tocData = UTF8.fromStringLazy $ ppTopElement $
558 let tocData = UTF8.fromStringLazy $ ppTopElement $