git.iko.soy/typeable/pandoc
on master help sign in
Added parseFormatSpec to Text.Pandoc.
244dae8John MacFarlane
src/Text/Pandoc.hs+22
@@ -138,12 +138,34 @@ import Text.Pandoc.Options
138import Data.ByteString.Lazy (ByteString)
138import Data.ByteString.Lazy (ByteString)
139import Data.Version (showVersion)
139import Data.Version (showVersion)
140import Text.JSON.Generic
140import Text.JSON.Generic
141+import Data.Set (Set)
142+import qualified Data.Set as Set
143+import Text.Parsec
141import Paths_pandoc (version)
144import Paths_pandoc (version)
142
145
143-- | Version number of pandoc library.
146-- | Version number of pandoc library.
144pandocVersion :: String
147pandocVersion :: String
145pandocVersion = showVersion version
148pandocVersion = showVersion version
146
149
150+parseFormatSpec :: String
151+ -> Either ParseError (String, Set Extension -> Set Extension)
152+parseFormatSpec = parse formatSpec ""
153+ where formatSpec = do
154+ name <- formatName
155+ extMods <- many extMod
156+ return (name, foldl (.) id extMods)
157+ formatName = many1 $ noneOf "-+"
158+ extMod = do
159+ polarity <- oneOf "-+"
160+ name <- many1 $ noneOf "-+"
161+ ext <- case reads name of
162+ ((n,[]):_) -> return n
163+ _ -> unexpected $ "Unknown extension: " ++
164+ name
165+ return $ case polarity of
166+ '-' -> Set.delete ext
167+ _ -> Set.insert ext
168+
147-- | Association list of formats and readers.
169-- | Association list of formats and readers.
148readers :: [(String, ReaderOptions -> String -> Pandoc)]
170readers :: [(String, ReaderOptions -> String -> Pandoc)]
149readers = [("native" , \_ -> readNative)
171readers = [("native" , \_ -> readNative)