@@ -138,12 +138,34 @@ import Text.Pandoc.Options
138138import Data.ByteString.Lazy (ByteString)
139139import Data.Version (showVersion)
140140import Text.JSON.Generic
141+import Data.Set (Set)
142+import qualified Data.Set as Set
143+import Text.Parsec
141144import Paths_pandoc (version)
142145
143146-- | Version number of pandoc library.
144147pandocVersion :: String
145148pandocVersion = showVersion version
146149
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+
147169-- | Association list of formats and readers.
148170readers :: [(String, ReaderOptions -> String -> Pandoc)]
149171readers = [("native" , \_ -> readNative)