@@ -20,10 +20,12 @@ module Text.Pandoc.App.CommandLineOptions (
2020 parseOptions
2121 , options
2222 , engines
23+ , lookupHighlightStyle
2324 ) where
2425import Prelude
2526import Control.Monad
2627import Control.Monad.Trans
28+import Control.Monad.Except (throwError)
2729import Data.Aeson.Encode.Pretty (encodePretty', Config(..), keyOrder,
2830 defConfig, Indent(..), NumberFormat(..))
2931import Data.Char (toLower)
@@ -34,8 +36,7 @@ import Data.List (isPrefixOf)
3436#endif
3537#endif
3638import Data.Maybe (fromMaybe)
37−import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
38− pygments)
39+import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
3940import System.Console.GetOpt
4041import System.Environment (getArgs, getProgName)
4142import System.Exit (exitSuccess)
@@ -47,6 +48,7 @@ import Text.Pandoc.Filter (Filter (..))
4748import Text.Pandoc.Highlighting (highlightingStyles)
4849import Text.Pandoc.Writers.Math (defaultMathJaxURL, defaultKaTeXURL)
4950import Text.Pandoc.Shared (ordNub, safeRead, defaultUserDataDirs)
51+import Text.Pandoc.Class (PandocMonad(..), runIOorExplode)
5052import Text.Printf
5153
5254#ifdef EMBED_DATA_FILES
@@ -102,20 +104,6 @@ engines = map ("html",) htmlEngines ++
102104pdfEngines :: [String]
103105pdfEngines = ordNub $ map snd engines
104106
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)
113− | otherwise =
114− case lookup (map toLower s) highlightingStyles of
115− Just sty -> return (Just sty)
116− Nothing -> E.throwIO $ PandocOptionError $
117− "Unknown highlight-style " ++ s
118−
119107-- | A list of functions, each transforming the options data structure
120108-- in response to a command-line option.
121109options :: [OptDescr (Opt -> IO Opt)]
@@ -296,8 +284,8 @@ options =
296284
297285 , Option "" ["highlight-style"]
298286 (ReqArg
299− (\arg opt -> lookupHighlightStyle arg >>= \style ->
300− return opt{ optHighlightStyle = style })
287+ (\arg opt ->
288+ return opt{ optHighlightStyle = Just arg })
301289 "STYLE|FILE")
302290 "" -- "Style for highlighted code"
303291
@@ -856,7 +844,7 @@ options =
856844 let write = case optOutputFile opt of
857845 Just f -> B.writeFile f
858846 Nothing -> B.putStr
859− sty <- fromMaybe pygments <$> lookupHighlightStyle arg
847+ sty <- runIOorExplode $ lookupHighlightStyle arg
860848 write $ encodePretty'
861849 defConfig{confIndent = Spaces 4
862850 ,confCompare = keyOrder
@@ -965,6 +953,20 @@ splitField s =
965953 (k,_:v) -> (k,v)
966954 (k,[]) -> (k,"true")
967955
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
964+ | otherwise =
965+ case lookup (map toLower s) highlightingStyles of
966+ Just sty -> return sty
967+ Nothing -> throwError $ PandocOptionError $
968+ "Unknown highlight-style " ++ s
969+
968970deprecatedOption :: String -> String -> IO ()
969971deprecatedOption o msg =
970972 runIO (report $ Deprecated o msg) >>=