git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1099 from hdevalence/master
3c4aa01John MacFarlane
pandoc.hs+3−5
@@ -656,7 +656,7 @@ options =
656 (ReqArg
656 (ReqArg
657 (\arg opt -> do
657 (\arg opt -> do
658 let b = takeBaseName arg
658 let b = takeBaseName arg
659− if (b == "pdflatex" || b == "lualatex" || b == "xelatex")
659+ if b `elem` ["pdflatex", "lualatex", "xelatex"]
660 then return opt { optLaTeXEngine = arg }
660 then return opt { optLaTeXEngine = arg }
661 else err 45 "latex-engine must be pdflatex, lualatex, or xelatex.")
661 else err 45 "latex-engine must be pdflatex, lualatex, or xelatex.")
662 "PROGRAM")
662 "PROGRAM")
@@ -1034,12 +1034,10 @@ main = do
1034
1034
1035 variables' <- case mathMethod of
1035 variables' <- case mathMethod of
1036 LaTeXMathML Nothing -> do
1036 LaTeXMathML Nothing -> do
1037− s <- readDataFileUTF8 datadir
1037+ s <- readDataFileUTF8 datadir "LaTeXMathML.js"
1038− ("LaTeXMathML.js")
1039 return $ ("mathml-script", s) : variables
1038 return $ ("mathml-script", s) : variables
1040 MathML Nothing -> do
1039 MathML Nothing -> do
1041− s <- readDataFileUTF8 datadir
1040+ s <- readDataFileUTF8 datadir "MathMLinHTML.js"
1042− ("MathMLinHTML.js")
1043 return $ ("mathml-script", s) : variables
1041 return $ ("mathml-script", s) : variables
1044 _ -> return variables
1042 _ -> return variables
1045
1043
src/Text/Pandoc/PDF.hs+2−1
@@ -41,6 +41,7 @@ import System.Directory
41import System.Environment
41import System.Environment
42import Control.Monad (unless)
42import Control.Monad (unless)
43import Data.List (isInfixOf)
43import Data.List (isInfixOf)
44+import Data.Maybe (fromMaybe)
44import qualified Data.ByteString.Base64 as B64
45import qualified Data.ByteString.Base64 as B64
45import qualified Text.Pandoc.UTF8 as UTF8
46import qualified Text.Pandoc.UTF8 as UTF8
46import Text.Pandoc.Definition
47import Text.Pandoc.Definition
@@ -87,7 +88,7 @@ handleImage' baseURL tmpdir (Image ils (src,tit)) = do
87 res <- fetchItem baseURL src
88 res <- fetchItem baseURL src
88 case res of
89 case res of
89 Right (contents, Just mime) -> do
90 Right (contents, Just mime) -> do
90− let ext = maybe (takeExtension src) id $
91+ let ext = fromMaybe (takeExtension src) $
91 extensionFromMimeType mime
92 extensionFromMimeType mime
92 let basename = UTF8.toString $ B64.encode $ UTF8.fromString src
93 let basename = UTF8.toString $ B64.encode $ UTF8.fromString src
93 let fname = tmpdir </> basename <.> ext
94 let fname = tmpdir </> basename <.> ext
src/Text/Pandoc/Parsing.hs+2−2
@@ -271,7 +271,7 @@ spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
271
271
272-- | Parses a nonspace, nonnewline character.
272-- | Parses a nonspace, nonnewline character.
273nonspaceChar :: Parser [Char] st Char
273nonspaceChar :: Parser [Char] st Char
274−nonspaceChar = satisfy $ \x -> x /= '\t' && x /= '\n' && x /= ' ' && x /= '\r'
274+nonspaceChar = satisfy $ flip notElem ['\t', '\n', ' ', '\r']
275
275
276-- | Skips zero or more spaces or tabs.
276-- | Skips zero or more spaces or tabs.
277skipSpaces :: Parser [Char] st ()
277skipSpaces :: Parser [Char] st ()
@@ -1062,7 +1062,7 @@ doubleQuoteStart :: Parser [Char] ParserState ()
1062doubleQuoteStart = do
1062doubleQuoteStart = do
1063 failIfInQuoteContext InDoubleQuote
1063 failIfInQuoteContext InDoubleQuote
1064 try $ do charOrRef "\"\8220\147"
1064 try $ do charOrRef "\"\8220\147"
1065− notFollowedBy (satisfy (\c -> c == ' ' || c == '\t' || c == '\n'))
1065+ notFollowedBy . satisfy $ flip elem [' ', '\t', '\n']
1066
1066
1067doubleQuoteEnd :: Parser [Char] st ()
1067doubleQuoteEnd :: Parser [Char] st ()
1068doubleQuoteEnd = do
1068doubleQuoteEnd = do
src/Text/Pandoc/Readers/DocBook.hs+4−3
@@ -12,6 +12,7 @@ import Data.Char (isSpace)
12import Control.Monad.State
12import Control.Monad.State
13import Control.Applicative ((<$>))
13import Control.Applicative ((<$>))
14import Data.List (intersperse)
14import Data.List (intersperse)
15+import Data.Maybe (fromMaybe)
15
16
16{-
17{-
17
18
@@ -683,7 +684,7 @@ parseBlock (Elem e) =
683 "lowerroman" -> LowerRoman
684 "lowerroman" -> LowerRoman
684 "upperroman" -> UpperRoman
685 "upperroman" -> UpperRoman
685 _ -> Decimal
686 _ -> Decimal
686− let start = maybe 1 id $
687+ let start = fromMaybe 1 $
687 (attrValue "override" <$> filterElement (named "listitem") e)
688 (attrValue "override" <$> filterElement (named "listitem") e)
688 >>= safeRead
689 >>= safeRead
689 orderedListWith (start,listStyle,DefaultDelim)
690 orderedListWith (start,listStyle,DefaultDelim)
@@ -779,7 +780,7 @@ parseBlock (Elem e) =
779 caption <- case filterChild isCaption e of
780 caption <- case filterChild isCaption e of
780 Just t -> getInlines t
781 Just t -> getInlines t
781 Nothing -> return mempty
782 Nothing -> return mempty
782− let e' = maybe e id $ filterChild (named "tgroup") e
783+ let e' = fromMaybe e $ filterChild (named "tgroup") e
783 let isColspec x = named "colspec" x || named "col" x
784 let isColspec x = named "colspec" x || named "col" x
784 let colspecs = case filterChild (named "colgroup") e' of
785 let colspecs = case filterChild (named "colgroup") e' of
785 Just c -> filterChildren isColspec c
786 Just c -> filterChildren isColspec c
@@ -801,7 +802,7 @@ parseBlock (Elem e) =
801 Just "center" -> AlignCenter
802 Just "center" -> AlignCenter
802 _ -> AlignDefault
803 _ -> AlignDefault
803 let toWidth c = case findAttr (unqual "colwidth") c of
804 let toWidth c = case findAttr (unqual "colwidth") c of
804− Just w -> maybe 0 id
805+ Just w -> fromMaybe 0
805 $ safeRead $ '0': filter (\x ->
806 $ safeRead $ '0': filter (\x ->
806 (x >= '0' && x <= '9')
807 (x >= '0' && x <= '9')
807 || x == '.') w
808 || x == '.') w
src/Text/Pandoc/Readers/HTML.hs+2−2
@@ -207,7 +207,7 @@ pHeader = try $ do
207 let bodyTitle = TagOpen tagtype attr ~== TagOpen "h1" [("class","title")]
207 let bodyTitle = TagOpen tagtype attr ~== TagOpen "h1" [("class","title")]
208 let level = read (drop 1 tagtype)
208 let level = read (drop 1 tagtype)
209 contents <- liftM concat $ manyTill inline (pCloses tagtype <|> eof)
209 contents <- liftM concat $ manyTill inline (pCloses tagtype <|> eof)
210− let ident = maybe "" id $ lookup "id" attr
210+ let ident = fromMaybe "" $ lookup "id" attr
211 let classes = maybe [] words $ lookup "class" attr
211 let classes = maybe [] words $ lookup "class" attr
212 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
212 let keyvals = [(k,v) | (k,v) <- attr, k /= "class", k /= "id"]
213 return $ if bodyTitle
213 return $ if bodyTitle
@@ -257,7 +257,7 @@ pCol = try $ do
257 skipMany pBlank
257 skipMany pBlank
258 return $ case lookup "width" attribs of
258 return $ case lookup "width" attribs of
259 Just x | not (null x) && last x == '%' ->
259 Just x | not (null x) && last x == '%' ->
260− maybe 0.0 id $ safeRead ('0':'.':init x)
260+ fromMaybe 0.0 $ safeRead ('0':'.':init x)
261 _ -> 0.0
261 _ -> 0.0
262
262
263pColgroup :: TagParser [Double]
263pColgroup :: TagParser [Double]
src/Text/Pandoc/Readers/LaTeX.hs+2−3
@@ -874,9 +874,8 @@ verbatimEnv = do
874 (_,r) <- withRaw $ do
874 (_,r) <- withRaw $ do
875 controlSeq "begin"
875 controlSeq "begin"
876 name <- braced
876 name <- braced
877− guard $ name == "verbatim" || name == "Verbatim" ||
877+ guard $ name `elem` ["verbatim", "Verbatim", "lstlisting",
878− name == "lstlisting" || name == "minted" ||
879− name == "alltt"
878+ "minted", "alltt"]
880 verbEnv name
879 verbEnv name
881 rest <- getInput
880 rest <- getInput
882 return (r,rest)
881 return (r,rest)
src/Text/Pandoc/Readers/Markdown.hs+7−7
@@ -730,7 +730,7 @@ listStart = bulletListStart <|> (anyOrderedListStart >> return ())
730listLine :: MarkdownParser String
730listLine :: MarkdownParser String
731listLine = try $ do
731listLine = try $ do
732 notFollowedBy' (do indentSpaces
732 notFollowedBy' (do indentSpaces
733− many (spaceChar)
733+ many spaceChar
734 listStart)
734 listStart)
735 notFollowedBy' $ htmlTag (~== TagClose "div")
735 notFollowedBy' $ htmlTag (~== TagClose "div")
736 chunks <- manyTill
736 chunks <- manyTill
@@ -789,8 +789,8 @@ listItem start = try $ do
789orderedList :: MarkdownParser (F Blocks)
789orderedList :: MarkdownParser (F Blocks)
790orderedList = try $ do
790orderedList = try $ do
791 (start, style, delim) <- lookAhead anyOrderedListStart
791 (start, style, delim) <- lookAhead anyOrderedListStart
792− unless ((style == DefaultStyle || style == Decimal || style == Example) &&
792+ unless (style `elem` [DefaultStyle, Decimal, Example] &&
793− (delim == DefaultDelim || delim == Period)) $
793+ delim `elem` [DefaultDelim, Period]) $
794 guardEnabled Ext_fancy_lists
794 guardEnabled Ext_fancy_lists
795 when (style == Example) $ guardEnabled Ext_example_lists
795 when (style == Example) $ guardEnabled Ext_example_lists
796 items <- fmap sequence $ many1 $ listItem
796 items <- fmap sequence $ many1 $ listItem
@@ -925,8 +925,8 @@ strictHtmlBlock = htmlInBalanced (not . isInlineTag)
925
925
926rawVerbatimBlock :: MarkdownParser String
926rawVerbatimBlock :: MarkdownParser String
927rawVerbatimBlock = try $ do
927rawVerbatimBlock = try $ do
928− (TagOpen tag _, open) <- htmlTag (tagOpen (\t ->
928+ (TagOpen tag _, open) <- htmlTag (tagOpen (flip elem
929− t == "pre" || t == "style" || t == "script")
929+ ["pre", "style", "script"])
930 (const True))
930 (const True))
931 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
931 contents <- manyTill anyChar (htmlTag (~== TagClose tag))
932 return $ open ++ contents ++ renderTags [TagClose tag]
932 return $ open ++ contents ++ renderTags [TagClose tag]
@@ -1722,7 +1722,7 @@ spanHtml = try $ do
1722 guardEnabled Ext_markdown_in_html_blocks
1722 guardEnabled Ext_markdown_in_html_blocks
1723 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "span" [])
1723 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "span" [])
1724 contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose "span"))
1724 contents <- mconcat <$> manyTill inline (htmlTag (~== TagClose "span"))
1725− let ident = maybe "" id $ lookup "id" attrs
1725+ let ident = fromMaybe "" $ lookup "id" attrs
1726 let classes = maybe [] words $ lookup "class" attrs
1726 let classes = maybe [] words $ lookup "class" attrs
1727 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1727 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1728 return $ B.spanWith (ident, classes, keyvals) <$> contents
1728 return $ B.spanWith (ident, classes, keyvals) <$> contents
@@ -1732,7 +1732,7 @@ divHtml = try $ do
1732 guardEnabled Ext_markdown_in_html_blocks
1732 guardEnabled Ext_markdown_in_html_blocks
1733 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "div" [])
1733 (TagOpen _ attrs, _) <- htmlTag (~== TagOpen "div" [])
1734 contents <- mconcat <$> manyTill block (htmlTag (~== TagClose "div"))
1734 contents <- mconcat <$> manyTill block (htmlTag (~== TagClose "div"))
1735− let ident = maybe "" id $ lookup "id" attrs
1735+ let ident = fromMaybe "" $ lookup "id" attrs
1736 let classes = maybe [] words $ lookup "class" attrs
1736 let classes = maybe [] words $ lookup "class" attrs
1737 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1737 let keyvals = [(k,v) | (k,v) <- attrs, k /= "id" && k /= "class"]
1738 return $ B.divWith (ident, classes, keyvals) <$> contents
1738 return $ B.divWith (ident, classes, keyvals) <$> contents
src/Text/Pandoc/Readers/MediaWiki.hs+4−3
@@ -54,6 +54,7 @@ import Data.Sequence (viewl, ViewL(..), (<|))
54import qualified Data.Foldable as F
54import qualified Data.Foldable as F
55import qualified Data.Map as M
55import qualified Data.Map as M
56import Data.Char (isDigit, isSpace)
56import Data.Char (isDigit, isSpace)
57+import Data.Maybe (fromMaybe)
57
58
58-- | Read mediawiki from an input string and return a Pandoc document.
59-- | Read mediawiki from an input string and return a Pandoc document.
59readMediaWiki :: ReaderOptions -- ^ Reader options
60readMediaWiki :: ReaderOptions -- ^ Reader options
@@ -204,7 +205,7 @@ table = do
204 tableStart
205 tableStart
205 styles <- option [] parseAttrs <* blankline
206 styles <- option [] parseAttrs <* blankline
206 let tableWidth = case lookup "width" styles of
207 let tableWidth = case lookup "width" styles of
207− Just w -> maybe 1.0 id $ parseWidth w
208+ Just w -> fromMaybe 1.0 $ parseWidth w
208 Nothing -> 1.0
209 Nothing -> 1.0
209 caption <- option mempty tableCaption
210 caption <- option mempty tableCaption
210 optional rowsep
211 optional rowsep
@@ -285,7 +286,7 @@ tableCell = try $ do
285 Just "center" -> AlignCenter
286 Just "center" -> AlignCenter
286 _ -> AlignDefault
287 _ -> AlignDefault
287 let width = case lookup "width" attrs of
288 let width = case lookup "width" attrs of
288− Just xs -> maybe 0.0 id $ parseWidth xs
289+ Just xs -> fromMaybe 0.0 $ parseWidth xs
289 Nothing -> 0.0
290 Nothing -> 0.0
290 return ((align, width), bs)
291 return ((align, width), bs)
291
292
@@ -387,7 +388,7 @@ orderedList =
387 spaces
388 spaces
388 items <- many (listItem '#' <|> li)
389 items <- many (listItem '#' <|> li)
389 optional (htmlTag (~== TagClose "ol"))
390 optional (htmlTag (~== TagClose "ol"))
390− let start = maybe 1 id $ safeRead $ fromAttrib "start" tag
391+ let start = fromMaybe 1 $ safeRead $ fromAttrib "start" tag
391 return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
392 return $ B.orderedListWith (start, DefaultStyle, DefaultDelim) items
392
393
393definitionList :: MWParser Blocks
394definitionList :: MWParser Blocks
src/Text/Pandoc/Readers/Textile.hs+1−1
@@ -594,7 +594,7 @@ surrounded border = enclosed (border *> notFollowedBy (oneOf " \t\n\r")) (try bo
594simpleInline :: Parser [Char] ParserState t -- ^ surrounding parser
594simpleInline :: Parser [Char] ParserState t -- ^ surrounding parser
595 -> ([Inline] -> Inline) -- ^ Inline constructor
595 -> ([Inline] -> Inline) -- ^ Inline constructor
596 -> Parser [Char] ParserState Inline -- ^ content parser (to be used repeatedly)
596 -> Parser [Char] ParserState Inline -- ^ content parser (to be used repeatedly)
597−simpleInline border construct = surrounded border (inlineWithAttribute) >>=
597+simpleInline border construct = surrounded border inlineWithAttribute >>=
598 return . construct . normalizeSpaces
598 return . construct . normalizeSpaces
599 where inlineWithAttribute = (try $ optional attributes) >> inline
599 where inlineWithAttribute = (try $ optional attributes) >> inline
600
600
src/Text/Pandoc/Shared.hs+5−9
@@ -532,7 +532,7 @@ headerShift n = walk shift
532
532
533-- | Detect if a list is tight.
533-- | Detect if a list is tight.
534isTightList :: [[Block]] -> Bool
534isTightList :: [[Block]] -> Bool
535−isTightList = and . map firstIsPlain
535+isTightList = all firstIsPlain
536 where firstIsPlain (Plain _ : _) = True
536 where firstIsPlain (Plain _ : _) = True
537 firstIsPlain _ = False
537 firstIsPlain _ = False
538
538
@@ -564,14 +564,10 @@ makeMeta title authors date =
564-- | Render HTML tags.
564-- | Render HTML tags.
565renderTags' :: [Tag String] -> String
565renderTags' :: [Tag String] -> String
566renderTags' = renderTagsOptions
566renderTags' = renderTagsOptions
567− renderOptions{ optMinimize = \x ->
567+ renderOptions{ optMinimize = matchTags ["hr", "br", "img",
568− let y = map toLower x
569− in y == "hr" || y == "br" ||
570− y == "img" || y == "meta" ||
571− y == "link"
568+ "meta", "link"]
572− , optRawTag = \x ->
573− let y = map toLower x
574− in y == "script" || y == "style" }
569+ , optRawTag = matchTags ["script", "style"] }
570+ where matchTags = \tags -> flip elem tags . map toLower
575
571
576--
572--
577-- File handling
573-- File handling
src/Text/Pandoc/Writers/Docx.hs+4−2
@@ -29,6 +29,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29Conversion of 'Pandoc' documents to docx.
29Conversion of 'Pandoc' documents to docx.
30-}
30-}
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
31module Text.Pandoc.Writers.Docx ( writeDocx ) where
32+import Data.Maybe (fromMaybe)
32import Data.List ( intercalate, groupBy )
33import Data.List ( intercalate, groupBy )
33import qualified Data.ByteString as B
34import qualified Data.ByteString as B
34import qualified Data.ByteString.Lazy as BL
35import qualified Data.ByteString.Lazy as BL
@@ -130,7 +131,8 @@ writeDocx opts doc@(Pandoc meta _) = do
130 let mkOverrideNode (part', contentType') = mknode "Override"
131 let mkOverrideNode (part', contentType') = mknode "Override"
131 [("PartName",part'),("ContentType",contentType')] ()
132 [("PartName",part'),("ContentType",contentType')] ()
132 let mkImageOverride (_, imgpath, mbMimeType, _, _) =
133 let mkImageOverride (_, imgpath, mbMimeType, _, _) =
134+ mkOverrideNode ("/word/" ++ imgpath,
133− mkOverrideNode ("/word/" ++ imgpath, maybe "application/octet-stream" id mbMimeType)
135+ fromMaybe "application/octet-stream" mbMimeType)
134 let overrides = map mkOverrideNode
136 let overrides = map mkOverrideNode
135 [("/word/webSettings.xml",
137 [("/word/webSettings.xml",
136 "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml")
138 "application/vnd.openxmlformats-officedocument.wordprocessingml.webSettings+xml")
@@ -322,7 +324,7 @@ mkNum markers marker numid =
322 NumberMarker _ _ start ->
324 NumberMarker _ _ start ->
323 map (\lvl -> mknode "w:lvlOverride" [("w:ilvl",show (lvl :: Int))]
325 map (\lvl -> mknode "w:lvlOverride" [("w:ilvl",show (lvl :: Int))]
324 $ mknode "w:startOverride" [("w:val",show start)] ()) [0..6]
326 $ mknode "w:startOverride" [("w:val",show start)] ()) [0..6]
325− where absnumid = maybe 0 id $ M.lookup marker markers
327+ where absnumid = fromMaybe 0 $ M.lookup marker markers
326
328
327mkAbstractNum :: (ListMarker,Int) -> IO Element
329mkAbstractNum :: (ListMarker,Int) -> IO Element
328mkAbstractNum (marker,numid) = do
330mkAbstractNum (marker,numid) = do
src/Text/Pandoc/Writers/EPUB.hs+6−6
@@ -176,8 +176,8 @@ addMetadataFromXML e@(Element (QName name _ (Just "dc")) attrs _ _) md
176 , titleFileAs = getAttr "file-as"
176 , titleFileAs = getAttr "file-as"
177 , titleType = getAttr "type"
177 , titleType = getAttr "type"
178 } : epubTitle md }
178 } : epubTitle md }
179− | name == "date" = md{ epubDate = maybe "" id $ normalizeDate'
179+ | name == "date" = md{ epubDate = fromMaybe "" $ normalizeDate'
180− $ strContent e }
180+ $ strContent e }
181 | name == "language" = md{ epubLanguage = strContent e }
181 | name == "language" = md{ epubLanguage = strContent e }
182 | name == "creator" = md{ epubCreator =
182 | name == "creator" = md{ epubCreator =
183 Creator{ creatorText = strContent e
183 Creator{ creatorText = strContent e
@@ -271,7 +271,7 @@ metadataFromMeta opts meta = EPUBMetadata{
271 }
271 }
272 where identifiers = getIdentifier meta
272 where identifiers = getIdentifier meta
273 titles = getTitle meta
273 titles = getTitle meta
274− date = maybe "" id $
274+ date = fromMaybe "" $
275 (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
275 (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
276 language = maybe "" metaValueToString $
276 language = maybe "" metaValueToString $
277 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
277 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
@@ -297,7 +297,7 @@ writeEPUB :: WriterOptions -- ^ Writer options
297 -> Pandoc -- ^ Document to convert
297 -> Pandoc -- ^ Document to convert
298 -> IO B.ByteString
298 -> IO B.ByteString
299writeEPUB opts doc@(Pandoc meta _) = do
299writeEPUB opts doc@(Pandoc meta _) = do
300− let version = maybe EPUB2 id (writerEpubVersion opts)
300+ let version = fromMaybe EPUB2 (writerEpubVersion opts)
301 let epub3 = version == EPUB3
301 let epub3 = version == EPUB3
302 epochtime <- floor `fmap` getPOSIXTime
302 epochtime <- floor `fmap` getPOSIXTime
303 let mkEntry path content = toEntry path epochtime content
303 let mkEntry path content = toEntry path epochtime content
@@ -401,7 +401,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
401 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
401 chapToEntry num (Chapter mbnum bs) = mkEntry (showChapter num)
402 $ renderHtml
402 $ renderHtml
403 $ writeHtml opts'{ writerNumberOffset =
403 $ writeHtml opts'{ writerNumberOffset =
404− maybe [] id mbnum }
404+ fromMaybe [] mbnum }
405 $ case bs of
405 $ case bs of
406 (Header _ _ xs : _) ->
406 (Header _ _ xs : _) ->
407 Pandoc (setMeta "title" (fromList xs) nullMeta) bs
407 Pandoc (setMeta "title" (fromList xs) nullMeta) bs
@@ -436,7 +436,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
436 let fontNode ent = unode "item" !
436 let fontNode ent = unode "item" !
437 [("id", takeBaseName $ eRelativePath ent),
437 [("id", takeBaseName $ eRelativePath ent),
438 ("href", eRelativePath ent),
438 ("href", eRelativePath ent),
439− ("media-type", maybe "" id $ getMimeType $ eRelativePath ent)] $ ()
439+ ("media-type", fromMaybe "" $ getMimeType $ eRelativePath ent)] $ ()
440 let plainTitle = case docTitle meta of
440 let plainTitle = case docTitle meta of
441 [] -> case epubTitle metadata of
441 [] -> case epubTitle metadata of
442 [] -> "UNTITLED"
442 [] -> "UNTITLED"
src/Text/Pandoc/Writers/HTML.hs+3−3
@@ -45,7 +45,7 @@ import Numeric ( showHex )
45import Data.Char ( ord, toLower )
45import Data.Char ( ord, toLower )
46import Data.List ( isPrefixOf, intersperse )
46import Data.List ( isPrefixOf, intersperse )
47import Data.String ( fromString )
47import Data.String ( fromString )
48−import Data.Maybe ( catMaybes )
48+import Data.Maybe ( catMaybes, fromMaybe )
49import Control.Monad.State
49import Control.Monad.State
50import Text.Blaze.Html hiding(contents)
50import Text.Blaze.Html hiding(contents)
51import Text.Blaze.Internal(preEscapedString)
51import Text.Blaze.Internal(preEscapedString)
@@ -118,7 +118,7 @@ pandocToHtml opts (Pandoc meta blocks) = do
118 let stringifyHTML = escapeStringForXML . stringify
118 let stringifyHTML = escapeStringForXML . stringify
119 let authsMeta = map stringifyHTML $ docAuthors meta
119 let authsMeta = map stringifyHTML $ docAuthors meta
120 let dateMeta = stringifyHTML $ docDate meta
120 let dateMeta = stringifyHTML $ docDate meta
121− let slideLevel = maybe (getSlideLevel blocks) id $ writerSlideLevel opts
121+ let slideLevel = fromMaybe (getSlideLevel blocks) $ writerSlideLevel opts
122 let sects = hierarchicalize $
122 let sects = hierarchicalize $
123 if writerSlideVariant opts == NoSlides
123 if writerSlideVariant opts == NoSlides
124 then blocks
124 then blocks
@@ -524,7 +524,7 @@ blockToHtml opts (DefinitionList lst) = do
524 contents <- mapM (\(term, defs) ->
524 contents <- mapM (\(term, defs) ->
525 do term' <- if null term
525 do term' <- if null term
526 then return mempty
526 then return mempty
527− else liftM (H.dt) $ inlineListToHtml opts term
527+ else liftM H.dt $ inlineListToHtml opts term
528 defs' <- mapM ((liftM (\x -> H.dd $ (x >> nl opts))) .
528 defs' <- mapM ((liftM (\x -> H.dd $ (x >> nl opts))) .
529 blockListToHtml opts) defs
529 blockListToHtml opts) defs
530 return $ mconcat $ nl opts : term' : nl opts :
530 return $ mconcat $ nl opts : term' : nl opts :
src/Text/Pandoc/Writers/LaTeX.hs+7−6
@@ -40,6 +40,7 @@ import Network.URI ( isURI, unEscapeString )
40import Data.List ( (\\), isSuffixOf, isInfixOf,
40import Data.List ( (\\), isSuffixOf, isInfixOf,
41 isPrefixOf, intercalate, intersperse )
41 isPrefixOf, intercalate, intersperse )
42import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
42import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
43+import Data.Maybe ( fromMaybe )
43import Control.Applicative ((<|>))
44import Control.Applicative ((<|>))
44import Control.Monad.State
45import Control.Monad.State
45import Text.Pandoc.Pretty
46import Text.Pandoc.Pretty
@@ -190,7 +191,7 @@ stringToLaTeX _ [] = return ""
190stringToLaTeX ctx (x:xs) = do
191stringToLaTeX ctx (x:xs) = do
191 opts <- gets stOptions
192 opts <- gets stOptions
192 rest <- stringToLaTeX ctx xs
193 rest <- stringToLaTeX ctx xs
193− let ligatures = writerTeXLigatures opts && not (ctx == CodeString)
194+ let ligatures = writerTeXLigatures opts && (ctx /= CodeString)
194 let isUrl = ctx == URLString
195 let isUrl = ctx == URLString
195 when (x == '€') $
196 when (x == '€') $
196 modify $ \st -> st{ stUsesEuro = True }
197 modify $ \st -> st{ stUsesEuro = True }
@@ -240,7 +241,7 @@ inCmd cmd contents = char '\\' <> text cmd <> braces contents
240toSlides :: [Block] -> State WriterState [Block]
241toSlides :: [Block] -> State WriterState [Block]
241toSlides bs = do
242toSlides bs = do
242 opts <- gets stOptions
243 opts <- gets stOptions
243− let slideLevel = maybe (getSlideLevel bs) id $ writerSlideLevel opts
244+ let slideLevel = fromMaybe (getSlideLevel bs) $ writerSlideLevel opts
244 let bs' = prepSlides slideLevel bs
245 let bs' = prepSlides slideLevel bs
245 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
246 concat `fmap` (mapM (elementToBeamer slideLevel) $ hierarchicalize bs')
246
247
@@ -443,7 +444,7 @@ blockToLaTeX (DefinitionList lst) = do
443 incremental <- gets stIncremental
444 incremental <- gets stIncremental
444 let inc = if incremental then "[<+->]" else ""
445 let inc = if incremental then "[<+->]" else ""
445 items <- mapM defListItemToLaTeX lst
446 items <- mapM defListItemToLaTeX lst
446− let spacing = if and $ map isTightList (map snd lst)
447+ let spacing = if all isTightList (map snd lst)
447 then text "\\itemsep1pt\\parskip0pt\\parsep0pt"
448 then text "\\itemsep1pt\\parskip0pt\\parsep0pt"
448 else empty
449 else empty
449 return $ text ("\\begin{description}" ++ inc) $$ spacing $$ vcat items $$
450 return $ text ("\\begin{description}" ++ inc) $$ spacing $$ vcat items $$
@@ -764,9 +765,9 @@ citationsToNatbib cits
764 | noPrefix (tail cits) && noSuffix (init cits) && ismode NormalCitation cits
765 | noPrefix (tail cits) && noSuffix (init cits) && ismode NormalCitation cits
765 = citeCommand "citep" p s ks
766 = citeCommand "citep" p s ks
766 where
767 where
767− noPrefix = and . map (null . citationPrefix)
768+ noPrefix = all (null . citationPrefix)
768− noSuffix = and . map (null . citationSuffix)
769+ noSuffix = all (null . citationSuffix)
769− ismode m = and . map (((==) m) . citationMode)
770+ ismode m = all (((==) m) . citationMode)
770 p = citationPrefix $ head $ cits
771 p = citationPrefix $ head $ cits
771 s = citationSuffix $ last $ cits
772 s = citationSuffix $ last $ cits
772 ks = intercalate ", " $ map citationId cits
773 ks = intercalate ", " $ map citationId cits
src/Text/Pandoc/Writers/Markdown.hs+6−5
@@ -338,7 +338,7 @@ blockToMarkdown opts (RawBlock f str)
338 else return $ if isEnabled Ext_markdown_attribute opts
338 else return $ if isEnabled Ext_markdown_attribute opts
339 then text (addMarkdownAttribute str) <> text "\n"
339 then text (addMarkdownAttribute str) <> text "\n"
340 else text str <> text "\n"
340 else text str <> text "\n"
341− | f == "latex" || f == "tex" || f == "markdown" = do
341+ | f `elem` ["latex", "tex", "markdown"] = do
342 st <- get
342 st <- get
343 if stPlain st
343 if stPlain st
344 then return empty
344 then return empty
@@ -628,10 +628,11 @@ getReference label (src, tit) = do
628 Nothing -> do
628 Nothing -> do
629 let label' = case find ((== label) . fst) (stRefs st) of
629 let label' = case find ((== label) . fst) (stRefs st) of
630 Just _ -> -- label is used; generate numerical label
630 Just _ -> -- label is used; generate numerical label
631− case find (\n -> not (any (== [Str (show n)])
631+ case find (\n -> notElem [Str (show n)]
632+ (map fst (stRefs st)))
632− (map fst (stRefs st)))) [1..(10000 :: Integer)] of
633+ [1..(10000 :: Integer)] of
633− Just x -> [Str (show x)]
634+ Just x -> [Str (show x)]
634− Nothing -> error "no unique label"
635+ Nothing -> error "no unique label"
635 Nothing -> label
636 Nothing -> label
636 modify (\s -> s{ stRefs = (label', (src,tit)) : stRefs st })
637 modify (\s -> s{ stRefs = (label', (src,tit)) : stRefs st })
637 return label'
638 return label'
src/Text/Pandoc/Writers/MediaWiki.hs+1−1
@@ -51,7 +51,7 @@ data WriterState = WriterState {
51writeMediaWiki :: WriterOptions -> Pandoc -> String
51writeMediaWiki :: WriterOptions -> Pandoc -> String
52writeMediaWiki opts document =
52writeMediaWiki opts document =
53 evalState (pandocToMediaWiki opts document)
53 evalState (pandocToMediaWiki opts document)
54− (WriterState { stNotes = False, stListLevel = [], stUseTags = False })
54+ WriterState { stNotes = False, stListLevel = [], stUseTags = False }
55
55
56-- | Return MediaWiki representation of document.
56-- | Return MediaWiki representation of document.
57pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
57pandocToMediaWiki :: WriterOptions -> Pandoc -> State WriterState String
src/Text/Pandoc/Writers/ODT.hs+2−1
@@ -31,6 +31,7 @@ Conversion of 'Pandoc' documents to ODT.
31module Text.Pandoc.Writers.ODT ( writeODT ) where
31module Text.Pandoc.Writers.ODT ( writeODT ) where
32import Data.IORef
32import Data.IORef
33import Data.List ( isPrefixOf )
33import Data.List ( isPrefixOf )
34+import Data.Maybe ( fromMaybe )
34import qualified Data.ByteString.Lazy as B
35import qualified Data.ByteString.Lazy as B
35import Text.Pandoc.UTF8 ( fromStringLazy )
36import Text.Pandoc.UTF8 ( fromStringLazy )
36import Codec.Archive.Zip
37import Codec.Archive.Zip
@@ -127,7 +128,7 @@ transformPic opts entriesRef (Image lab (src,_)) = do
127 return $ Emph lab
128 return $ Emph lab
128 Right (img, _) -> do
129 Right (img, _) -> do
129 let size = imageSize img
130 let size = imageSize img
130− let (w,h) = maybe (0,0) id $ sizeInPoints `fmap` size
131+ let (w,h) = fromMaybe (0,0) $ sizeInPoints `fmap` size
131 let tit' = show w ++ "x" ++ show h
132 let tit' = show w ++ "x" ++ show h
132 entries <- readIORef entriesRef
133 entries <- readIORef entriesRef
133 let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src
134 let newsrc = "Pictures/" ++ show (length entries) ++ takeExtension src
src/Text/Pandoc/Writers/Org.hs+1−1
@@ -129,7 +129,7 @@ blockToOrg (Para inlines) = do
129blockToOrg (RawBlock "html" str) =
129blockToOrg (RawBlock "html" str) =
130 return $ blankline $$ "#+BEGIN_HTML" $$
130 return $ blankline $$ "#+BEGIN_HTML" $$
131 nest 2 (text str) $$ "#+END_HTML" $$ blankline
131 nest 2 (text str) $$ "#+END_HTML" $$ blankline
132−blockToOrg (RawBlock f str) | f == "org" || f == "latex" || f == "tex" =
132+blockToOrg (RawBlock f str) | f `elem` ["org", "latex", "tex"] =
133 return $ text str
133 return $ text str
134blockToOrg (RawBlock _ _) = return empty
134blockToOrg (RawBlock _ _) = return empty
135blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
135blockToOrg HorizontalRule = return $ blankline $$ "--------------" $$ blankline
src/Text/Pandoc/Writers/Shared.hs+1−2
@@ -65,8 +65,7 @@ metaToJSON opts blockWriter inlineWriter (Meta metamap)
65 renderedMap <- Traversable.mapM
65 renderedMap <- Traversable.mapM
66 (metaValueToJSON blockWriter inlineWriter)
66 (metaValueToJSON blockWriter inlineWriter)
67 metamap
67 metamap
68− return $ M.foldWithKey (\key val obj -> defField key val obj)
69− baseContext renderedMap
68+ return $ M.foldWithKey defField baseContext renderedMap
70 | otherwise = return (Object H.empty)
69 | otherwise = return (Object H.empty)
71
70
72metaValueToJSON :: Monad m
71metaValueToJSON :: Monad m
src/Text/Pandoc/Writers/Textile.hs+1−1
@@ -51,7 +51,7 @@ data WriterState = WriterState {
51writeTextile :: WriterOptions -> Pandoc -> String
51writeTextile :: WriterOptions -> Pandoc -> String
52writeTextile opts document =
52writeTextile opts document =
53 evalState (pandocToTextile opts document)
53 evalState (pandocToTextile opts document)
54− (WriterState { stNotes = [], stListLevel = [], stUseTags = False })
54+ WriterState { stNotes = [], stListLevel = [], stUseTags = False }
55
55
56-- | Return Textile representation of document.
56-- | Return Textile representation of document.
57pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
57pandocToTextile :: WriterOptions -> Pandoc -> State WriterState String
tests/Tests/Readers/LaTeX.hs+1−1
@@ -21,7 +21,7 @@ tests = [ testGroup "basic"
21 [ "simple" =:
21 [ "simple" =:
22 "word" =?> para "word"
22 "word" =?> para "word"
23 , "space" =:
23 , "space" =:
24− "some text" =?> para ("some text")
24+ "some text" =?> para "some text"
25 , "emphasized" =:
25 , "emphasized" =:
26 "\\emph{emphasized}" =?> para (emph "emphasized")
26 "\\emph{emphasized}" =?> para (emph "emphasized")
27 ]
27 ]
tests/Tests/Readers/Markdown.hs+2−2
@@ -171,13 +171,13 @@ tests = [ testGroup "inline code"
171 , testGroup "smart punctuation"
171 , testGroup "smart punctuation"
172 [ test markdownSmart "quote before ellipses"
172 [ test markdownSmart "quote before ellipses"
173 ("'...hi'"
173 ("'...hi'"
174− =?> para (singleQuoted ("…hi")))
174+ =?> para (singleQuoted "…hi"))
175 , test markdownSmart "apostrophe before emph"
175 , test markdownSmart "apostrophe before emph"
176 ("D'oh! A l'*aide*!"
176 ("D'oh! A l'*aide*!"
177 =?> para ("D’oh! A l’" <> emph "aide" <> "!"))
177 =?> para ("D’oh! A l’" <> emph "aide" <> "!"))
178 , test markdownSmart "apostrophe in French"
178 , test markdownSmart "apostrophe in French"
179 ("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
179 ("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
180− =?> para ("À l’arrivée de la guerre, le thème de l’«impossibilité du socialisme»"))
180+ =?> para "À l’arrivée de la guerre, le thème de l’«impossibilité du socialisme»")
181 ]
181 ]
182 , testGroup "mixed emphasis and strong"
182 , testGroup "mixed emphasis and strong"
183 [ "emph and strong emph alternating" =:
183 [ "emph and strong emph alternating" =:
tests/Tests/Walk.hs+2−2
@@ -21,11 +21,11 @@ tests = [ testGroup "Walk"
21
21
22p_walk :: (Typeable a, Walkable a Pandoc)
22p_walk :: (Typeable a, Walkable a Pandoc)
23 => (a -> a) -> Pandoc -> Bool
23 => (a -> a) -> Pandoc -> Bool
24−p_walk f = (\(d :: Pandoc) -> everywhere (mkT f) d == walk f d)
24+p_walk f d = everywhere (mkT f) d == walk f d
25
25
26p_query :: (Eq a, Typeable a1, Monoid a, Walkable a1 Pandoc)
26p_query :: (Eq a, Typeable a1, Monoid a, Walkable a1 Pandoc)
27 => (a1 -> a) -> Pandoc -> Bool
27 => (a1 -> a) -> Pandoc -> Bool
28−p_query f = (\(d :: Pandoc) -> everything mappend (mempty `mkQ` f) d == query f d)
28+p_query f d = everything mappend (mempty `mkQ` f) d == query f d
29
29
30inlineTrans :: Inline -> Inline
30inlineTrans :: Inline -> Inline
31inlineTrans (Str xs) = Str $ map toUpper xs
31inlineTrans (Str xs) = Str $ map toUpper xs