Added parseFormatSpec to Text.Pandoc.

This commit is contained in:
John MacFarlane
2012-08-09 07:42:40 -07:00
parent dfa4b76630
commit 244dae8da8
+22
View File
@@ -138,12 +138,34 @@ import Text.Pandoc.Options
import Data.ByteString.Lazy (ByteString)
import Data.Version (showVersion)
import Text.JSON.Generic
import Data.Set (Set)
import qualified Data.Set as Set
import Text.Parsec
import Paths_pandoc (version)
-- | Version number of pandoc library.
pandocVersion :: String
pandocVersion = showVersion version
parseFormatSpec :: String
-> Either ParseError (String, Set Extension -> Set Extension)
parseFormatSpec = parse formatSpec ""
where formatSpec = do
name <- formatName
extMods <- many extMod
return (name, foldl (.) id extMods)
formatName = many1 $ noneOf "-+"
extMod = do
polarity <- oneOf "-+"
name <- many1 $ noneOf "-+"
ext <- case reads name of
((n,[]):_) -> return n
_ -> unexpected $ "Unknown extension: " ++
name
return $ case polarity of
'-' -> Set.delete ext
_ -> Set.insert ext
-- | Association list of formats and readers.
readers :: [(String, ReaderOptions -> String -> Pandoc)]
readers = [("native" , \_ -> readNative)