-- | @since 1.4.5
module Documentation.Haddock.Markup (
    markup
  , idMarkup
  , plainMarkup
  ) where

import Documentation.Haddock.Types

import Data.Maybe ( fromMaybe )

markup :: DocMarkupH mod id a -> DocH mod id -> a
markup :: DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
DocEmpty                       = DocMarkupH mod id a -> a
forall mod id a. DocMarkupH mod id a -> a
markupEmpty DocMarkupH mod id a
m
markup DocMarkupH mod id a
m (DocAppend DocH mod id
d1 DocH mod id
d2)              = DocMarkupH mod id a -> a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a -> a
markupAppend DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d1) (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d2)
markup DocMarkupH mod id a
m (DocString String
s)                  = DocMarkupH mod id a -> String -> a
forall mod id a. DocMarkupH mod id a -> String -> a
markupString DocMarkupH mod id a
m String
s
markup DocMarkupH mod id a
m (DocParagraph DocH mod id
d)               = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupParagraph DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocIdentifier id
x)              = DocMarkupH mod id a -> id -> a
forall mod id a. DocMarkupH mod id a -> id -> a
markupIdentifier DocMarkupH mod id a
m id
x
markup DocMarkupH mod id a
m (DocIdentifierUnchecked mod
x)     = DocMarkupH mod id a -> mod -> a
forall mod id a. DocMarkupH mod id a -> mod -> a
markupIdentifierUnchecked DocMarkupH mod id a
m mod
x
markup DocMarkupH mod id a
m (DocModule (ModLink String
mo Maybe (DocH mod id)
l))     = DocMarkupH mod id a -> ModLink a -> a
forall mod id a. DocMarkupH mod id a -> ModLink a -> a
markupModule DocMarkupH mod id a
m (String -> Maybe a -> ModLink a
forall id. String -> Maybe id -> ModLink id
ModLink String
mo ((DocH mod id -> a) -> Maybe (DocH mod id) -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m) Maybe (DocH mod id)
l))
markup DocMarkupH mod id a
m (DocWarning DocH mod id
d)                 = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupWarning DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocEmphasis DocH mod id
d)                = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupEmphasis DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocBold DocH mod id
d)                    = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupBold DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocMonospaced DocH mod id
d)              = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupMonospaced DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocUnorderedList [DocH mod id]
ds)          = DocMarkupH mod id a -> [a] -> a
forall mod id a. DocMarkupH mod id a -> [a] -> a
markupUnorderedList DocMarkupH mod id a
m ((DocH mod id -> a) -> [DocH mod id] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m) [DocH mod id]
ds)
markup DocMarkupH mod id a
m (DocOrderedList [DocH mod id]
ds)            = DocMarkupH mod id a -> [a] -> a
forall mod id a. DocMarkupH mod id a -> [a] -> a
markupOrderedList DocMarkupH mod id a
m ((DocH mod id -> a) -> [DocH mod id] -> [a]
forall a b. (a -> b) -> [a] -> [b]
map (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m) [DocH mod id]
ds)
markup DocMarkupH mod id a
m (DocDefList [(DocH mod id, DocH mod id)]
ds)                = DocMarkupH mod id a -> [(a, a)] -> a
forall mod id a. DocMarkupH mod id a -> [(a, a)] -> a
markupDefList DocMarkupH mod id a
m (((DocH mod id, DocH mod id) -> (a, a))
-> [(DocH mod id, DocH mod id)] -> [(a, a)]
forall a b. (a -> b) -> [a] -> [b]
map (DocMarkupH mod id a -> (DocH mod id, DocH mod id) -> (a, a)
forall mod id a.
DocMarkupH mod id a -> (DocH mod id, DocH mod id) -> (a, a)
markupPair DocMarkupH mod id a
m) [(DocH mod id, DocH mod id)]
ds)
markup DocMarkupH mod id a
m (DocCodeBlock DocH mod id
d)               = DocMarkupH mod id a -> a -> a
forall mod id a. DocMarkupH mod id a -> a -> a
markupCodeBlock DocMarkupH mod id a
m (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
d)
markup DocMarkupH mod id a
m (DocHyperlink (Hyperlink String
u Maybe (DocH mod id)
l)) = DocMarkupH mod id a -> Hyperlink a -> a
forall mod id a. DocMarkupH mod id a -> Hyperlink a -> a
markupHyperlink DocMarkupH mod id a
m (String -> Maybe a -> Hyperlink a
forall id. String -> Maybe id -> Hyperlink id
Hyperlink String
u ((DocH mod id -> a) -> Maybe (DocH mod id) -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m) Maybe (DocH mod id)
l))
markup DocMarkupH mod id a
m (DocAName String
ref)                 = DocMarkupH mod id a -> String -> a
forall mod id a. DocMarkupH mod id a -> String -> a
markupAName DocMarkupH mod id a
m String
ref
markup DocMarkupH mod id a
m (DocPic Picture
img)                   = DocMarkupH mod id a -> Picture -> a
forall mod id a. DocMarkupH mod id a -> Picture -> a
markupPic DocMarkupH mod id a
m Picture
img
markup DocMarkupH mod id a
m (DocMathInline String
mathjax)        = DocMarkupH mod id a -> String -> a
forall mod id a. DocMarkupH mod id a -> String -> a
markupMathInline DocMarkupH mod id a
m String
mathjax
markup DocMarkupH mod id a
m (DocMathDisplay String
mathjax)       = DocMarkupH mod id a -> String -> a
forall mod id a. DocMarkupH mod id a -> String -> a
markupMathDisplay DocMarkupH mod id a
m String
mathjax
markup DocMarkupH mod id a
m (DocProperty String
p)                = DocMarkupH mod id a -> String -> a
forall mod id a. DocMarkupH mod id a -> String -> a
markupProperty DocMarkupH mod id a
m String
p
markup DocMarkupH mod id a
m (DocExamples [Example]
e)                = DocMarkupH mod id a -> [Example] -> a
forall mod id a. DocMarkupH mod id a -> [Example] -> a
markupExample DocMarkupH mod id a
m [Example]
e
markup DocMarkupH mod id a
m (DocHeader (Header Int
l DocH mod id
t))       = DocMarkupH mod id a -> Header a -> a
forall mod id a. DocMarkupH mod id a -> Header a -> a
markupHeader DocMarkupH mod id a
m (Int -> a -> Header a
forall id. Int -> id -> Header id
Header Int
l (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
t))
markup DocMarkupH mod id a
m (DocTable (Table [TableRow (DocH mod id)]
h [TableRow (DocH mod id)]
b))         = DocMarkupH mod id a -> Table a -> a
forall mod id a. DocMarkupH mod id a -> Table a -> a
markupTable DocMarkupH mod id a
m ([TableRow a] -> [TableRow a] -> Table a
forall id. [TableRow id] -> [TableRow id] -> Table id
Table ((TableRow (DocH mod id) -> TableRow a)
-> [TableRow (DocH mod id)] -> [TableRow a]
forall a b. (a -> b) -> [a] -> [b]
map ((DocH mod id -> a) -> TableRow (DocH mod id) -> TableRow a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m)) [TableRow (DocH mod id)]
h) ((TableRow (DocH mod id) -> TableRow a)
-> [TableRow (DocH mod id)] -> [TableRow a]
forall a b. (a -> b) -> [a] -> [b]
map ((DocH mod id -> a) -> TableRow (DocH mod id) -> TableRow a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m)) [TableRow (DocH mod id)]
b))

