    {-# LANGUAGE FlexibleInstances   #-}
    {-# LANGUAGE GADTs               #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE OverloadedStrings   #-}
    {- |
       Module      : Text.Pandoc
       Copyright   : Copyright (C) 2006-2020 John MacFarlane
       License     : GNU GPL, version 2 or above

       Maintainer  : John MacFarlane <jgm@berkeley.edu>
       Stability   : alpha
       Portability : portable

    This helper module exports all writers functions.
    -}
    module Text.Pandoc.Writers
      (
        -- * Writers: converting /from/ Pandoc format
          Writer(..)
        , writers
        , writeAsciiDoc
        , writeAsciiDoctor
        , writeBeamer
        , writeCommonMark
        , writeConTeXt
        , writeCustom
        , writeDZSlides
        , writeDocbook4
        , writeDocbook5
        , writeDocx
        , writeDokuWiki
        , writeEPUB2
        , writeEPUB3
        , writeFB2
        , writeIpynb
        , writeHaddock
        , writeHtml4
        , writeHtml4String
        , writeHtml5
        , writeHtml5String
        , writeICML
        , writeJATS
        , writeJatsArchiving
        , writeJatsArticleAuthoring
        , writeJatsPublishing
        , writeJSON
        , writeJira
        , writeLaTeX
        , writeMan
        , writeMarkdown
        , writeMediaWiki
        , writeMs
        , writeMuse
        , writeNative
        , writeODT
        , writeOPML
        , writeOpenDocument
        , writeOrg
        , writePlain
        , writePowerpoint
        , writeRST
        , writeRTF
        , writeRevealJs
        , writeS5
        , writeSlideous
        , writeSlidy
        , writeTEI
        , writeTexinfo
        , writeTextile
        , writeXWiki
        , writeZimWiki
        , getWriter
        ) where

    import Control.Monad.Except (throwError)
    import Control.Monad (unless)
    import Data.Aeson
    import qualified Data.ByteString.Lazy as BL
    import Data.Text (Text)
    import qualified Data.Text as T
    import Text.Pandoc.Class
    import Text.Pandoc.Definition
    import Text.Pandoc.Options
    import qualified Text.Pandoc.UTF8 as UTF8
    import Text.Pandoc.Error
    import Text.Pandoc.Writers.AsciiDoc
    import Text.Pandoc.Writers.CommonMark
    import Text.Pandoc.Writers.ConTeXt
    import Text.Pandoc.Writers.Custom
    import Text.Pandoc.Writers.Docbook
    import Text.Pandoc.Writers.Docx
    import Text.Pandoc.Writers.DokuWiki
    import Text.Pandoc.Writers.EPUB
    import Text.Pandoc.Writers.FB2
    import Text.Pandoc.Writers.Ipynb
    import Text.Pandoc.Writers.Haddock
    import Text.Pandoc.Writers.HTML
    import Text.Pandoc.Writers.ICML
    import Text.Pandoc.Writers.JATS
    import Text.Pandoc.Writers.Jira
    import Text.Pandoc.Writers.LaTeX
    import Text.Pandoc.Writers.Man
    import Text.Pandoc.Writers.Markdown
    import Text.Pandoc.Writers.MediaWiki
    import Text.Pandoc.Writers.Ms
    import Text.Pandoc.Writers.Muse
    import Text.Pandoc.Writers.Native
    import Text.Pandoc.Writers.ODT
    import Text.Pandoc.Writers.OpenDocument
    import Text.Pandoc.Writers.OPML
    import Text.Pandoc.Writers.Org
    import Text.Pandoc.Writers.Powerpoint
    import Text.Pandoc.Writers.RST
    import Text.Pandoc.Writers.RTF
    import Text.Pandoc.Writers.TEI
    import Text.Pandoc.Writers.Texinfo
    import Text.Pandoc.Writers.Textile
    import Text.Pandoc.Writers.XWiki
    import Text.Pandoc.Writers.ZimWiki
    import Text.Parsec.Error

    data Writer m = TextWriter (WriterOptions -> Pandoc -> m Text)
                  | ByteStringWriter (WriterOptions -> Pandoc -> m BL.ByteString)

    -- | Association list of formats and writers.
    writers :: PandocMonad m => [ (Text, Writer m) ]
    writers :: [(Text, Writer m)]
    writers = [
       ("native"       , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeNative)
      ,("json"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJSON)
      ,("docx"         , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writeDocx)
      ,("odt"          , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writeODT)
      ,("pptx"         , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writePowerpoint)
      ,("epub"         , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writeEPUB3)
      ,("epub2"        , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writeEPUB2)
      ,("epub3"        , (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m ByteString) -> Writer m
    ByteStringWriter WriterOptions -> Pandoc -> m ByteString
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m ByteString
    writeEPUB3)
      ,("fb2"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeFB2)
      ,("ipynb"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeIpynb)
      ,("html"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeHtml5String)
      ,("html4"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeHtml4String)
      ,("html5"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeHtml5String)
      ,("icml"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeICML)
      ,("s5"           , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeS5)
      ,("slidy"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeSlidy)
      ,("slideous"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeSlideous)
      ,("dzslides"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeDZSlides)
      ,("revealjs"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeRevealJs)
      ,("docbook"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeDocbook5)
      ,("docbook4"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeDocbook4)
      ,("docbook5"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeDocbook5)
      ,("jats"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJatsArchiving)
      ,("jats_articleauthoring", (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJatsArticleAuthoring)
      ,("jats_publishing" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJatsPublishing)
      ,("jats_archiving" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJatsArchiving)
      ,("jira"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeJira)
      ,("opml"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeOPML)
      ,("opendocument" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeOpenDocument)
      ,("latex"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeLaTeX)
      ,("beamer"       , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeBeamer)
      ,("context"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeConTeXt)
      ,("texinfo"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeTexinfo)
      ,("man"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMan)
      ,("ms"           , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMs)
      ,("markdown"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMarkdown)
      ,("markdown_strict" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMarkdown)
      ,("markdown_phpextra" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMarkdown)
      ,("markdown_github" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMarkdown)
      ,("markdown_mmd" , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMarkdown)
      ,("plain"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writePlain)
      ,("rst"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeRST)
      ,("mediawiki"    , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMediaWiki)
      ,("dokuwiki"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeDokuWiki)
      ,("xwiki"        , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeXWiki)
      ,("zimwiki"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeZimWiki)
      ,("textile"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeTextile)
      ,("rtf"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeRTF)
      ,("org"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeOrg)
      ,("asciidoc"     , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeAsciiDoc)
      ,("asciidoctor"  , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeAsciiDoctor)
      ,("haddock"      , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeHaddock)
      ,("commonmark"   , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeCommonMark)
      ,("gfm"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeCommonMark)
      ,("tei"          , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeTEI)
      ,("muse"         , (WriterOptions -> Pandoc -> m Text) -> Writer m
    forall (m :: * -> *).
    (WriterOptions -> Pandoc -> m Text) -> Writer m
    TextWriter WriterOptions -> Pandoc -> m Text
    forall (m :: * -> *).
    PandocMonad m =>
    WriterOptions -> Pandoc -> m Text
    writeMuse)
      ]

    -- | Retrieve writer, extensions based on formatSpec (format+extensions).
    getWriter :: PandocMonad m => Text -> m (Writer m, Extensions)
    getWriter :: Text -> m (Writer m, Extensions)
    getWriter s :: Text
    s =
      case Text -> Either ParseError (Text, [Extension], [Extension])
    parseFormatSpec Text
    s of
            Left e :: ParseError
    e  -> PandocError -> m (Writer m, Extensions)
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> m (Writer m, Extensions))
    -> PandocError -> m (Writer m, Extensions)
    forall a b. (a -> b) -> a -> b
    $ Text -> PandocError
    PandocAppError
                        (Text -> PandocError) -> Text -> PandocError
    forall a b. (a -> b) -> a -> b
    $ Text -> [Text] -> Text
    T.intercalate "\n" [String -> Text
    T.pack String
    m | Message m :: String
    m <- ParseError -> [Message]
    errorMessages ParseError
    e]
            Right (writerName :: Text
    writerName, extsToEnable :: [Extension]
    extsToEnable, extsToDisable :: [Extension]
    extsToDisable) ->
               case Text -> [(Text, Writer m)] -> Maybe (Writer m)
    forall a b. Eq a => a -> [(a, b)] -> Maybe b
    lookup Text
    writerName [(Text, Writer m)]
    forall (m :: * -> *). PandocMonad m => [(Text, Writer m)]
    writers of
                       Nothing  -> PandocError -> m (Writer m, Extensions)
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> m (Writer m, Extensions))
    -> PandocError -> m (Writer m, Extensions)
    forall a b. (a -> b) -> a -> b
    $
                                     Text -> PandocError
    PandocUnknownWriterError Text
    writerName
                       Just  w :: Writer m
    w  -> do
                         let allExts :: Extensions
    allExts = Text -> Extensions
    getAllExtensions Text
    writerName
                         let exts :: Extensions
    exts = (Extension -> Extensions -> Extensions)
    -> Extensions -> [Extension] -> Extensions
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr Extension -> Extensions -> Extensions
    disableExtension
                               ((Extension -> Extensions -> Extensions)
    -> Extensions -> [Extension] -> Extensions
    forall (t :: * -> *) a b.
    Foldable t =>
    (a -> b -> b) -> b -> t a -> b
    foldr Extension -> Extensions -> Extensions
    enableExtension
                                 (Text -> Extensions
    getDefaultExtensions Text
    writerName)
                                       [Extension]
    extsToEnable) [Extension]
    extsToDisable
                         (Extension -> m ()) -> [Extension] -> m ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ (\ext :: Extension
    ext ->
                                  Bool -> m () -> m ()
    forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
    unless (Extension -> Extensions -> Bool
    extensionEnabled Extension
    ext Extensions
    allExts) (m () -> m ()) -> m () -> m ()
    forall a b. (a -> b) -> a -> b
    $
                                    PandocError -> m ()
    forall e (m :: * -> *) a. MonadError e m => e -> m a
    throwError (PandocError -> m ()) -> PandocError -> m ()
    forall a b. (a -> b) -> a -> b
    $
                                       Text -> Text -> PandocError
    PandocUnsupportedExtensionError
                                       (Int -> Text -> Text
    T.drop 4 (Text -> Text) -> Text -> Text
    forall a b. (a -> b) -> a -> b
    $ String -> Text
    T.pack (String -> Text) -> String -> Text
    forall a b. (a -> b) -> a -> b
    $ Extension -> String
    forall a. Show a => a -> String
    show Extension
    ext) Text
    writerName)
                              ([Extension]
    extsToEnable [Extension] -> [Extension] -> [Extension]
    forall a. [a] -> [a] -> [a]
    ++ [Extension]
    extsToDisable)
                         (Writer m, Extensions) -> m (Writer m, Extensions)
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Writer m
    w, Extensions
    exts)

    writeJSON :: PandocMonad m => WriterOptions -> Pandoc -> m Text
    writeJSON :: WriterOptions -> Pandoc -> m Text
    writeJSON _ = Text -> m Text
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Text -> m Text) -> (Pandoc -> Text) -> Pandoc -> m Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> Text
    UTF8.toText (ByteString -> Text) -> (Pandoc -> ByteString) -> Pandoc -> Text
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ByteString -> ByteString
    BL.toStrict (ByteString -> ByteString)
    -> (Pandoc -> ByteString) -> Pandoc -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Pandoc -> ByteString
    forall a. ToJSON a => a -> ByteString
    encode