@@ -20,10 +20,12 @@ module Text.Pandoc.App.CommandLineOptions (
20 parseOptions
20 parseOptions
23+ , lookupHighlightStyle
24import Prelude
25import Prelude
25import Control.Monad
26import Control.Monad
26import Control.Monad.Trans
27import Control.Monad.Trans
28+import Control.Monad.Except (throwError)
27import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
29import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
28 defConfig, Indent(..), NumberFormat(..))
30 defConfig, Indent(..), NumberFormat(..))
29import Data.Char (toLower)
31import Data.Char (toLower)
@@ -34,8 +36,7 @@ import Data.List (isPrefixOf)
36import Data.Maybe (fromMaybe)
38import Data.Maybe (fromMaybe)
37−import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
39+import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
39import System.Console.GetOpt
40import System.Console.GetOpt
40import System.Environment (getArgs, getProgName)
41import System.Environment (getArgs, getProgName)
41import System.Exit (exitSuccess)
42import System.Exit (exitSuccess)
@@ -47,6 +48,7 @@ import Text.Pandoc.Filter (Filter (..))
47import Text.Pandoc.Highlighting (highlightingStyles)
48import Text.Pandoc.Highlighting (highlightingStyles)
48import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
49import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
49import Text.Pandoc.Shared (ordNub, safeRead, defaultUserDataDirs)
50import Text.Pandoc.Shared (ordNub, safeRead, defaultUserDataDirs)
51+import Text.Pandoc.Class (PandocMonad(..), runIOorExplode)
50import Text.Printf
52import Text.Printf
52#ifdef EMBED_DATA_FILES
54#ifdef EMBED_DATA_FILES
@@ -102,20 +104,6 @@ engines = map ("html",) htmlEngines ++
102pdfEngines :: [String]
104pdfEngines :: [String]
103pdfEngines = ordNub $ map snd engines
105pdfEngines = ordNub $ map snd engines
105−lookupHighlightStyle :: String -> IO (Maybe Style)
106−lookupHighlightStyle s
107− | takeExtension s == ".theme" = -- attempt to load KDE theme
108− do contents <- B.readFile s
109− case parseTheme contents of
110− Left _ -> E.throwIO $ PandocOptionError $
111− "Could not read highlighting theme " ++ s
112− Right sty -> return (Just sty)
114− case lookup (map toLower s) highlightingStyles of
115− Just sty -> return (Just sty)
116− Nothing -> E.throwIO $ PandocOptionError $
117− "Unknown highlight-style " ++ s
119-- | A list of functions, each transforming the options data structure
107-- | A list of functions, each transforming the options data structure
120-- in response to a command-line option.
108-- in response to a command-line option.
121options :: [OptDescr (Opt -> IO Opt)]
109options :: [OptDescr (Opt -> IO Opt)]
@@ -296,8 +284,8 @@ options =
297 , Option "" ["highlight-style"]
285 , Option "" ["highlight-style"]
299− (\arg opt -> lookupHighlightStyle arg >>= \style ->
287+ (\arg opt ->
300− return opt{ optHighlightStyle = style })
288+ return opt{ optHighlightStyle = Just arg })
301 "STYLE|FILE")
289 "STYLE|FILE")
302 "" -- "Style for highlighted code"
290 "" -- "Style for highlighted code"
@@ -856,7 +844,7 @@ options =
856 let write = case optOutputFile opt of
844 let write = case optOutputFile opt of
857 Just f -> B.writeFile f
845 Just f -> B.writeFile f
858 Nothing -> B.putStr
846 Nothing -> B.putStr
859− sty <- fromMaybe pygments <$> lookupHighlightStyle arg
847+ sty <- runIOorExplode $ lookupHighlightStyle arg
860 write $ encodePretty'
848 write $ encodePretty'
861 defConfig{confIndent = Spaces 4
849 defConfig{confIndent = Spaces 4
862 ,confCompare = keyOrder
850 ,confCompare = keyOrder
@@ -965,6 +953,20 @@ splitField s =
965 (k,_:v) -> (k,v)
953 (k,_:v) -> (k,v)
966 (k,[]) -> (k,"true")
954 (k,[]) -> (k,"true")
956+lookupHighlightStyle :: PandocMonad m => String -> m Style
957+lookupHighlightStyle s
958+ | takeExtension s == ".theme" = -- attempt to load KDE theme
959+ do contents <- readFileLazy s
960+ case parseTheme contents of
961+ Left _ -> throwError $ PandocOptionError $
962+ "Could not read highlighting theme " ++ s
963+ Right sty -> return sty
965+ case lookup (map toLower s) highlightingStyles of
966+ Just sty -> return sty
967+ Nothing -> throwError $ PandocOptionError $
968+ "Unknown highlight-style " ++ s
968deprecatedOption :: String -> String -> IO ()
970deprecatedOption :: String -> String -> IO ()
969deprecatedOption o msg =
971deprecatedOption o msg =
970 runIO (report $ Deprecated o msg) >>=
972 runIO (report $ Deprecated o msg) >>=