markupPair :: DocMarkupH mod id a -> (DocH mod id, DocH mod id) -> (a, a)
markupPair :: DocMarkupH mod id a -> (DocH mod id, DocH mod id) -> (a, a)
markupPair DocMarkupH mod id a
m (DocH mod id
a,DocH mod id
b) = (DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
a, DocMarkupH mod id a -> DocH mod id -> a
forall mod id a. DocMarkupH mod id a -> DocH mod id -> a
markup DocMarkupH mod id a
m DocH mod id
b)

-- | The identity markup
idMarkup :: DocMarkupH mod id (DocH mod id)
idMarkup :: DocMarkupH mod id (DocH mod id)
idMarkup = Markup :: forall mod id a.
a
-> (String -> a)
-> (a -> a)
-> (a -> a -> a)
-> (id -> a)
-> (mod -> a)
-> (ModLink a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> ([a] -> a)
-> ([a] -> a)
-> ([(a, a)] -> a)
-> (a -> a)
-> (Hyperlink a -> a)
-> (String -> a)
-> (Picture -> a)
-> (String -> a)
-> (String -> a)
-> (String -> a)
-> ([Example] -> a)
-> (Header a -> a)
-> (Table a -> a)
-> DocMarkupH mod id a
Markup {
  markupEmpty :: DocH mod id
markupEmpty                = DocH mod id
forall mod id. DocH mod id
DocEmpty,
  markupString :: String -> DocH mod id
markupString               = String -> DocH mod id
forall mod id. String -> DocH mod id
DocString,
  markupParagraph :: DocH mod id -> DocH mod id
markupParagraph            = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocParagraph,
  markupAppend :: DocH mod id -> DocH mod id -> DocH mod id
markupAppend               = DocH mod id -> DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id -> DocH mod id
DocAppend,
  markupIdentifier :: id -> DocH mod id
markupIdentifier           = id -> DocH mod id
forall mod id. id -> DocH mod id
DocIdentifier,
  markupIdentifierUnchecked :: mod -> DocH mod id
markupIdentifierUnchecked  = mod -> DocH mod id
forall mod id. mod -> DocH mod id
DocIdentifierUnchecked,
  markupModule :: ModLink (DocH mod id) -> DocH mod id
markupModule               = ModLink (DocH mod id) -> DocH mod id
forall mod id. ModLink (DocH mod id) -> DocH mod id
DocModule,
  markupWarning :: DocH mod id -> DocH mod id
markupWarning              = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocWarning,
  markupEmphasis :: DocH mod id -> DocH mod id
markupEmphasis             = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocEmphasis,
  markupBold :: DocH mod id -> DocH mod id
markupBold                 = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocBold,
  markupMonospaced :: DocH mod id -> DocH mod id
markupMonospaced           = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocMonospaced,
  markupUnorderedList :: [DocH mod id] -> DocH mod id
markupUnorderedList        = [DocH mod id] -> DocH mod id
forall mod id. [DocH mod id] -> DocH mod id
DocUnorderedList,
  markupOrderedList :: [DocH mod id] -> DocH mod id
markupOrderedList          = [DocH mod id] -> DocH mod id
forall mod id. [DocH mod id] -> DocH mod id
DocOrderedList,
  markupDefList :: [(DocH mod id, DocH mod id)] -> DocH mod id
markupDefList              = [(DocH mod id, DocH mod id)] -> DocH mod id
forall mod id. [(DocH mod id, DocH mod id)] -> DocH mod id
DocDefList,
  markupCodeBlock :: DocH mod id -> DocH mod id
markupCodeBlock            = DocH mod id -> DocH mod id
forall mod id. DocH mod id -> DocH mod id
DocCodeBlock,
  markupHyperlink :: Hyperlink (DocH mod id) -> DocH mod id
markupHyperlink            = Hyperlink (DocH mod id) -> DocH mod id
forall mod id. Hyperlink (DocH mod id) -> DocH mod id
DocHyperlink,
  markupAName :: String -> DocH mod id
markupAName                = String -> DocH mod id
forall mod id. String -> DocH mod id
DocAName,
  markupPic :: Picture -> DocH mod id
markupPic                  = Picture -> DocH mod id
forall mod id. Picture -> DocH mod id
DocPic,
  markupMathInline :: String -> DocH mod id
markupMathInline           = String -> DocH mod id
forall mod id. String -> DocH mod id
DocMathInline,
  markupMathDisplay :: String -> DocH mod id
markupMathDisplay          = String -> DocH mod id
forall mod id. String -> DocH mod id
DocMathDisplay,
  markupProperty :: String -> DocH mod id
markupProperty             = String -> DocH mod id
forall mod id. String -> DocH mod id
DocProperty,
  markupExample :: [Example] -> DocH mod id
markupExample              = [Example] -> DocH mod id
forall mod id. [Example] -> DocH mod id
DocExamples,
  markupHeader :: Header (DocH mod id) -> DocH mod id
markupHeader               = Header (DocH mod id) -> DocH mod id
forall mod id. Header (DocH mod id) -> DocH mod id
DocHeader,
  markupTable :: Table (DocH mod id) -> DocH mod id
markupTable                = Table (DocH mod id) -> DocH mod id
forall mod id. Table (DocH mod id) -> DocH mod id
DocTable
  }

-- | Map a 'DocH' into a best estimate of an alternate string. The idea is to
-- strip away any formatting while preserving as much of the actual text as
-- possible.
plainMarkup :: (mod -> String) -> (id -> String) -> DocMarkupH mod id String
plainMarkup :: (mod -> String) -> (id -> String) -> DocMarkupH mod id String
plainMarkup mod -> String
plainMod id -> String
plainIdent = Markup :: forall mod id a.
a
-> (String -> a)
-> (a -> a)
-> (a -> a -> a)
-> (id -> a)
-> (mod -> a)
-> (ModLink a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> ([a] -> a)
-> ([a] -> a)
-> ([(a, a)] -> a)
-> (a -> a)
-> (Hyperlink a -> a)
-> (String -> a)
-> (Picture -> a)
-> (String -> a)
-> (String -> a)
-> (String -> a)
-> ([Example] -> a)
-> (Header a -> a)
-> (Table a -> a)
-> DocMarkupH mod id a
Markup {
  markupEmpty :: String
markupEmpty                = String
"",
  markupString :: String -> String
markupString               = String -> String
forall a. a -> a
id,
  markupParagraph :: String -> String
markupParagraph            = String -> String
forall a. a -> a
id,
  markupAppend :: String -> String -> String
markupAppend               = String -> String -> String
forall a. [a] -> [a] -> [a]
(++),
  markupIdentifier :: id -> String
markupIdentifier           = id -> String
plainIdent,
  markupIdentifierUnchecked :: mod -> String
markupIdentifierUnchecked  = mod -> String
plainMod,
  markupModule :: ModLink String -> String
markupModule               = \(ModLink String
m Maybe String
lbl) -> String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
m Maybe String
lbl,
  markupWarning :: String -> String
markupWarning              = String -> String
forall a. a -> a
id,
  markupEmphasis :: String -> String
markupEmphasis             = String -> String
forall a. a -> a
id,
  markupBold :: String -> String
markupBold                 = String -> String
forall a. a -> a
id,
  markupMonospaced :: String -> String
markupMonospaced           = String -> String
forall a. a -> a
id,
  markupUnorderedList :: [String] -> String
markupUnorderedList        = String -> [String] -> String
forall a b. a -> b -> a
const String
"",
  markupOrderedList :: [String] -> String
markupOrderedList          = String -> [String] -> String
forall a b. a -> b -> a
const String
"",
  markupDefList :: [(String, String)] -> String
markupDefList              = String -> [(String, String)] -> String
forall a b. a -> b -> a
const String
"",
  markupCodeBlock :: String -> String
markupCodeBlock            = String -> String
forall a. a -> a
id,
  markupHyperlink :: Hyperlink String -> String
markupHyperlink            = \(Hyperlink String
url Maybe String
lbl) -> String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
url Maybe String
lbl,
  markupAName :: String -> String
markupAName                = String -> String
forall a. a -> a
id,
  markupPic :: Picture -> String
markupPic                  = \(Picture String
uri Maybe String
title) -> String -> Maybe String -> String
forall a. a -> Maybe a -> a
fromMaybe String
uri Maybe String
title,
  markupMathInline :: String -> String
markupMathInline           = String -> String
forall a. a -> a
id,
  markupMathDisplay :: String -> String
markupMathDisplay          = String -> String
forall a. a -> a
id,
  markupProperty :: String -> String
markupProperty             = String -> String
forall a. a -> a
id,
  markupExample :: [Example] -> String
markupExample              = String -> [Example] -> String
forall a b. a -> b -> a
const String
"",
  markupHeader :: Header String -> String
markupHeader               = \(Header Int
_ String
title) -> String
title,
  markupTable :: Table String -> String
markupTable                = String -> Table String -> String
forall a b. a -> b -> a
const String
""
  }