{-# LANGUAGE GHC2021 #-}
-- | Re-exports all Pandoc AST filter modules and provides a single
--   @applyAll@ combinator that chains them in the correct order.
module Filters
    ( applyAll
    , preprocessSource
    ) where

import           Text.Pandoc.Definition (Pandoc)

import qualified Filters.Sidenotes  as Sidenotes
import qualified Filters.Typography as Typography
import qualified Filters.Links      as Links
import qualified Filters.Smallcaps  as Smallcaps
import qualified Filters.Dropcaps   as Dropcaps
import qualified Filters.Math       as Math
import qualified Filters.Wikilinks  as Wikilinks
import qualified Filters.Code       as Code
import qualified Filters.Images     as Images

-- | Apply all AST-level filters in pipeline order.
--   Run on the Pandoc document after reading, before writing.
applyAll :: Pandoc -> Pandoc
applyAll
    = Sidenotes.apply
    . Typography.apply
    . Links.apply
    . Smallcaps.apply
    . Dropcaps.apply
    . Math.apply
    . Code.apply
    . Images.apply

-- | Apply source-level preprocessors to the raw Markdown string.
--   Run before 'readPandocWith'.
preprocessSource :: String -> String
preprocessSource = Wikilinks.preprocess
