@@ -44,7 +44,7 @@ import System.Exit ( exitWith, ExitCode (..) )
4444import System.FilePath
4545import System.Console.GetOpt
4646import Data.Char ( toLower )
47−import Data.List ( intercalate, isSuffixOf, isPrefixOf )
47+import Data.List ( intercalate, isPrefixOf )
4848import System.Directory ( getAppUserDataDirectory, doesFileExist, findExecutable )
4949import System.IO ( stdout )
5050import System.IO.Error ( isDoesNotExistError )
@@ -58,7 +58,6 @@ import Network.HTTP (simpleHTTP, mkRequest, getResponseBody, RequestMethod(..))
5858import Network.URI (parseURI, isURI, URI(..))
5959import qualified Data.ByteString.Lazy as B
6060import Data.ByteString.Lazy.UTF8 (toString)
61−import qualified Data.Set as Set
6261import Text.CSL.Reference (Reference(..))
6362#if MIN_VERSION_base(4,4,0)
6463#else
@@ -99,8 +98,8 @@ wrapWords indent c = wrap' (c - indent) (c - indent)
9998 then ",\n" ++ replicate indent ' ' ++ x ++ wrap' cols (cols - length x) xs
10099 else ", " ++ x ++ wrap' cols (remaining - (length x + 2)) xs
101100
102−nonTextFormats :: [String]
103−nonTextFormats = ["odt","docx","epub"]
101+isTextFormat :: String -> Bool
102+isTextFormat s = takeWhile (`notElem` "+-") s `notElem` ["odt","docx","epub"]
104103
105104-- | Data structure for command line options.
106105data Opt = Opt
@@ -133,7 +132,6 @@ data Opt = Opt
133132 , optEPUBFonts :: [FilePath] -- ^ EPUB fonts to embed
134133 , optDumpArgs :: Bool -- ^ Output command-line arguments
135134 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
136− , optStrict :: Bool -- ^ Use strict markdown syntax
137135 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
138136 , optWrapText :: Bool -- ^ Wrap text
139137 , optColumns :: Int -- ^ Line length in characters
@@ -186,7 +184,6 @@ defaultOpts = Opt
186184 , optEPUBFonts = []
187185 , optDumpArgs = False
188186 , optIgnoreArgs = False
189− , optStrict = False
190187 , optReferenceLinks = False
191188 , optWrapText = True
192189 , optColumns = 72
@@ -237,7 +234,10 @@ options =
237234
238235 , Option "" ["strict"]
239236 (NoArg
240− (\opt -> return opt { optStrict = True } ))
237+ (\opt -> do
238+ err 59 $ "The --strict option has been removed.\n" ++
239+ "Use `strict' input or output format instead."
240+ return opt ))
241241 "" -- "Disable markdown syntax extensions"
242242
243243 , Option "R" ["parse-raw"]
@@ -702,7 +702,7 @@ usageMessage :: String -> [OptDescr (Opt -> IO Opt)] -> String
702702usageMessage programName = usageInfo
703703 (programName ++ " [OPTIONS] [FILES]" ++ "\nInput formats: " ++
704704 (wrapWords 16 78 $ readers'names) ++ "\nOutput formats: " ++
705− (wrapWords 16 78 $ writers'names ++ nonTextFormats) ++ "\nOptions:")
705+ (wrapWords 16 78 $ writers'names) ++ "\nOptions:")
706706 where
707707 writers'names = map fst writers
708708 readers'names = map fst readers
@@ -782,9 +782,10 @@ main = do
782782 ["Try " ++ prg ++ " --help for more information."]
783783
784784 let defaultOpts' = if compatMode
785− then defaultOpts { optReader = "markdown"
785+ then defaultOpts { optReader = "strict"
786786 , optWriter = "html"
787− , optStrict = True }
787+ , optEmailObfuscation =
788+ ReferenceObfuscation }
788789 else defaultOpts
789790
790791 -- thread option data structure through all supplied option actions
@@ -819,7 +820,6 @@ main = do
819820 , optEPUBFonts = epubFonts
820821 , optDumpArgs = dumpArgs
821822 , optIgnoreArgs = ignoreArgs
822− , optStrict = strict
823823 , optReferenceLinks = referenceLinks
824824 , optWrapText = wrap
825825 , optColumns = columns
@@ -867,8 +867,8 @@ main = do
867867
868868 let pdfOutput = map toLower (takeExtension outputFile) == ".pdf"
869869
870− let laTeXOutput = writerName' == "latex" || writerName' == "beamer" ||
871− writerName' == "latex+lhs" || writerName' == "beamer+lhs"
870+ let laTeXOutput = "latex" `isPrefixOf` writerName' ||
871+ "beamer" `isPrefixOf` writerName'
872872
873873 when pdfOutput $ do
874874 -- make sure writer is latex or beamer
@@ -882,11 +882,11 @@ main = do
882882 latexEngine ++ " is needed for pdf output."
883883 Just _ -> return ()
884884
885− reader <- case (lookup readerName' readers) of
886− Just r -> return r
887− Nothing -> err 7 ("Unknown reader: " ++ readerName')
885+ reader <- case getReader readerName' of
886+ Right r -> return r
887+ Left e -> err 7 e
888888
889− let standalone' = standalone || writerName' `elem` nonTextFormats || pdfOutput
889+ let standalone' = standalone || not (isTextFormat writerName') || pdfOutput
890890
891891 templ <- case templatePath of
892892 _ | not standalone' -> return ""
@@ -896,8 +896,8 @@ main = do
896896 Left e -> throwIO e
897897 Right t -> return t
898898 Just tp -> do
899− -- strip off "+lhs" if present
900− let format = takeWhile (/='+') writerName'
899+ -- strip off extensions
900+ let format = takeWhile (`notElem` "+-") writerName'
901901 let tp' = case takeExtension tp of
902902 "" -> tp <.> format
903903 _ -> tp
@@ -919,13 +919,13 @@ main = do
919919 return $ ("mathml-script", s) : variables
920920 _ -> return variables
921921
922− variables'' <- case writerName' of
923− "dzslides" -> do
922+ variables'' <- if "dzslides" `isPrefixOf` writerName'
923+ then do
924924 dztempl <- readDataFile datadir $ "dzslides" </> "template.html"
925925 let dzcore = unlines $ dropWhile (not . isPrefixOf "<!-- {{{{ dzslides core")
926926 $ lines dztempl
927927 return $ ("dzslides-core", dzcore) : variables'
928− _ -> return variables'
928+ else return variables'
929929
930930 -- unescape reference ids, which may contain XML entities, so
931931 -- that we can do lookups with regular string equality
@@ -942,13 +942,8 @@ main = do
942942 then "."
943943 else takeDirectory (head sources)
944944
945− let defaultExts = if strict
946− then strictExtensions
947− else pandocExtensions
948−
949− let readerOpts = def{ readerExtensions = defaultExts
950− , readerSmart = smart || (texLigatures &&
951− (laTeXOutput || writerName' == "context"))
945+ let readerOpts = def{ readerSmart = smart || (texLigatures &&
946+ (laTeXOutput || "context" `isPrefixOf` writerName'))
952947 , readerStandalone = standalone'
953948 , readerParseRaw = parseRaw
954949 , readerColumns = columns
@@ -972,13 +967,10 @@ main = do
972967 writerIgnoreNotes = False,
973968 writerNumberSections = numberSections,
974969 writerSectionDivs = sectionDivs,
975− writerExtensions = defaultExts,
976970 writerReferenceLinks = referenceLinks,
977971 writerWrapText = wrap,
978972 writerColumns = columns,
979− writerEmailObfuscation = if strict
980− then ReferenceObfuscation
981− else obfuscationMethod,
973+ writerEmailObfuscation = obfuscationMethod,
982974 writerIdentifierPrefix = idPrefix,
983975 writerSourceDirectory = sourceDir,
984976 writerUserDataDir = datadir,
@@ -997,7 +989,7 @@ main = do
997989 writerReferenceDocx = referenceDocx
998990 }
999991
1000− when (writerName' `elem` nonTextFormats&& outputFile == "-") $
992+ when (not (isTextFormat writerName') && outputFile == "-") $
1001993 err 5 $ "Cannot write " ++ writerName' ++ " output to stdout.\n" ++
1002994 "Specify an output file using the -o option."
1003995
@@ -1022,7 +1014,7 @@ main = do
10221014
10231015 let doc0 = foldr ($) doc transforms
10241016
1025− doc1 <- if writerName' == "rtf"
1017+ doc1 <- if "rtf" `isPrefixOf` writerName'
10261018 then bottomUpM rtfEmbedImage doc0
10271019 else return doc0
10281020
@@ -1050,12 +1042,11 @@ main = do
10501042 writerFn "-" = UTF8.putStr
10511043 writerFn f = UTF8.writeFile f
10521044
1053− let mbwriter = lookup writerName' writers
1054− case mbwriter of
1055− Nothing -> err 9 ("Unknown writer: " ++ writerName')
1056− Just (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile
1057− Just (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary
1058− Just (PureStringWriter f)
1045+ case getWriter writerName' of
1046+ Left e -> err 9 e
1047+ Right (IOStringWriter f) -> f writerOptions doc2 >>= writerFn outputFile
1048+ Right (IOByteStringWriter f) -> f writerOptions doc2 >>= writeBinary
1049+ Right (PureStringWriter f)
10591050 | pdfOutput -> do
10601051 res <- tex2pdf latexEngine $ f writerOptions doc2
10611052 case res of