@@ -1,6 +1,5 @@
11{-# LANGUAGE NoImplicitPrelude #-}
22{-# LANGUAGE CPP #-}
3−{-# LANGUAGE DeriveGeneric #-}
43{-# LANGUAGE ScopedTypeVariables #-}
54{-# LANGUAGE TupleSections #-}
65#ifdef DERIVE_JSON_VIA_TH
@@ -36,10 +35,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3635Does a pandoc conversion based on command-line options.
3736-}
3837module Text.Pandoc.App.CommandLineOptions (
39− Opt(..)
40− , LineEnding (..)
41− , defaultOpts
42− , parseOptions
38+ parseOptions
4339 , options
4440 , engines
4541 ) where
@@ -51,7 +47,6 @@ import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
5147import Data.Char (toLower, toUpper)
5248import Data.List (intercalate, sort)
5349import Data.Maybe (fromMaybe)
54−import GHC.Generics
5550import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
5651 pygments)
5752import System.Console.GetOpt
@@ -60,19 +55,13 @@ import System.Exit (exitSuccess)
6055import System.FilePath
6156import System.IO (stdout)
6257import Text.Pandoc
58+import Text.Pandoc.App.Opt (Opt (..), LineEnding (..))
6359import Text.Pandoc.Filter (Filter (..))
6460import Text.Pandoc.Highlighting (highlightingStyles)
6561import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
6662import Text.Pandoc.Shared (ordNub, safeRead)
6763import Text.Printf
6864
69−#ifdef DERIVE_JSON_VIA_TH
70−import Data.Aeson.TH (deriveJSON, defaultOptions)
71−#else
72−import Data.Aeson (FromJSON (..), ToJSON (..),
73− defaultOptions, genericToEncoding)
74−#endif
75−
7665#ifdef EMBED_DATA_FILES
7766import Text.Pandoc.Data (dataFiles)
7867import System.Directory (getAppUserDataDirectory)
@@ -88,9 +77,6 @@ import qualified Data.Map as M
8877import qualified Data.Text as T
8978import qualified Text.Pandoc.UTF8 as UTF8
9079
91−-- | The type of line-endings to be used when writing plain-text.
92−data LineEnding = LF | CRLF | Native deriving (Show, Generic)
93−
9480parseOptions :: [OptDescr (Opt -> IO Opt)] -> Opt -> IO Opt
9581parseOptions options' defaults = do
9682 rawArgs <- map UTF8.decodeArg <$> getArgs
@@ -130,152 +116,6 @@ engines = map ("html",) htmlEngines ++
130116pdfEngines :: [String]
131117pdfEngines = ordNub $ map snd engines
132118
133−
134−-- | Data structure for command line options.
135−data Opt = Opt
136− { optTabStop :: Int -- ^ Number of spaces per tab
137− , optPreserveTabs :: Bool -- ^ Preserve tabs instead of converting to spaces
138− , optStandalone :: Bool -- ^ Include header, footer
139− , optReader :: Maybe String -- ^ Reader format
140− , optWriter :: Maybe String -- ^ Writer format
141− , optTableOfContents :: Bool -- ^ Include table of contents
142− , optBaseHeaderLevel :: Int -- ^ Base header level
143− , optTemplate :: Maybe FilePath -- ^ Custom template
144− , optVariables :: [(String,String)] -- ^ Template variables to set
145− , optMetadata :: [(String, String)] -- ^ Metadata fields to set
146− , optMetadataFile :: Maybe FilePath -- ^ Name of YAML metadata file
147− , optOutputFile :: Maybe FilePath -- ^ Name of output file
148− , optInputFiles :: [FilePath] -- ^ Names of input files
149− , optNumberSections :: Bool -- ^ Number sections in LaTeX
150− , optNumberOffset :: [Int] -- ^ Starting number for sections
151− , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
152− , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
153− , optSelfContained :: Bool -- ^ Make HTML accessible offline
154− , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
155− , optHighlightStyle :: Maybe Style -- ^ Style to use for highlighted code
156− , optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
157− , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
158− , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
159− , optAbbreviations :: Maybe FilePath -- ^ Path to abbrevs file
160− , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
161− , optEpubSubdirectory :: String -- ^ EPUB subdir in OCF container
162− , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
163− , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
164− , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
165− , optEpubCoverImage :: Maybe FilePath -- ^ Cover image for epub
166− , optTOCDepth :: Int -- ^ Number of levels to include in TOC
167− , optDumpArgs :: Bool -- ^ Output command-line arguments
168− , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
169− , optVerbosity :: Verbosity -- ^ Verbosity of diagnostic output
170− , optTrace :: Bool -- ^ Enable tracing
171− , optLogFile :: Maybe FilePath -- ^ File to write JSON log output
172− , optFailIfWarnings :: Bool -- ^ Fail on warnings
173− , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
174− , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
175− , optDpi :: Int -- ^ Dpi
176− , optWrapText :: WrapOption -- ^ Options for wrapping text
177− , optColumns :: Int -- ^ Line length in characters
178− , optFilters :: [Filter] -- ^ Filters to apply
179− , optEmailObfuscation :: ObfuscationMethod
180− , optIdentifierPrefix :: String
181− , optStripEmptyParagraphs :: Bool -- ^ Strip empty paragraphs
182− , optIndentedCodeClasses :: [String] -- ^ Default classes for indented code blocks
183− , optDataDir :: Maybe FilePath
184− , optCiteMethod :: CiteMethod -- ^ Method to output cites
185− , optListings :: Bool -- ^ Use listings package for code blocks
186− , optPdfEngine :: Maybe String -- ^ Program to use for latex/html -> pdf
187− , optPdfEngineArgs :: [String] -- ^ Flags to pass to the engine
188− , optSlideLevel :: Maybe Int -- ^ Header level that creates slides
189− , optSetextHeaders :: Bool -- ^ Use atx headers for markdown level 1-2
190− , optAscii :: Bool -- ^ Prefer ascii output
191− , optDefaultImageExtension :: String -- ^ Default image extension
192− , optExtractMedia :: Maybe FilePath -- ^ Path to extract embedded media
193− , optTrackChanges :: TrackChanges -- ^ Accept or reject MS Word track-changes.
194− , optFileScope :: Bool -- ^ Parse input files before combining
195− , optTitlePrefix :: Maybe String -- ^ Prefix for title
196− , optCss :: [FilePath] -- ^ CSS files to link to
197− , optIncludeBeforeBody :: [FilePath] -- ^ Files to include before
198− , optIncludeAfterBody :: [FilePath] -- ^ Files to include after body
199− , optIncludeInHeader :: [FilePath] -- ^ Files to include in header
200− , optResourcePath :: [FilePath] -- ^ Path to search for images etc
201− , optRequestHeaders :: [(String, String)] -- ^ Headers for HTTP requests
202− , optEol :: LineEnding -- ^ Style of line-endings to use
203− , optStripComments :: Bool -- ^ Skip HTML comments
204− } deriving (Generic, Show)
205−
206−-- | Defaults for command-line options.
207−defaultOpts :: Opt
208−defaultOpts = Opt
209− { optTabStop = 4
210− , optPreserveTabs = False
211− , optStandalone = False
212− , optReader = Nothing
213− , optWriter = Nothing
214− , optTableOfContents = False
215− , optBaseHeaderLevel = 1
216− , optTemplate = Nothing
217− , optVariables = []
218− , optMetadata = []
219− , optMetadataFile = Nothing
220− , optOutputFile = Nothing
221− , optInputFiles = []
222− , optNumberSections = False
223− , optNumberOffset = [0,0,0,0,0,0]
224− , optSectionDivs = False
225− , optIncremental = False
226− , optSelfContained = False
227− , optHtmlQTags = False
228− , optHighlightStyle = Just pygments
229− , optSyntaxDefinitions = []
230− , optTopLevelDivision = TopLevelDefault
231− , optHTMLMathMethod = PlainMath
232− , optAbbreviations = Nothing
233− , optReferenceDoc = Nothing
234− , optEpubSubdirectory = "EPUB"
235− , optEpubMetadata = Nothing
236− , optEpubFonts = []
237− , optEpubChapterLevel = 1
238− , optEpubCoverImage = Nothing
239− , optTOCDepth = 3
240− , optDumpArgs = False
241− , optIgnoreArgs = False
242− , optVerbosity = WARNING
243− , optTrace = False
244− , optLogFile = Nothing
245− , optFailIfWarnings = False
246− , optReferenceLinks = False
247− , optReferenceLocation = EndOfDocument
248− , optDpi = 96
249− , optWrapText = WrapAuto
250− , optColumns = 72
251− , optFilters = []
252− , optEmailObfuscation = NoObfuscation
253− , optIdentifierPrefix = ""
254− , optStripEmptyParagraphs = False
255− , optIndentedCodeClasses = []
256− , optDataDir = Nothing
257− , optCiteMethod = Citeproc
258− , optListings = False
259− , optPdfEngine = Nothing
260− , optPdfEngineArgs = []
261− , optSlideLevel = Nothing
262− , optSetextHeaders = True
263− , optAscii = False
264− , optDefaultImageExtension = ""
265− , optExtractMedia = Nothing
266− , optTrackChanges = AcceptChanges
267− , optFileScope = False
268− , optTitlePrefix = Nothing
269− , optCss = []
270− , optIncludeBeforeBody = []
271− , optIncludeAfterBody = []
272− , optIncludeInHeader = []
273− , optResourcePath = ["."]
274− , optRequestHeaders = []
275− , optEol = Native
276− , optStripComments = False
277− }
278−
279119lookupHighlightStyle :: String -> IO (Maybe Style)
280120lookupHighlightStyle s
281121 | takeExtension s == ".theme" = -- attempt to load KDE theme
@@ -1091,18 +931,3 @@ deprecatedOption o msg =
1091931 \r -> case r of
1092932 Right () -> return ()
1093933 Left e -> E.throwIO e
1094−
1095−-- see https://github.com/jgm/pandoc/pull/4083
1096−-- using generic deriving caused long compilation times
1097−#ifdef DERIVE_JSON_VIA_TH
1098−$(deriveJSON defaultOptions ''LineEnding)
1099−$(deriveJSON defaultOptions ''Opt)
1100−#else
1101−instance ToJSON LineEnding where
1102− toEncoding = genericToEncoding defaultOptions
1103−instance FromJSON LineEnding
1104−
1105−instance ToJSON Opt where
1106− toEncoding = genericToEncoding defaultOptions
1107−instance FromJSON Opt
1108−#endif