@@ -1,4 +1,6 @@
1−{-# LANGUAGE CPP, TupleSections, ScopedTypeVariables #-}
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE ScopedTypeVariables #-}
3+{-# LANGUAGE TupleSections #-}
24{-
35Copyright (C) 2006-2016 John MacFarlane <jgm@berkeley.edu>
46
@@ -35,51 +37,50 @@ module Text.Pandoc.App (
3537 , parseOptions
3638 , options
3739 ) where
38−import Text.Pandoc
39−import Text.Pandoc.Builder (setMeta)
40−import Text.Pandoc.PDF (makePDF)
41−import Text.Pandoc.Walk (walk)
42−import Text.Pandoc.Shared ( tabFilter, readDataFileUTF8,
43− headerShift, err, openURL, safeRead,
44− readDataFile )
45−import Text.Pandoc.MediaBag ( mediaDirectory, extractMediaBag, MediaBag )
46−import Text.Pandoc.XML ( toEntities )
47−import Text.Pandoc.Highlighting (highlightingStyles)
48−import Text.Pandoc.SelfContained ( makeSelfContained )
49−import Text.Pandoc.Process (pipeProcess)
50−import Skylighting ( Style, defaultSyntaxMap, Syntax(..) )
51−import Text.Printf
52−import System.Environment ( getEnvironment, getProgName, getArgs )
5340import Control.Applicative ((<|>))
54−import System.Exit ( ExitCode (..), exitSuccess )
55−import System.FilePath
56−import Data.Char ( toLower, toUpper )
57−import Data.List ( intercalate, isPrefixOf, isSuffixOf, sort )
58−import System.Directory ( getAppUserDataDirectory, findExecutable,
59− doesFileExist, Permissions(..), getPermissions )
60−import System.IO ( stdout, stderr )
61−import System.IO.Error ( isDoesNotExistError )
6241import qualified Control.Exception as E
63−import Control.Exception.Extensible ( throwIO )
64−import qualified Text.Pandoc.UTF8 as UTF8
42+import Control.Exception.Extensible (throwIO)
6543import Control.Monad
6644import Control.Monad.Trans
67−import Data.Maybe (fromMaybe, isNothing, isJust)
68−import Data.Foldable (foldrM)
69−import Network.URI (parseURI, isURI, URI(..))
70−import qualified Data.ByteString.Lazy as B
45+import Data.Aeson (eitherDecode', encode)
7146import qualified Data.ByteString as BS
47+import qualified Data.ByteString.Lazy as B
48+import Data.Char (toLower, toUpper)
49+import Data.Foldable (foldrM)
50+import Data.List (intercalate, isPrefixOf, isSuffixOf, sort)
7251import qualified Data.Map as M
73−import Data.Aeson (eitherDecode', encode)
52+import Data.Maybe (fromMaybe, isJust, isNothing)
53+import qualified Data.Text as T
7454import Data.Yaml (decode)
7555import qualified Data.Yaml as Yaml
76−import qualified Data.Text as T
77−import System.Console.GetOpt
78−import Text.Pandoc.Class (withMediaBag, PandocIO, getLog)
56+import Network.URI (URI (..), isURI, parseURI)
7957import Paths_pandoc (getDataDir)
58+import Skylighting (Style, Syntax (..), defaultSyntaxMap)
59+import System.Console.GetOpt
60+import System.Directory (Permissions (..), doesFileExist, findExecutable,
61+ getAppUserDataDirectory, getPermissions)
62+import System.Environment (getArgs, getEnvironment, getProgName)
63+import System.Exit (ExitCode (..), exitSuccess)
64+import System.FilePath
65+import System.IO (stderr, stdout)
66+import System.IO.Error (isDoesNotExistError)
67+import Text.Pandoc
68+import Text.Pandoc.Builder (setMeta)
69+import Text.Pandoc.Class (PandocIO, getLog, withMediaBag)
70+import Text.Pandoc.Highlighting (highlightingStyles)
71+import Text.Pandoc.MediaBag (MediaBag, extractMediaBag, mediaDirectory)
72+import Text.Pandoc.PDF (makePDF)
73+import Text.Pandoc.Process (pipeProcess)
74+import Text.Pandoc.SelfContained (makeSelfContained)
75+import Text.Pandoc.Shared (err, headerShift, openURL, readDataFile,
76+ readDataFileUTF8, safeRead, tabFilter)
77+import qualified Text.Pandoc.UTF8 as UTF8
78+import Text.Pandoc.Walk (walk)
79+import Text.Pandoc.XML (toEntities)
80+import Text.Printf
8081#ifndef _WINDOWS
81−import System.Posix.Terminal (queryTerminal)
8282import System.Posix.IO (stdOutput)
83+import System.Posix.Terminal (queryTerminal)
8384#endif
8485
8586parseOptions :: [OptDescr (Opt -> IO Opt)] -> Opt -> IO Opt
@@ -119,7 +120,7 @@ convertWithOpts opts = do
119120 let csscdn = "https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css"
120121 let mathMethod =
121122 case (optKaTeXJS opts, optKaTeXStylesheet opts) of
122− (Nothing, _) -> optHTMLMathMethod opts
123+ (Nothing, _) -> optHTMLMathMethod opts
123124 (Just js, ss) -> KaTeX js (fromMaybe csscdn ss)
124125
125126
@@ -151,8 +152,8 @@ convertWithOpts opts = do
151152 Just x -> map toLower x
152153
153154 let writerName = case optWriter opts of
154− Nothing -> defaultWriterName outputFile
155− Just x -> map toLower x
155+ Nothing -> defaultWriterName outputFile
156+ Just x -> map toLower x
156157 let format = takeWhile (`notElem` ['+','-'])
157158 $ takeFileName writerName -- in case path to lua script
158159
@@ -196,13 +197,13 @@ convertWithOpts opts = do
196197 Nothing -> do
197198 deftemp <- getDefaultTemplate datadir format
198199 case deftemp of
199− Left e -> throwIO e
200− Right t -> return (Just t)
200+ Left e -> throwIO e
201+ Right t -> return (Just t)
201202 Just tp -> do
202203 -- strip off extensions
203204 let tp' = case takeExtension tp of
204− "" -> tp <.> format
205− _ -> tp
205+ "" -> tp <.> format
206+ _ -> tp
206207 Just <$> E.catch (UTF8.readFile tp')
207208 (\e -> if isDoesNotExistError e
208209 then E.catch
@@ -221,7 +222,7 @@ convertWithOpts opts = do
221222 -- note: this reverses the list constructed in option parsing,
222223 -- which in turn was reversed from the command-line order,
223224 -- so we end up with the correct order in the variable list:
224− let withList _ [] vars = return vars
225+ let withList _ [] vars = return vars
225226 withList f (x:xs) vars = f x vars >>= withList f xs
226227
227228 variables <-
@@ -352,7 +353,7 @@ convertWithOpts opts = do
352353 rs <- getLog
353354 return (x, rs)
354355 case optLogFile opts of
355− Nothing -> return ()
356+ Nothing -> return ()
356357 Just logfile -> B.writeFile logfile (encodeLogMessages reports)
357358 let isWarning msg = messageVerbosity msg == WARNING
358359 when (optFailIfWarnings opts && any isWarning reports) $
@@ -394,7 +395,7 @@ convertWithOpts opts = do
394395 let pdfprog = case () of
395396 _ | conTeXtOutput -> "context"
396397 _ | html5Output -> "wkhtmltopdf"
397− _ -> optLaTeXEngine opts
398+ _ -> optLaTeXEngine opts
398399 -- check for pdf creating program
399400 mbPdfProg <- liftIO $ findExecutable pdfprog
400401 when (isNothing mbPdfProg) $
@@ -437,7 +438,7 @@ externalFilter f args' d = liftIO $ do
437438 else return True
438439 let (f', args'') = if exists
439440 then case map toLower (takeExtension f) of
440− _ | isExecutable -> ("." </> f, args')
441+ _ | isExecutable -> ("." </> f, args')
441442 ".py" -> ("python", f:args')
442443 ".hs" -> ("runhaskell", f:args')
443444 ".pl" -> ("perl", f:args')
@@ -465,66 +466,66 @@ externalFilter f args' d = liftIO $ do
465466
466467-- | Data structure for command line options.
467468data Opt = Opt
468− { optTabStop :: Int -- ^ Number of spaces per tab
469− , optPreserveTabs :: Bool -- ^ Preserve tabs instead of converting to spaces
470− , optStandalone :: Bool -- ^ Include header, footer
471− , optReader :: Maybe String -- ^ Reader format
472− , optWriter :: Maybe String -- ^ Writer format
473− , optTableOfContents :: Bool -- ^ Include table of contents
474− , optBaseHeaderLevel :: Int -- ^ Base header level
475− , optTemplate :: Maybe FilePath -- ^ Custom template
476− , optVariables :: [(String,String)] -- ^ Template variables to set
477− , optMetadata :: [(String, String)] -- ^ Metadata fields to set
478− , optOutputFile :: FilePath -- ^ Name of output file
479− , optInputFiles :: [FilePath] -- ^ Names of input files
480− , optNumberSections :: Bool -- ^ Number sections in LaTeX
481− , optNumberOffset :: [Int] -- ^ Starting number for sections
482− , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
483− , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
484− , optSelfContained :: Bool -- ^ Make HTML accessible offline
485− , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
486− , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
487− , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
488− , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
489− , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
490− , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
491− , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
492− , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
493− , optEpubCoverImage :: Maybe FilePath -- ^ Cover image for epub
494− , optTOCDepth :: Int -- ^ Number of levels to include in TOC
495− , optDumpArgs :: Bool -- ^ Output command-line arguments
496− , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
497− , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
498− , optLogFile :: Maybe FilePath -- ^ File to write JSON log output
499− , optFailIfWarnings :: Bool -- ^ Fail on warnings
500− , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
501− , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
502− , optDpi :: Int -- ^ Dpi
503− , optWrapText :: WrapOption -- ^ Options for wrapping text
504− , optColumns :: Int -- ^ Line length in characters
505− , optFilters :: [FilePath] -- ^ Filters to apply
506− , optEmailObfuscation :: ObfuscationMethod
507− , optIdentifierPrefix :: String
508− , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
509− , optDataDir :: Maybe FilePath
510− , optCiteMethod :: CiteMethod -- ^ Method to output cites
511− , optListings :: Bool -- ^ Use listings package for code blocks
512− , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
513− , optLaTeXEngineArgs :: [String] -- ^ Flags to pass to the latex-engine
514− , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
515− , optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
516− , optAscii :: Bool -- ^ Use ascii characters only in html
469+ { optTabStop :: Int -- ^ Number of spaces per tab
470+ , optPreserveTabs :: Bool -- ^ Preserve tabs instead of converting to spaces
471+ , optStandalone :: Bool -- ^ Include header, footer
472+ , optReader :: Maybe String -- ^ Reader format
473+ , optWriter :: Maybe String -- ^ Writer format
474+ , optTableOfContents :: Bool -- ^ Include table of contents
475+ , optBaseHeaderLevel :: Int -- ^ Base header level
476+ , optTemplate :: Maybe FilePath -- ^ Custom template
477+ , optVariables :: [(String,String)] -- ^ Template variables to set
478+ , optMetadata :: [(String, String)] -- ^ Metadata fields to set
479+ , optOutputFile :: FilePath -- ^ Name of output file
480+ , optInputFiles :: [FilePath] -- ^ Names of input files
481+ , optNumberSections :: Bool -- ^ Number sections in LaTeX
482+ , optNumberOffset :: [Int] -- ^ Starting number for sections
483+ , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
484+ , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
485+ , optSelfContained :: Bool -- ^ Make HTML accessible offline
486+ , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
487+ , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
488+ , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
489+ , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
490+ , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
491+ , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
492+ , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
493+ , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
494+ , optEpubCoverImage :: Maybe FilePath -- ^ Cover image for epub
495+ , optTOCDepth :: Int -- ^ Number of levels to include in TOC
496+ , optDumpArgs :: Bool -- ^ Output command-line arguments
497+ , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
498+ , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
499+ , optLogFile :: Maybe FilePath -- ^ File to write JSON log output
500+ , optFailIfWarnings :: Bool -- ^ Fail on warnings
501+ , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
502+ , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
503+ , optDpi :: Int -- ^ Dpi
504+ , optWrapText :: WrapOption -- ^ Options for wrapping text
505+ , optColumns :: Int -- ^ Line length in characters
506+ , optFilters :: [FilePath] -- ^ Filters to apply
507+ , optEmailObfuscation :: ObfuscationMethod
508+ , optIdentifierPrefix :: String
509+ , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
510+ , optDataDir :: Maybe FilePath
511+ , optCiteMethod :: CiteMethod -- ^ Method to output cites
512+ , optListings :: Bool -- ^ Use listings package for code blocks
513+ , optLaTeXEngine :: String -- ^ Program to use for latex -> pdf
514+ , optLaTeXEngineArgs :: [String] -- ^ Flags to pass to the latex-engine
515+ , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
516+ , optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
517+ , optAscii :: Bool -- ^ Use ascii characters only in html
517518 , optDefaultImageExtension :: String -- ^ Default image extension
518− , optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
519− , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
520− , optFileScope :: Bool -- ^ Parse input files before combining
521− , optKaTeXStylesheet :: Maybe String -- ^ Path to stylesheet for KaTeX
522− , optKaTeXJS :: Maybe String -- ^ Path to js file for KaTeX
523− , optTitlePrefix :: Maybe String -- ^ Prefix for title
524− , optCss :: [FilePath] -- ^ CSS files to link to
525− , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
526− , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
527− , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
519+ , optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
520+ , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
521+ , optFileScope :: Bool -- ^ Parse input files before combining
522+ , optKaTeXStylesheet :: Maybe String -- ^ Path to stylesheet for KaTeX
523+ , optKaTeXJS :: Maybe String -- ^ Path to js file for KaTeX
524+ , optTitlePrefix :: Maybe String -- ^ Prefix for title
525+ , optCss :: [FilePath] -- ^ CSS files to link to
526+ , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
527+ , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
528+ , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
528529 }
529530
530531-- | Defaults for command-line options.
@@ -675,7 +676,7 @@ defaultWriterName x =
675676 ".icml" -> "icml"
676677 ".tei.xml" -> "tei"
677678 ".tei" -> "tei"
678− ['.',y] | y `elem` ['1'..'9'] -> "man"
679+ ['.',y] | y `elem` ['1'..'9'] -> "man"
679680 _ -> "html"
680681
681682-- Transformations of a Pandoc document post-parsing:
@@ -1210,8 +1211,8 @@ options =
12101211 (OptArg
12111212 (\arg opt -> do
12121213 let url' = case arg of
1213− Just u -> u ++ "?"
1214− Nothing -> "/cgi-bin/mimetex.cgi?"
1214+ Just u -> u ++ "?"
1215+ Nothing -> "/cgi-bin/mimetex.cgi?"
12151216 return opt { optHTMLMathMethod = WebTeX url' })
12161217 "URL")
12171218 "" -- "Use mimetex for HTML math"
@@ -1423,7 +1424,7 @@ handleUnrecognizedOption x =
14231424
14241425uppercaseFirstLetter :: String -> String
14251426uppercaseFirstLetter (c:cs) = toUpper c : cs
1426−uppercaseFirstLetter [] = []
1427+uppercaseFirstLetter [] = []
14271428
14281429readers'names :: [String]
14291430readers'names = sort (map fst (readers :: [(String, Reader PandocIO)]))