git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #1486 from Aelve/minor

Very minor cleanup and readability changes

commit2de2842bddf06847560f975933837923cba83db1 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 4 Aug 2014, 22:07 (12 years ago) parent39b59b7675b154
13 files changed+123−106
pandoc.hs+52−37 src/Text/Pandoc/Readers/Docx.hs+7−7 src/Text/Pandoc/Readers/Org.hs+1−1 src/Text/Pandoc/Readers/RST.hs+1−4 src/Text/Pandoc/Shared.hs+8−8 src/Text/Pandoc/Writers/AsciiDoc.hs+3−2 src/Text/Pandoc/Writers/Docbook.hs+15−15 src/Text/Pandoc/Writers/EPUB.hs+6−6 src/Text/Pandoc/Writers/FB2.hs+16−16 src/Text/Pandoc/Writers/LaTeX.hs+5−4 src/Text/Pandoc/Writers/Man.hs+3−2 src/Text/Pandoc/Writers/Markdown.hs+3−2 src/Text/Pandoc/Writers/RST.hs+3−2
pandoc.hs+52−37
@@ -57,7 +57,8 @@ import System.IO.Error ( isDoesNotExistError )
5757import qualified Control.Exception as E
5858import Control.Exception.Extensible ( throwIO )
5959import qualified Text.Pandoc.UTF8 as UTF8
60−import Control.Monad (when, unless, liftM, (>=>))
60+import Control.Monad (when, unless, (>=>))
61+import Data.Maybe (isJust)
6162import Data.Foldable (foldrM)
6263import Network.URI (parseURI, isURI, URI(..))
6364import qualified Data.ByteString.Lazy as B
@@ -74,10 +75,13 @@ import Data.Monoid
7475type Transform = Pandoc -> Pandoc
7576
7677copyrightMessage :: String
77−copyrightMessage = "\nCopyright (C) 2006-2014 John MacFarlane\n" ++
78− "Web: http://johnmacfarlane.net/pandoc\n" ++
79− "This is free software; see the source for copying conditions. There is no\n" ++
80− "warranty, not even for merchantability or fitness for a particular purpose."
78+copyrightMessage = unlines [
79+ "",
80+ "Copyright (C) 2006-2014 John MacFarlane",
81+ "Web: http://johnmacfarlane.net/pandoc",
82+ "This is free software; see the source for copying conditions.",
83+ "There is no warranty, not even for merchantability or fitness",
84+ "for a particular purpose." ]
8185
8286compileInfo :: String
8387compileInfo =
@@ -91,15 +95,21 @@ compileInfo =
9195-- comma separated words in lines with a maximum line length.
9296wrapWords :: Int -> Int -> [String] -> String
9397wrapWords indent c = wrap' (c - indent) (c - indent)
94− where wrap' _ _ [] = ""
95− wrap' cols remaining (x:xs) = if remaining == cols
96− then x ++ wrap' cols (remaining - length x) xs
97− else if (length x + 1) > remaining
98− then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
99− else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
98+ where
99+ wrap' _ _ [] = ""
100+ wrap' cols remaining (x:xs)
101+ | remaining == cols =
102+ x ++ wrap' cols (remaining - length x) xs
103+ | (length x + 1) > remaining =
104+ ",\n" ++ replicate indent ' ' ++ x ++
105+ wrap' cols (cols - length x) xs
106+ | otherwise =
107+ ", " ++ x ++
108+ wrap' cols (remaining - length x - 2) xs
100109
101110isTextFormat :: String -> Bool
102−isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub","epub3"]
111+isTextFormat s = takeWhile (`notElem` "+-") s `notElem` binaries
112+ where binaries = ["odt","docx","epub","epub3"]
103113
104114externalFilter :: FilePath -> [String] -> Pandoc -> IO Pandoc
105115externalFilter f args' d = do
@@ -938,7 +948,7 @@ defaultWriterName x =
938948 ".fb2" -> "fb2"
939949 ".opml" -> "opml"
940950 ['.',y] | y `elem` ['1'..'9'] -> "man"
941− _ -> "html"
951+ _ -> "html"
942952
943953-- Transformations of a Pandoc document post-parsing:
944954
@@ -968,7 +978,7 @@ applyFilters filters args d =
968978main :: IO ()
969979main = do
970980
971− rawArgs <- liftM (map UTF8.decodeArg) getArgs
981+ rawArgs <- map UTF8.decodeArg <$> getArgs
972982 prg <- getProgName
973983 let compatMode = (prg == "hsmarkdown")
974984
@@ -1003,7 +1013,7 @@ main = do
10031013 , optTemplate = templatePath
10041014 , optOutputFile = outputFile
10051015 , optNumberSections = numberSections
1006− , optNumberOffset = numberFrom
1016+ , optNumberOffset = numberFrom
10071017 , optSectionDivs = sectionDivs
10081018 , optIncremental = incremental
10091019 , optSelfContained = selfContained
@@ -1051,18 +1061,17 @@ main = do
10511061 exitWith ExitSuccess
10521062
10531063 -- --bibliography implies -F pandoc-citeproc for backwards compatibility:
1054− let filters' = case M.lookup "bibliography" metadata of
1055− Just _ | optCiteMethod opts /= Natbib &&
1056− optCiteMethod opts /= Biblatex &&
1057− all (\f -> takeBaseName f /= "pandoc-citeproc")
1058− filters -> "pandoc-citeproc" : filters
1059− _ -> filters
1064+ let needsCiteproc = isJust (M.lookup "bibliography" metadata) &&
1065+ optCiteMethod opts `notElem` [Natbib, Biblatex] &&
1066+ "pandoc-citeproc" `notElem` map takeBaseName filters
1067+ let filters' = if needsCiteproc then "pandoc-citeproc" : filters
1068+ else filters
10601069
10611070 let sources = if ignoreArgs then [] else args
10621071
10631072 datadir <- case mbDataDir of
10641073 Nothing -> E.catch
1065− (liftM Just $ getAppUserDataDirectory "pandoc")
1074+ (Just <$> getAppUserDataDirectory "pandoc")
10661075 (\e -> let _ = (e :: E.SomeException)
10671076 in return Nothing)
10681077 Just _ -> return mbDataDir
@@ -1093,7 +1102,8 @@ main = do
10931102 else case getWriter writerName' of
10941103 Left e -> err 9 $
10951104 if writerName' == "pdf"
1096− then e ++ "\nTo create a pdf with pandoc, use " ++
1105+ then e ++
1106+ "\nTo create a pdf with pandoc, use " ++
10971107 "the latex or beamer writer and specify\n" ++
10981108 "an output file with .pdf extension " ++
10991109 "(pandoc -t latex -o filename.pdf)."
@@ -1145,20 +1155,22 @@ main = do
11451155 then do
11461156 dztempl <- readDataFileUTF8 datadir
11471157 ("dzslides" </> "template.html")
1148− let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
1149− $ lines dztempl
1158+ let dzline = "<!-- {{{{ dzslides core"
1159+ let dzcore = unlines
1160+ $ dropWhile (not . (dzline `isPrefixOf`))
1161+ $ lines dztempl
11501162 return $ ("dzslides-core", dzcore) : variables'
11511163 else return variables'
11521164
11531165 let sourceURL = case sources of
1154− [] -> Nothing
1155− (x:_) -> case parseURI x of
1156− Just u
1157− | uriScheme u `elem` ["http:","https:"] ->
1158− Just $ show u{ uriPath = "",
1159− uriQuery = "",
1160− uriFragment = "" }
1161− _ -> Nothing
1166+ [] -> Nothing
1167+ (x:_) -> case parseURI x of
1168+ Just u
1169+ | uriScheme u `elem` ["http:","https:"] ->
1170+ Just $ show u{ uriPath = "",
1171+ uriQuery = "",
1172+ uriFragment = "" }
1173+ _ -> Nothing
11621174
11631175 let readerOpts = def{ readerSmart = smart || (texLigatures &&
11641176 (laTeXOutput || "context" `isPrefixOf` writerName'))
@@ -1194,11 +1206,14 @@ main = do
11941206 let readFiles [] = error "Cannot read archive from stdin"
11951207 readFiles (x:_) = B.readFile x
11961208
1197− let convertTabs = tabFilter (if (preserveTabs || readerName' == "t2t") then 0 else tabStop)
1209+ let convertTabs = tabFilter (if preserveTabs || readerName' == "t2t"
1210+ then 0
1211+ else tabStop)
11981212
1199− let handleIncludes' = if readerName' == "latex" || readerName' == "latex+lhs"
1200− then handleIncludes
1201− else return
1213+ let handleIncludes' = if readerName' == "latex" ||
1214+ readerName' == "latex+lhs"
1215+ then handleIncludes
1216+ else return
12021217
12031218 (doc, media) <-
12041219 case reader of
src/Text/Pandoc/Readers/Docx.hs+7−7
@@ -86,7 +86,7 @@ import Text.Pandoc.Readers.Docx.TexChar
8686import Text.Pandoc.Shared
8787import Text.Pandoc.MediaBag (insertMedia, MediaBag)
8888import Data.Maybe (mapMaybe, fromMaybe)
89−import Data.List (delete, isPrefixOf, (\\), intercalate, intersect)
89+import Data.List (delete, stripPrefix, (\\), intercalate, intersect)
9090import Data.Monoid
9191import qualified Data.ByteString.Lazy as B
9292import qualified Data.Map as M
@@ -455,8 +455,8 @@ oMathElemToTexString (LowerLimit base limElems) = do
455455 -- we want to make sure to replace the `\rightarrow` with `\to`
456456 let arrowToTo :: String -> String
457457 arrowToTo "" = ""
458− arrowToTo s | "\\rightarrow" `isPrefixOf` s =
459− "\\to" ++ (arrowToTo $ drop (length "\\rightarrow") s)
458+ arrowToTo s | Just s' <- stripPrefix "\\rightarrow" s =
459+ "\\to" ++ arrowToTo s'
460460 arrowToTo (c:cs) = c : arrowToTo cs
461461 lim' = arrowToTo lim
462462 return $ case baseString of
@@ -470,8 +470,8 @@ oMathElemToTexString (UpperLimit base limElems) = do
470470 -- we want to make sure to replace the `\rightarrow` with `\to`
471471 let arrowToTo :: String -> String
472472 arrowToTo "" = ""
473− arrowToTo s | "\\rightarrow" `isPrefixOf` s =
474− "\\to" ++ (arrowToTo $ drop (length "\\rightarrow") s)
473+ arrowToTo s | Just s' <- stripPrefix "\\rightarrow" s =
474+ "\\to" ++ arrowToTo s'
475475 arrowToTo (c:cs) = c : arrowToTo cs
476476 lim' = arrowToTo lim
477477 return $ case baseString of
@@ -698,8 +698,8 @@ ilToCode Space = " "
698698ilToCode _ = ""
699699
700700isHeaderClass :: String -> Maybe Int
701−isHeaderClass s | "Heading" `isPrefixOf` s =
702− case reads (drop (length "Heading") s) :: [(Int, String)] of
701+isHeaderClass s | Just s' <- stripPrefix "Heading" s =
702+ case reads s' :: [(Int, String)] of
703703 [] -> Nothing
704704 ((n, "") : []) -> Just n
705705 _ -> Nothing
src/Text/Pandoc/Readers/Org.hs+1−1
@@ -274,7 +274,7 @@ optionalAttributes parser = try $
274274parseBlockAttributes :: OrgParser ()
275275parseBlockAttributes = do
276276 attrs <- many attribute
277− () <$ mapM (uncurry parseAndAddAttribute) attrs
277+ mapM_ (uncurry parseAndAddAttribute) attrs
278278 where
279279 attribute :: OrgParser (String, String)
280280 attribute = try $ do
src/Text/Pandoc/Readers/RST.hs+1−4
@@ -47,7 +47,7 @@ import Text.Pandoc.Builder (Inlines, Blocks, trimInlines, (<>))
4747import qualified Text.Pandoc.Builder as B
4848import Data.Monoid (mconcat, mempty)
4949import Data.Sequence (viewr, ViewR(..))
50−import Data.Char (toLower)
50+import Data.Char (toLower, isHexDigit)
5151
5252-- | Parse reStructuredText string and return Pandoc document.
5353readRST :: ReaderOptions -- ^ Reader options
@@ -656,9 +656,6 @@ extractUnicodeChar s = maybe Nothing (\c -> Just (c,rest)) mbc
656656 where (ds,rest) = span isHexDigit s
657657 mbc = safeRead ('\'':'\\':'x':ds ++ "'")
658658
659−isHexDigit :: Char -> Bool
660−isHexDigit c = c `elem` "0123456789ABCDEFabcdef"
661−
662659extractCaption :: RSTParser (Inlines, Blocks)
663660extractCaption = do
664661 capt <- trimInlines . mconcat <$> many inline
src/Text/Pandoc/Shared.hs+8−8
@@ -1,5 +1,5 @@
11{-# LANGUAGE DeriveDataTypeable, CPP, MultiParamTypeClasses,
2− FlexibleContexts, ScopedTypeVariables #-}
2+ FlexibleContexts, ScopedTypeVariables, PatternGuards #-}
33{-
44Copyright (C) 2006-2014 John MacFarlane <jgm@berkeley.edu>
55
@@ -99,7 +99,7 @@ import System.Environment (getProgName)
9999import System.Exit (exitWith, ExitCode(..))
100100import Data.Char ( toLower, isLower, isUpper, isAlpha,
101101 isLetter, isDigit, isSpace )
102−import Data.List ( find, isPrefixOf, intercalate )
102+import Data.List ( find, stripPrefix, intercalate )
103103import qualified Data.Map as M
104104import Network.URI ( escapeURIString, isURI, nonStrictRelativeTo,
105105 unEscapeString, parseURIReference, isAllowedInURI )
@@ -183,9 +183,9 @@ substitute :: (Eq a) => [a] -> [a] -> [a] -> [a]
183183substitute _ _ [] = []
184184substitute [] _ xs = xs
185185substitute target replacement lst@(x:xs) =
186− if target `isPrefixOf` lst
187− then replacement ++ substitute target replacement (drop (length target) lst)
188− else x : substitute target replacement xs
186+ case stripPrefix target lst of
187+ Just lst' -> replacement ++ substitute target replacement lst'
188+ Nothing -> x : substitute target replacement xs
189189
190190ordNub :: (Ord a) => [a] -> [a]
191191ordNub l = go Set.empty l
@@ -808,9 +808,9 @@ fetchItem' media sourceURL s = do
808808-- | Read from a URL and return raw data and maybe mime type.
809809openURL :: String -> IO (Either E.SomeException (BS.ByteString, Maybe String))
810810openURL u
811− | "data:" `isPrefixOf` u =
812− let mime = takeWhile (/=',') $ drop 5 u
813− contents = B8.pack $ unEscapeString $ drop 1 $ dropWhile (/=',') u
811+ | Just u' <- stripPrefix "data:" u =
812+ let mime = takeWhile (/=',') u'
813+ contents = B8.pack $ unEscapeString $ drop 1 $ dropWhile (/=',') u'
814814 in return $ Right (decodeLenient contents, Just mime)
815815#ifdef HTTP_CLIENT
816816 | otherwise = withSocketsDo $ E.try $ do
src/Text/Pandoc/Writers/AsciiDoc.hs+3−2
@@ -43,7 +43,8 @@ import Text.Pandoc.Shared
4343import Text.Pandoc.Writers.Shared
4444import Text.Pandoc.Options
4545import Text.Pandoc.Parsing hiding (blankline, space)
46−import Data.List ( isPrefixOf, intersperse, intercalate )
46+import Data.Maybe (fromMaybe)
47+import Data.List ( stripPrefix, intersperse, intercalate )
4748import Text.Pandoc.Pretty
4849import Control.Monad.State
4950import qualified Data.Map as M
@@ -401,7 +402,7 @@ inlineToAsciiDoc opts (Link txt (src, _tit)) = do
401402 let prefix = if isRelative
402403 then text "link:"
403404 else empty
404− let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
405+ let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
405406 let useAuto = case txt of
406407 [Str s] | escapeURI s == srcSuffix -> True
407408 _ -> False
src/Text/Pandoc/Writers/Docbook.hs+15−15
@@ -1,4 +1,4 @@
1−{-# LANGUAGE OverloadedStrings #-}
1+{-# LANGUAGE OverloadedStrings, PatternGuards #-}
22{-
33Copyright (C) 2006-2014 John MacFarlane <jgm@berkeley.edu>
44
@@ -37,7 +37,7 @@ import Text.Pandoc.Writers.Shared
3737import Text.Pandoc.Options
3838import Text.Pandoc.Templates (renderTemplate')
3939import Text.Pandoc.Readers.TeXMath
40−import Data.List ( isPrefixOf, intercalate, isSuffixOf )
40+import Data.List ( stripPrefix, isPrefixOf, intercalate, isSuffixOf )
4141import Data.Char ( toLower )
4242import Control.Applicative ((<$>))
4343import Data.Monoid ( Any(..) )
@@ -313,19 +313,19 @@ inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
313313 | otherwise = empty
314314inlineToDocbook _ LineBreak = text "\n"
315315inlineToDocbook _ Space = space
316−inlineToDocbook opts (Link txt (src, _)) =
317− if isPrefixOf "mailto:" src
318− then let src' = drop 7 src
319− emailLink = inTagsSimple "email" $ text $
320− escapeStringForXML $ src'
321− in case txt of
322− [Str s] | escapeURI s == src' -> emailLink
323− _ -> inlinesToDocbook opts txt <+>
324− char '(' <> emailLink <> char ')'
325− else (if isPrefixOf "#" src
326− then inTags False "link" [("linkend", drop 1 src)]
327− else inTags False "ulink" [("url", src)]) $
328− inlinesToDocbook opts txt
316+inlineToDocbook opts (Link txt (src, _))
317+ | Just email <- stripPrefix "mailto:" src =
318+ let emailLink = inTagsSimple "email" $ text $
319+ escapeStringForXML $ email
320+ in case txt of
321+ [Str s] | escapeURI s == email -> emailLink
322+ _ -> inlinesToDocbook opts txt <+>
323+ char '(' <> emailLink <> char ')'
324+ | otherwise =
325+ (if isPrefixOf "#" src
326+ then inTags False "link" [("linkend", drop 1 src)]
327+ else inTags False "ulink" [("url", src)]) $
328+ inlinesToDocbook opts txt
329329inlineToDocbook _ (Image _ (src, tit)) =
330330 let titleDoc = if null tit
331331 then empty
src/Text/Pandoc/Writers/EPUB.hs+6−6
@@ -32,7 +32,7 @@ module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
3232import Data.IORef
3333import qualified Data.Map as M
3434import Data.Maybe ( fromMaybe )
35−import Data.List ( isInfixOf, intercalate )
35+import Data.List ( isPrefixOf, isInfixOf, intercalate )
3636import System.Environment ( getEnv )
3737import Text.Printf (printf)
3838import System.FilePath ( (</>), takeExtension, takeFileName )
@@ -825,11 +825,11 @@ ppTopElement = ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++) . unEntity .
825825 unEntity (x:xs) = x : unEntity xs
826826
827827mediaTypeOf :: FilePath -> Maybe String
828−mediaTypeOf x = case getMimeType x of
829− Just y@('i':'m':'a':'g':'e':_) -> Just y
830− Just y@('v':'i':'d':'e':'o':_) -> Just y
831− Just y@('a':'u':'d':'i':'o':_) -> Just y
832− _ -> Nothing
828+mediaTypeOf x =
829+ let mediaPrefixes = ["image", "video", "audio"] in
830+ case getMimeType x of
831+ Just y | any (`isPrefixOf` y) mediaPrefixes -> Just y
832+ _ -> Nothing
833833
834834data IdentState = IdentState{
835835 chapterNumber :: Int,
src/Text/Pandoc/Writers/FB2.hs+16−16
@@ -1,3 +1,5 @@
1+{-# LANGUAGE PatternGuards #-}
2+
13{-
24Copyright (c) 2011-2012, Sergey Astanin
35All rights reserved.
@@ -29,7 +31,7 @@ import Control.Monad.State (StateT, evalStateT, get, modify)
2931import Control.Monad.State (liftM, liftM2, liftIO)
3032import Data.ByteString.Base64 (encode)
3133import Data.Char (toLower, isSpace, isAscii, isControl)
32−import Data.List (intersperse, intercalate, isPrefixOf)
34+import Data.List (intersperse, intercalate, isPrefixOf, stripPrefix)
3335import Data.Either (lefts, rights)
3436import Network.Browser (browse, request, setAllowRedirects, setOutHandler)
3537import Network.HTTP (catchIO_, getRequest, getHeaders, getResponseBody)
@@ -252,22 +254,21 @@ readDataURI :: String -- ^ URI
252254 -> Maybe (String,String,Bool,String)
253255 -- ^ Maybe (mime,charset,isBase64,data)
254256readDataURI uri =
255− let prefix = "data:"
256− in if not (prefix `isPrefixOf` uri)
257− then Nothing
258− else
259− let rest = drop (length prefix) uri
260− meta = takeWhile (/= ',') rest -- without trailing ','
261− uridata = drop (length meta + 1) rest
262− parts = split (== ';') meta
263− (mime,cs,enc)=foldr upd ("text/plain","US-ASCII",False) parts
264− in Just (mime,cs,enc,uridata)
257+ case stripPrefix "data:" uri of
258+ Nothing -> Nothing
259+ Just rest ->
260+ let meta = takeWhile (/= ',') rest -- without trailing ','
261+ uridata = drop (length meta + 1) rest
262+ parts = split (== ';') meta
263+ (mime,cs,enc)=foldr upd ("text/plain","US-ASCII",False) parts
264+ in Just (mime,cs,enc,uridata)
265+
265266 where
266267 upd str m@(mime,cs,enc)
267− | isMimeType str = (str,cs,enc)
268− | "charset=" `isPrefixOf` str = (mime,drop (length "charset=") str,enc)
269− | str == "base64" = (mime,cs,True)
270− | otherwise = m
268+ | isMimeType str = (str,cs,enc)
269+ | Just str' <- stripPrefix "charset=" str = (mime,str',enc)
270+ | str == "base64" = (mime,cs,True)
271+ | otherwise = m
271272
272273-- Without parameters like ;charset=...; see RFC 2045, 5.1
273274isMimeType :: String -> Bool
@@ -295,7 +296,6 @@ fetchURL url = do
295296 let content_type = lookupHeader HdrContentType (getHeaders r)
296297 content <- liftM (Just . toStr . encode . toBS) . getResponseBody $ Right r
297298 return $ liftM2 (,) content_type content
298− where
299299
300300toBS :: String -> B.ByteString
301301toBS = B.pack . map (toEnum . fromEnum)
src/Text/Pandoc/Writers/LaTeX.hs+5−4
@@ -1,4 +1,5 @@
1−{-# LANGUAGE OverloadedStrings, ScopedTypeVariables #-}
1+{-# LANGUAGE OverloadedStrings, ScopedTypeVariables,
2+ PatternGuards #-}
23{-
34Copyright (C) 2006-2014 John MacFarlane <jgm@berkeley.edu>
45
@@ -37,7 +38,7 @@ import Text.Pandoc.Options
3738import Text.Pandoc.Templates
3839import Text.Printf ( printf )
3940import Network.URI ( isURI, unEscapeString )
40−import Data.List ( (\\), isSuffixOf, isInfixOf,
41+import Data.List ( (\\), isSuffixOf, isInfixOf, stripPrefix,
4142 isPrefixOf, intercalate, intersperse )
4243import Data.Char ( toLower, isPunctuation, isAscii, isLetter, isDigit, ord )
4344import Data.Maybe ( fromMaybe )
@@ -761,8 +762,8 @@ inlineToLaTeX (Link txt (src, _)) =
761762 do modify $ \s -> s{ stUrl = True }
762763 src' <- stringToLaTeX URLString src
763764 return $ text $ "\\url{" ++ src' ++ "}"
764− [Str x] | "mailto:" `isPrefixOf` src &&
765− escapeURI x == drop 7 src -> -- email autolink
765+ [Str x] | Just rest <- stripPrefix "mailto:" src,
766+ escapeURI x == rest -> -- email autolink
766767 do modify $ \s -> s{ stUrl = True }
767768 src' <- stringToLaTeX URLString src
768769 contents <- inlineListToLaTeX txt
src/Text/Pandoc/Writers/Man.hs+3−2
@@ -36,7 +36,8 @@ import Text.Pandoc.Writers.Shared
3636import Text.Pandoc.Options
3737import Text.Pandoc.Readers.TeXMath
3838import Text.Printf ( printf )
39−import Data.List ( isPrefixOf, intersperse, intercalate )
39+import Data.List ( stripPrefix, intersperse, intercalate )
40+import Data.Maybe (fromMaybe)
4041import Text.Pandoc.Pretty
4142import Text.Pandoc.Builder (deleteMeta)
4243import Control.Monad.State
@@ -343,7 +344,7 @@ inlineToMan _ (LineBreak) = return $
343344inlineToMan _ Space = return space
344345inlineToMan opts (Link txt (src, _)) = do
345346 linktext <- inlineListToMan opts txt
346− let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
347+ let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
347348 return $ case txt of
348349 [Str s]
349350 | escapeURI s == srcSuffix ->
src/Text/Pandoc/Writers/Markdown.hs+3−2
@@ -38,7 +38,8 @@ import Text.Pandoc.Shared
3838import Text.Pandoc.Writers.Shared
3939import Text.Pandoc.Options
4040import Text.Pandoc.Parsing hiding (blankline, blanklines, char, space)
41−import Data.List ( group, isPrefixOf, find, intersperse, transpose, sortBy )
41+import Data.Maybe (fromMaybe)
42+import Data.List ( group, stripPrefix, find, intersperse, transpose, sortBy )
4243import Data.Char ( isSpace, isPunctuation )
4344import Data.Ord ( comparing )
4445import Text.Pandoc.Pretty
@@ -815,7 +816,7 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
815816 let linktitle = if null tit
816817 then empty
817818 else text $ " \"" ++ tit ++ "\""
818− let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
819+ let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
819820 let useAuto = isURI src &&
820821 case txt of
821822 [Str s] | escapeURI s == srcSuffix -> True
src/Text/Pandoc/Writers/RST.hs+3−2
@@ -37,7 +37,8 @@ import Text.Pandoc.Shared
3737import Text.Pandoc.Writers.Shared
3838import Text.Pandoc.Templates (renderTemplate')
3939import Text.Pandoc.Builder (deleteMeta)
40−import Data.List ( isPrefixOf, intersperse, transpose )
40+import Data.Maybe (fromMaybe)
41+import Data.List ( isPrefixOf, stripPrefix, intersperse, transpose )
4142import Network.URI (isURI)
4243import Text.Pandoc.Pretty
4344import Control.Monad.State
@@ -401,7 +402,7 @@ inlineToRST (Link [Str str] (src, _))
401402 if "mailto:" `isPrefixOf` src
402403 then src == escapeURI ("mailto:" ++ str)
403404 else src == escapeURI str = do
404− let srcSuffix = if isPrefixOf "mailto:" src then drop 7 src else src
405+ let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
405406 return $ text srcSuffix
406407inlineToRST (Link [Image alt (imgsrc,imgtit)] (src, _tit)) = do
407408 label <- registerImage alt (imgsrc,imgtit) (Just src)