mdoc-0.3.0.0: src/Mdoc/Syntax/Mdoc.hs
-- |
--
-- Module : Mdoc.Syntax.Mdoc
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Syntax.Mdoc
( Mdoc (..)
-- * Pretty
, prettyMdoc
-- * Util
, textToMdoc
) where
import Mdoc.Prelude
import Data.Text qualified as T
import Mdoc.Pretty
import Mdoc.Syntax.MacroName
import Mdoc.Syntax.MdocLine
newtype Mdoc = Mdoc
{ lines :: [MdocLine]
}
deriving stock (Eq, Generic, Show)
deriving newtype (Monoid, Semigroup)
deriving (ToJSON) via (Rendered Mdoc)
prettyMdoc :: Mdoc -> Doc Ann
prettyMdoc mdoc = vsep $ map prettyMdocLine mdoc.lines
instance Pretty Mdoc where
pretty = unAnnotate . prettyMdoc
textToMdoc :: Text -> Maybe Mdoc
textToMdoc =
fmap
( Mdoc
. intersperse (MacroLine Pp [])
. map (TextLine . esc)
. toList
)
. nonEmpty
. T.lines