diff options
| author | Albert Krewinkel <[email protected]> | 2022-10-05 12:13:32 +0200 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-10-08 16:05:48 -0700 |
| commit | 429606d5da6e2438f7f634f307ef33f795f7aa43 (patch) | |
| tree | 5895c2e43012b9d5b8afa71ff90c01dc28b63d3d /src | |
| parent | 3cbf044f9906c4be49a6babd26e40442a87ffb4f (diff) | |
Extensions: add new function `readExtension`
The function tries to read an extension from a string.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Extensions.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index 87ae893b3..c8bf1e546 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -16,6 +16,7 @@ Data structures and functions for representing markup extensions. -} module Text.Pandoc.Extensions ( Extension(..) + , readExtension , Extensions , emptyExtensions , extensionsFromList @@ -38,8 +39,8 @@ import Data.List (foldl') import qualified Data.Text as T import Data.Typeable (Typeable) import GHC.Generics (Generic) -import Safe (readMay) import Text.Parsec +import Text.Read (readMaybe) import Data.Aeson.TH (deriveJSON) import Data.Aeson @@ -157,6 +158,12 @@ instance ToJSON Extensions where toJSON exts = toJSON $ [ext | ext <- [minBound..maxBound], extensionEnabled ext exts] +-- | Reads a single extension from a string. +readExtension :: String -> Maybe Extension +readExtension name = case name of + "lhs" -> Just Ext_literate_haskell + _ -> readMaybe ("Ext_" ++ name) + extensionsFromList :: [Extension] -> Extensions extensionsFromList = foldr enableExtension emptyExtensions @@ -620,12 +627,9 @@ parseFormatSpec = parse formatSpec "" extMod = do polarity <- oneOf "-+" name <- many $ noneOf "-+" - ext <- case readMay ("Ext_" ++ name) of + ext <- case readExtension name of Just n -> return n - Nothing - | name == "lhs" -> return Ext_literate_haskell - | otherwise -> unexpected $ - "unknown extension: " ++ name + Nothing -> unexpected $ "unknown extension: " ++ name return $ \(extsToEnable, extsToDisable) -> case polarity of '+' -> (ext : extsToEnable, extsToDisable) |
