module Text.Commonmark.Parser.Options ( ParserOption(..) , ParserOptions() , parserOptions , defParserOptions , poNormalize , poLinkReferences ) where import Data.Monoid (Endo(Endo, appEndo), mappend) import Data.Text (Text) data ParserOption = -- | Consolidate adjacent text nodes Normalize -- | Allows to predefine -- . -- -- References are represented with a mapping from a -- to a pair of a -- -- and an optional -- . -- -- During parsing the link references defined in a document would be -- collected into additional mapping. When link references are being -- mapping defined in options takes precedence over mapping found in -- the document. -- -- TODO: Examples | LinkReferences (Text -> Maybe (Text, Maybe Text)) data ParserOptions = ParserOptions { poNormalize :: Bool , poLinkReferences :: Text -> Maybe (Text, Maybe Text) } parserOptions :: [ParserOption] -> ParserOptions parserOptions = ($ defParserOptions) . appEndo . foldMap (Endo . optFn) where optFn :: ParserOption -> ParserOptions -> ParserOptions optFn Normalize o = o { poNormalize = True } optFn (LinkReferences f) o = o { poLinkReferences = f } defParserOptions :: ParserOptions defParserOptions = ParserOptions { poNormalize = False , poLinkReferences = const Nothing }