git.iko.soy/typeable/pandoc
on master help sign in
Opt: Change optHighlightStyle to a Maybe String instead of Maybe Style.
3ef0cddJohn MacFarlane
src/Text/Pandoc/App/CommandLineOptions.hs+21−19
@@ -20,10 +20,12 @@ module Text.Pandoc.App.CommandLineOptions (
20 parseOptions
20 parseOptions
21 , options
21 , options
22 , engines
22 , engines
23+ , lookupHighlightStyle
23 ) where
24 ) where
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)
34#endif
36#endif
35#endif
37#endif
36import Data.Maybe (fromMaybe)
38import Data.Maybe (fromMaybe)
37−import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme,
39+import Skylighting (Style, Syntax (..), defaultSyntaxMap, parseTheme)
38− pygments)
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
51
53
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
104
106
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−
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 =
296
284
297 , Option "" ["highlight-style"]
285 , Option "" ["highlight-style"]
298 (ReqArg
286 (ReqArg
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"
303
291
@@ -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")
967
955
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+
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) >>=
src/Text/Pandoc/App/Opt.hs+2−3
@@ -23,7 +23,6 @@ module Text.Pandoc.App.Opt (
23import Prelude
23import Prelude
24import GHC.Generics
24import GHC.Generics
25import Text.Pandoc.Filter (Filter (..))
25import Text.Pandoc.Filter (Filter (..))
26−import Text.Pandoc.Highlighting (Style, pygments)
27import Text.Pandoc.Logging (Verbosity (WARNING))
26import Text.Pandoc.Logging (Verbosity (WARNING))
28import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
27import Text.Pandoc.Options (TopLevelDivision (TopLevelDefault),
29 TrackChanges (AcceptChanges),
28 TrackChanges (AcceptChanges),
@@ -63,7 +62,7 @@ data Opt = Opt
63 , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
62 , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
64 , optSelfContained :: Bool -- ^ Make HTML accessible offline
63 , optSelfContained :: Bool -- ^ Make HTML accessible offline
65 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
64 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
66− , optHighlightStyle :: Maybe Style -- ^ Style to use for highlighted code
65+ , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
67 , optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
66 , optSyntaxDefinitions :: [FilePath] -- ^ xml syntax defs to load
68 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
67 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
69 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
68 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
@@ -137,7 +136,7 @@ defaultOpts = Opt
137 , optIncremental = False
136 , optIncremental = False
138 , optSelfContained = False
137 , optSelfContained = False
139 , optHtmlQTags = False
138 , optHtmlQTags = False
140− , optHighlightStyle = Just pygments
139+ , optHighlightStyle = Just "pygments"
141 , optSyntaxDefinitions = []
140 , optSyntaxDefinitions = []
142 , optTopLevelDivision = TopLevelDefault
141 , optTopLevelDivision = TopLevelDefault
143 , optHTMLMathMethod = PlainMath
142 , optHTMLMathMethod = PlainMath
src/Text/Pandoc/App/OutputSettings.hs+5−2
@@ -35,7 +35,7 @@ import System.IO (stdout)
35import Text.Pandoc
35import Text.Pandoc
36import Text.Pandoc.App.FormatHeuristics (formatFromFilePaths)
36import Text.Pandoc.App.FormatHeuristics (formatFromFilePaths)
37import Text.Pandoc.App.Opt (Opt (..))
37import Text.Pandoc.App.Opt (Opt (..))
38−import Text.Pandoc.App.CommandLineOptions (engines)
38+import Text.Pandoc.App.CommandLineOptions (engines, lookupHighlightStyle)
39import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
39import Text.Pandoc.BCP47 (Lang (..), parseBCP47)
40import qualified Text.Pandoc.UTF8 as UTF8
40import qualified Text.Pandoc.UTF8 as UTF8
41
41
@@ -105,6 +105,9 @@ optToOutputSettings opts = do
105 syntaxMap <- foldM addSyntaxMap defaultSyntaxMap
105 syntaxMap <- foldM addSyntaxMap defaultSyntaxMap
106 (optSyntaxDefinitions opts)
106 (optSyntaxDefinitions opts)
107
107
108+ hlStyle <- maybe (return Nothing) (fmap Just . lookupHighlightStyle)
109+ (optHighlightStyle opts)
110+
108 -- note: this reverses the list constructed in option parsing,
111 -- note: this reverses the list constructed in option parsing,
109 -- which in turn was reversed from the command-line order,
112 -- which in turn was reversed from the command-line order,
110 -- so we end up with the correct order in the variable list:
113 -- so we end up with the correct order in the variable list:
@@ -221,7 +224,7 @@ optToOutputSettings opts = do
221 , writerTopLevelDivision = optTopLevelDivision opts
224 , writerTopLevelDivision = optTopLevelDivision opts
222 , writerListings = optListings opts
225 , writerListings = optListings opts
223 , writerSlideLevel = optSlideLevel opts
226 , writerSlideLevel = optSlideLevel opts
224− , writerHighlightStyle = optHighlightStyle opts
227+ , writerHighlightStyle = hlStyle
225 , writerSetextHeaders = optSetextHeaders opts
228 , writerSetextHeaders = optSetextHeaders opts
226 , writerEpubSubdirectory = optEpubSubdirectory opts
229 , writerEpubSubdirectory = optEpubSubdirectory opts
227 , writerEpubMetadata = epubMetadata
230 , writerEpubMetadata = epubMetadata