@@ -44,7 +44,7 @@ import System.Exit ( exitWith, ExitCode (..) )
44import System.FilePath
44import System.FilePath
45import System.Console.GetOpt
45import System.Console.GetOpt
46import Data.Char ( toLower )
46import Data.Char ( toLower )
47−import Data.List ( intercalate, isSuffixOf, isPrefixOf )
47+import Data.List ( intercalate, isPrefixOf )
48import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
48import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
49import System.IO ( stdout )
49import System.IO ( stdout )
50import System.IO.Error ( isDoesNotExistError )
50import System.IO.Error ( isDoesNotExistError )
@@ -58,7 +58,6 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
58import Network.URI (parseURI, isURI, URI(..))
58import Network.URI (parseURI, isURI, URI(..))
59import qualified Data.ByteString.Lazy as B
59import qualified Data.ByteString.Lazy as B
60import Data.ByteString.Lazy.UTF8 (toString)
60import Data.ByteString.Lazy.UTF8 (toString)
61−import qualified Data.Set as Set
62import Text.CSL.Reference (Reference(..))
61import Text.CSL.Reference (Reference(..))
63#if MIN_VERSION_base(4,4,0)
62#if MIN_VERSION_base(4,4,0)
@@ -99,8 +98,8 @@ wrapWords indent c = wrap' (c - indent) (c - indent)
99 then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
98 then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
100 else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
99 else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
102−nonTextFormats :: [String]
101+isTextFormat :: String -> Bool
103−nonTextFormats = ["odt","docx","epub"]
102+isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub"]
105-- | Data structure for command line options.
104-- | Data structure for command line options.
106data Opt = Opt
105data Opt = Opt
@@ -133,7 +132,6 @@ data Opt = Opt
133 , optEPUBFonts :: [FilePath] -- ^ EPUB fonts to embed
132 , optEPUBFonts :: [FilePath] -- ^ EPUB fonts to embed
134 , optDumpArgs :: Bool -- ^ Output command-line arguments
133 , optDumpArgs :: Bool -- ^ Output command-line arguments
135 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
134 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
136− , optStrict :: Bool -- ^ Use strict markdown syntax
137 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
135 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
138 , optWrapText :: Bool -- ^ Wrap text
136 , optWrapText :: Bool -- ^ Wrap text
139 , optColumns :: Int -- ^ Line length in characters
137 , optColumns :: Int -- ^ Line length in characters
@@ -186,7 +184,6 @@ defaultOpts = Opt
186 , optEPUBFonts = []
184 , optEPUBFonts = []
187 , optDumpArgs = False
185 , optDumpArgs = False
188 , optIgnoreArgs = False
186 , optIgnoreArgs = False
190 , optReferenceLinks = False
187 , optReferenceLinks = False
191 , optWrapText = True
188 , optWrapText = True
192 , optColumns = 72
189 , optColumns = 72
@@ -237,7 +234,10 @@ options =
238 , Option "" ["strict"]
235 , Option "" ["strict"]
238+ err 59 $ "The --strict option has been removed.\n" ++
239+ "Use `strict' input or output format instead."
240− (\opt -> return opt { optStrict = True } ))
240+ return opt ))
241 "" -- "Disable markdown syntax extensions"
241 "" -- "Disable markdown syntax extensions"
243 , Option "R" ["parse-raw"]
243 , Option "R" ["parse-raw"]
@@ -702,7 +702,7 @@ usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
702usageMessage programName = usageInfo
702usageMessage programName = usageInfo
703 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
703 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
704 (wrapWords 16 78 $ readers'names) ++ "\nOutput formats: " ++
704 (wrapWords 16 78 $ readers'names) ++ "\nOutput formats: " ++
705− (wrapWords 16 78 $ writers'names ++ nonTextFormats) ++ "\nOptions:")
705+ (wrapWords 16 78 $ writers'names) ++ "\nOptions:")
707 writers'names = map fst writers
707 writers'names = map fst writers
708 readers'names = map fst readers
708 readers'names = map fst readers
@@ -782,9 +782,10 @@ main = do
782 ["Try " ++ prg ++ " --help for more information."]
782 ["Try " ++ prg ++ " --help for more information."]
784 let defaultOpts' = if compatMode
784 let defaultOpts' = if compatMode
785− then defaultOpts { optReader = "markdown"
785+ then defaultOpts { optReader = "strict"
786 , optWriter = "html"
786 , optWriter = "html"
787− , optStrict = True }
787+ , optEmailObfuscation =
788+ ReferenceObfuscation }
788 else defaultOpts
789 else defaultOpts
790 -- thread option data structure through all supplied option actions
791 -- thread option data structure through all supplied option actions
@@ -819,7 +820,6 @@ main = do
819 , optEPUBFonts = epubFonts
820 , optEPUBFonts = epubFonts
820 , optDumpArgs = dumpArgs
821 , optDumpArgs = dumpArgs
821 , optIgnoreArgs = ignoreArgs
822 , optIgnoreArgs = ignoreArgs
822− , optStrict = strict
823 , optReferenceLinks = referenceLinks
823 , optReferenceLinks = referenceLinks
824 , optWrapText = wrap
824 , optWrapText = wrap
825 , optColumns = columns
825 , optColumns = columns
@@ -867,8 +867,8 @@ main = do
868 let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
868 let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
870− let laTeXOutput = writerName' == "latex" || writerName' == "beamer" ||
870+ let laTeXOutput = "latex" `isPrefixOf` writerName' ||
871− writerName' == "latex+lhs" || writerName' == "beamer+lhs"
871+ "beamer" `isPrefixOf` writerName'
873 when pdfOutput $ do
873 when pdfOutput $ do
874 -- make sure writer is latex or beamer
874 -- make sure writer is latex or beamer
@@ -882,11 +882,11 @@ main = do
882 latexEngine ++ " is needed for pdf output."
882 latexEngine ++ " is needed for pdf output."
883 Just _ -> return ()
883 Just _ -> return ()
885− reader <- case (lookup readerName' readers) of
885+ reader <- case getReader readerName' of
886− Just r -> return r
886+ Right r -> return r
887− Nothing -> err 7 ("Unknown reader: " ++ readerName')
887+ Left e -> err 7 e
889− let standalone' = standalone || writerName' `elem` nonTextFormats || pdfOutput
889+ let standalone' = standalone || not (isTextFormat writerName') || pdfOutput
891 templ <- case templatePath of
891 templ <- case templatePath of
892 _ | not standalone' -> return ""
892 _ | not standalone' -> return ""
@@ -896,8 +896,8 @@ main = do
896 Left e -> throwIO e
896 Left e -> throwIO e
897 Right t -> return t
897 Right t -> return t
898 Just tp -> do
898 Just tp -> do
899− -- strip off "+lhs" if present
899+ -- strip off extensions
900− let format = takeWhile (/='+') writerName'
900+ let format = takeWhile (`notElem` "+-") writerName'
901 let tp' = case takeExtension tp of
901 let tp' = case takeExtension tp of
902 "" -> tp <.> format
902 "" -> tp <.> format
@@ -919,13 +919,13 @@ main = do
919 return $ ("mathml-script", s) : variables
919 return $ ("mathml-script", s) : variables
920 _ -> return variables
920 _ -> return variables
922− variables'' <- case writerName' of
922+ variables'' <- if "dzslides" `isPrefixOf` writerName'
923− "dzslides" -> do
923+ then do
924 dztempl <- readDataFile datadir $ "dzslides" </> "template.html"
924 dztempl <- readDataFile datadir $ "dzslides" </> "template.html"
925 let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
925 let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
926 $ lines dztempl
926 $ lines dztempl
927 return $ ("dzslides-core", dzcore) : variables'
927 return $ ("dzslides-core", dzcore) : variables'
928− _ -> return variables'
928+ else return variables'
930 -- unescape reference ids, which may contain XML entities, so
930 -- unescape reference ids, which may contain XML entities, so
931 -- that we can do lookups with regular string equality
931 -- that we can do lookups with regular string equality
@@ -942,13 +942,8 @@ main = do
943 else takeDirectory (head sources)
943 else takeDirectory (head sources)
945− let defaultExts = if strict
946− then strictExtensions
947− else pandocExtensions
949− let readerOpts = def{ readerExtensions = defaultExts
950− , readerSmart = smart || (texLigatures &&
945+ let readerOpts = def{ readerSmart = smart || (texLigatures &&
951− (laTeXOutput || writerName' == "context"))
946+ (laTeXOutput || "context" `isPrefixOf` writerName'))
952 , readerStandalone = standalone'
947 , readerStandalone = standalone'
953 , readerParseRaw = parseRaw
948 , readerParseRaw = parseRaw
954 , readerColumns = columns
949 , readerColumns = columns
@@ -972,13 +967,10 @@ main = do
972 writerIgnoreNotes = False,
967 writerIgnoreNotes = False,
973 writerNumberSections = numberSections,
968 writerNumberSections = numberSections,
974 writerSectionDivs = sectionDivs,
969 writerSectionDivs = sectionDivs,
975− writerExtensions = defaultExts,
976 writerReferenceLinks = referenceLinks,
970 writerReferenceLinks = referenceLinks,
977 writerWrapText = wrap,
971 writerWrapText = wrap,
978 writerColumns = columns,
972 writerColumns = columns,
979− writerEmailObfuscation = if strict
973+ writerEmailObfuscation = obfuscationMethod,
980− then ReferenceObfuscation
981− else obfuscationMethod,
982 writerIdentifierPrefix = idPrefix,
974 writerIdentifierPrefix = idPrefix,
983 writerSourceDirectory = sourceDir,
975 writerSourceDirectory = sourceDir,
984 writerUserDataDir = datadir,
976 writerUserDataDir = datadir,
@@ -997,7 +989,7 @@ main = do
997 writerReferenceDocx = referenceDocx
989 writerReferenceDocx = referenceDocx
1000− when (writerName' `elem` nonTextFormats&& outputFile == "-") $
992+ when (not (isTextFormat writerName') && outputFile == "-") $
1001 err 5 $ "Cannot write " ++ writerName' ++ " output to stdout.\n" ++
993 err 5 $ "Cannot write " ++ writerName' ++ " output to stdout.\n" ++
1002 "Specify an output file using the -o option."
994 "Specify an output file using the -o option."
@@ -1022,7 +1014,7 @@ main = do
1023 let doc0 = foldr ($) doc transforms
1015 let doc0 = foldr ($) doc transforms
1025− doc1 <- if writerName' == "rtf"
1017+ doc1 <- if "rtf" `isPrefixOf` writerName'
1026 then bottomUpM rtfEmbedImage doc0
1018 then bottomUpM rtfEmbedImage doc0
1027 else return doc0
1019 else return doc0
@@ -1050,12 +1042,11 @@ main = do
1050 writerFn "-" = UTF8.putStr
1042 writerFn "-" = UTF8.putStr
1051 writerFn f = UTF8.writeFile f
1043 writerFn f = UTF8.writeFile f
1053− let mbwriter = lookup writerName' writers
1045+ case getWriter writerName' of
1054− case mbwriter of
1046+ Left e -> err 9 e
1055− Nothing -> err 9 ("Unknown writer: " ++ writerName')
1056− Just (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile
1047+ Right (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile
1057− Just (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary
1048+ Right (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary
1058− Just (PureStringWriter f)
1049+ Right (PureStringWriter f)
1059 | pdfOutput -> do
1050 | pdfOutput -> do
1060 res <- tex2pdf latexEngine $ f writerOptions doc2
1051 res <- tex2pdf latexEngine $ f writerOptions doc2
1061 case res of
1052 case res of