git.iko.soy/typeable/pandoc
on master help sign in
More simplification of Opt in pandoc.hs.
commit67f4360fb8b7dbadf8581a8a9a6f133654f91bab authorJohn MacFarlane <jgm@berkeley.edu> dateSat 4 Feb 2017, 22:44 (10 years ago) parent396d304
1 file changed+13−9
pandoc.hs+13−9
pandoc.hs+13−9
@@ -133,7 +133,7 @@ convertWithOpts opts args = do
133133 , optIncremental = incremental
134134 , optSelfContained = selfContained
135135 , optHtmlQTags = htmlQTags
136− , optHighlightStyle = highlightStyle
136+ , optHighlightStyle = mbHighlightStyle
137137 , optTopLevelDivision = topLevelDivision
138138 , optHTMLMathMethod = mathMethod'
139139 , optReferenceDoc = referenceDoc
@@ -309,6 +309,8 @@ convertWithOpts opts args = do
309309 , readerTrackChanges = trackChanges
310310 }
311311
312+ highlightStyle <- lookupHighlightStyle mbHighlightStyle
313+
312314 let writerOptions = def { writerTemplate = templ,
313315 writerVariables = variables'',
314316 writerTabStop = tabStop,
@@ -534,14 +536,14 @@ data Opt = Opt
534536 , optTemplate :: Maybe FilePath -- ^ Custom template
535537 , optVariables :: [(String,String)] -- ^ Template variables to set
536538 , optMetadata :: M.Map String MetaValue -- ^ Metadata fields to set
537− , optOutputFile :: String -- ^ Name of output file
539+ , optOutputFile :: FilePath -- ^ Name of output file
538540 , optNumberSections :: Bool -- ^ Number sections in LaTeX
539541 , optNumberOffset :: [Int] -- ^ Starting number for sections
540542 , optSectionDivs :: Bool -- ^ Put sections in div tags in HTML
541543 , optIncremental :: Bool -- ^ Use incremental lists in Slidy/Slideous/S5
542544 , optSelfContained :: Bool -- ^ Make HTML accessible offline
543545 , optHtmlQTags :: Bool -- ^ Use <q> tags in HTML
544− , optHighlightStyle :: Maybe Style -- ^ Style to use for highlighted code
546+ , optHighlightStyle :: Maybe String -- ^ Style to use for highlighted code
545547 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
546548 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
547549 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
@@ -600,7 +602,7 @@ defaultOpts = Opt
600602 , optIncremental = False
601603 , optSelfContained = False
602604 , optHtmlQTags = False
603− , optHighlightStyle = Just pygments
605+ , optHighlightStyle = Just "pygments"
604606 , optTopLevelDivision = TopLevelDefault
605607 , optHTMLMathMethod = PlainMath
606608 , optReferenceDoc = Nothing
@@ -840,10 +842,7 @@ options =
840842
841843 , Option "" ["highlight-style"]
842844 (ReqArg
843− (\arg opt -> do
844− case lookup (map toLower arg) highlightingStyles of
845− Just s -> return opt{ optHighlightStyle = Just s }
846− Nothing -> err 39 $ "Unknown style: " ++ arg)
845+ (\arg opt -> return opt{ optHighlightStyle = Just arg })
847846 "STYLE")
848847 "" -- "Style for highlighted code"
849848
@@ -1475,4 +1474,9 @@ writerFn :: MonadIO m => FilePath -> String -> m ()
14751474writerFn "-" = liftIO . UTF8.putStr
14761475writerFn f = liftIO . UTF8.writeFile f
14771476
1478−
1477+lookupHighlightStyle :: Maybe String -> IO (Maybe Style)
1478+lookupHighlightStyle Nothing = return Nothing
1479+lookupHighlightStyle (Just s) =
1480+ case lookup (map toLower s) highlightingStyles of
1481+ Just sty -> return (Just sty)
1482+ Nothing -> err 68 $ "Unknown highlight-style " ++ s