mdoc-0.1.0.0: src/Mdoc/Pretty/MacroArg.hs
-- |
--
-- Module : Mdoc.Pretty.MacroArg
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Pretty.MacroArg
( prettyMacroArg
) where
import Mdoc.Prelude
import Data.Text qualified as T
import Data.Time (defaultTimeLocale, formatTime)
import Mdoc.MacroArg
import Mdoc.Pretty
import Mdoc.Pretty.Interpolation
import Mdoc.Pretty.MacroName
prettyMacroArg :: MacroArg -> Doc Ann
prettyMacroArg = \case
Mdocdate md ->
mconcat
[ annotate AnnSymbol "$"
, annotate AnnSpecial "Mdocdate"
, maybe
""
( (annotate AnnSymbol ":" <+>)
. annotate AnnArgument
. pretty
. formatTime defaultTimeLocale "%B %e %Y "
)
md
, annotate AnnSymbol "$"
]
Callable name -> annotate AnnKeyword (prettyMacroName name)
Quoted x ->
mconcat
[ annotate AnnQuote $ pretty '"'
, annotate AnnQuoted $ pretty $ T.replace "\"" "\\\"" x
, annotate AnnQuote $ pretty '"'
]
QuotedComma x ->
mconcat
[ annotate AnnQuote $ pretty '"'
, annotate AnnQuoted $ pretty $ T.replace "\"" "\\\"" x
, annotate AnnQuote $ pretty '"'
, pretty ("," :: Text)
]
InterpolatedArg i -> prettyInterpolation i
Bare x -> pretty x