    --------------------------------------------------------------------
    -- |
    -- Module    : Text.Atom.Feed.Export
    -- Copyright : (c) Galois, Inc. 2008,
    --             (c) Sigbjorn Finne 2009-
    -- License   : BSD3
    --
    -- Maintainer: Sigbjorn Finne <sof@forkIO.com>
    -- Stability : provisional
    -- Portability:: portable
    -- Description: Convert from Atom to XML
    --
    -- Convert from Atom to XML
    --
    --------------------------------------------------------------------
    module Text.Atom.Feed.Export
      ( atom_prefix
      , atom_thr_prefix
      , atomNS
      , atomThreadNS
      , xmlns_atom
      , xmlns_atom_thread
      , atomName
      , atomAttr
      , atomNode
      , atomLeaf
      , atomThreadName
      , atomThreadAttr
      , atomThreadNode
      , atomThreadLeaf
      , xmlFeed
      , textFeed
      , xmlEntry
      , xmlContent
      , xmlCategory
      , xmlLink
      , xmlSource
      , xmlGenerator
      , xmlAuthor
      , xmlContributor
      , xmlPerson
      , xmlInReplyTo
      , xmlInReplyTotal
      , xmlId
      , xmlIcon
      , xmlLogo
      , xmlUpdated
      , xmlPublished
      , xmlRights
      , xmlTitle
      , xmlSubtitle
      , xmlSummary
      , xmlTextContent
      , mb
      ) where

    import Prelude.Compat

    import Data.Text (Text, pack)
    import Data.XML.Types as XML
    import Text.Atom.Feed
    import qualified Data.Text.Lazy as TL
    import qualified Data.Text.Util as U

    atom_prefix :: Maybe Text
    atom_prefix :: Maybe Text
    atom_prefix = Maybe Text
    forall a. Maybe a
    Nothing -- Just "atom"

    atom_thr_prefix :: Maybe Text
    atom_thr_prefix :: Maybe Text
    atom_thr_prefix = Text -> Maybe Text
    forall a. a -> Maybe a
    Just "thr"

    atomNS :: Text
    atomNS :: Text
    atomNS = "http://www.w3.org/2005/Atom"

    atomThreadNS :: Text
    atomThreadNS :: Text
    atomThreadNS = "http://purl.org/syndication/thread/1.0"

    blank_element :: Name -> [Node] -> XML.Element
    blank_element :: Name -> [Node] -> Element
    blank_element name :: Name
    name = Name -> [(Name, [Content])] -> [Node] -> Element
    XML.Element Name
    name []

    xmlns_atom :: Attr
    xmlns_atom :: (Name, [Content])
    xmlns_atom = (Name
    qn, [Text -> Content
    ContentText Text
    atomNS])
      where
        qn :: Name
    qn =
          case Maybe Text
    atom_prefix of
            Nothing -> Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name {nameLocalName :: Text
    nameLocalName = "xmlns", nameNamespace :: Maybe Text
    nameNamespace = Maybe Text
    forall a. Maybe a
    Nothing, namePrefix :: Maybe Text
    namePrefix = Maybe Text
    forall a. Maybe a
    Nothing}
            Just s :: Text
    s ->
              Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name
                { nameLocalName :: Text
    nameLocalName = Text
    s
                , nameNamespace :: Maybe Text
    nameNamespace = Maybe Text
    forall a. Maybe a
    Nothing -- XXX: is this ok?
                , namePrefix :: Maybe Text
    namePrefix = Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns"
                }

    xmlns_atom_thread :: Attr
    xmlns_atom_thread :: (Name, [Content])
    xmlns_atom_thread = (Name
    qn, [Text -> Content
    ContentText Text
    atomThreadNS])
      where
        qn :: Name
    qn =
          case Maybe Text
    atom_prefix of
            Nothing -> Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name {nameLocalName :: Text
    nameLocalName = "xmlns", nameNamespace :: Maybe Text
    nameNamespace = Maybe Text
    forall a. Maybe a
    Nothing, namePrefix :: Maybe Text
    namePrefix = Maybe Text
    forall a. Maybe a
    Nothing}
            Just s :: Text
    s ->
              Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name
                { nameLocalName :: Text
    nameLocalName = Text
    s
                , nameNamespace :: Maybe Text
    nameNamespace = Maybe Text
    forall a. Maybe a
    Nothing -- XXX: is this ok?
                , namePrefix :: Maybe Text
    namePrefix = Text -> Maybe Text
    forall a. a -> Maybe a
    Just "xmlns"
                }

    atomName :: Text -> Name
    atomName :: Text -> Name
    atomName nc :: Text
    nc = Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name {nameLocalName :: Text
    nameLocalName = Text
    nc, nameNamespace :: Maybe Text
    nameNamespace = Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    atomNS, namePrefix :: Maybe Text
    namePrefix = Maybe Text
    atom_prefix}

    atomAttr :: Text -> Text -> Attr
    atomAttr :: Text -> Text -> (Name, [Content])
    atomAttr x :: Text
    x y :: Text
    y = (Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name {nameLocalName :: Text
    nameLocalName = Text
    x, nameNamespace :: Maybe Text
    nameNamespace = Maybe Text
    forall a. Maybe a
    Nothing, namePrefix :: Maybe Text
    namePrefix = Maybe Text
    atom_prefix}, [Text -> Content
    ContentText Text
    y])

    atomNode :: Text -> [Node] -> XML.Element
    atomNode :: Text -> [Node] -> Element
    atomNode x :: Text
    x = Name -> [Node] -> Element
    blank_element (Text -> Name
    atomName Text
    x)

    atomLeaf :: Text -> Text -> XML.Element
    atomLeaf :: Text -> Text -> Element
    atomLeaf tag :: Text
    tag txt :: Text
    txt = Name -> [Node] -> Element
    blank_element (Text -> Name
    atomName Text
    tag) [Content -> Node
    NodeContent (Content -> Node) -> Content -> Node
    forall a b. (a -> b) -> a -> b
    $ Text -> Content
    ContentText Text
    txt]

    atomThreadName :: Text -> Name
    atomThreadName :: Text -> Name
    atomThreadName nc :: Text
    nc =
      Name :: Text -> Maybe Text -> Maybe Text -> Name
    Name {nameLocalName :: Text
    nameLocalName = Text
    nc, nameNamespace :: Maybe Text
    nameNamespace = Text -> Maybe Text
    forall a. a -> Maybe a
    Just Text
    atomThreadNS, namePrefix :: Maybe Text
    namePrefix = Maybe Text
    atom_thr_prefix}

    atomThreadAttr :: Text -> Text -> Attr
    atomThreadAttr :: Text -> Text -> (Name, [Content])
    atomThreadAttr x :: Text
    x y :: Text
    y = (Text -> Name
    atomThreadName Text
    x, [Text -> Content
    ContentText Text
    y])

    atomThreadNode :: Text -> [Node] -> XML.Element
    atomThreadNode :: Text -> [Node] -> Element
    atomThreadNode x :: Text
    x = Name -> [Node] -> Element
    blank_element (Text -> Name
    atomThreadName Text
    x)

    atomThreadLeaf :: Text -> Text -> XML.Element
    atomThreadLeaf :: Text -> Text -> Element
    atomThreadLeaf tag :: Text
    tag txt :: Text
    txt = Name -> [Node] -> Element
    blank_element (Text -> Name
    atomThreadName Text
    tag) [Content -> Node
    NodeContent (Content -> Node) -> Content -> Node
    forall a b. (a -> b) -> a -> b
    $ Text -> Content
    ContentText Text
    txt]

    --------------------------------------------------------------------------------
    xmlFeed :: Feed -> XML.Element
    xmlFeed :: Feed -> Element
    xmlFeed f :: Feed
    f =
      (Text -> [Node] -> Element
    atomNode "feed" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
    forall a b. (a -> b) -> a -> b
    $
       [TextContent -> Element
    xmlTitle (Feed -> TextContent
    feedTitle Feed
    f)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       [Text -> Element
    xmlId (Feed -> Text
    feedId Feed
    f)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       [Text -> Element
    xmlUpdated (Feed -> Text
    feedUpdated Feed
    f)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Link -> Element) -> [Link] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Link -> Element
    xmlLink (Feed -> [Link]
    feedLinks Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Person -> Element) -> [Person] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Person -> Element
    xmlAuthor (Feed -> [Person]
    feedAuthors Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Category -> Element) -> [Category] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Category -> Element
    xmlCategory (Feed -> [Category]
    feedCategories Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Person -> Element) -> [Person] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Person -> Element
    xmlContributor (Feed -> [Person]
    feedContributors Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Generator -> Element) -> Maybe Generator -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Generator -> Element
    xmlGenerator (Feed -> Maybe Generator
    feedGenerator Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlIcon (Feed -> Maybe Text
    feedIcon Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlLogo (Feed -> Maybe Text
    feedLogo Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlRights (Feed -> Maybe TextContent
    feedRights Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlSubtitle (Feed -> Maybe TextContent
    feedSubtitle Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (Entry -> Element) -> [Entry] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Entry -> Element
    xmlEntry (Feed -> [Entry]
    feedEntries Feed
    f) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Feed -> [Element]
    feedOther Feed
    f)
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = [(Name, [Content])
    xmlns_atom]}

    textFeed :: Feed -> Maybe TL.Text
    textFeed :: Feed -> Maybe Text
    textFeed = (Feed -> Element) -> Feed -> Maybe Text
    forall a. (a -> Element) -> a -> Maybe Text
    U.renderFeed Feed -> Element
    xmlFeed

    xmlEntry :: Entry -> XML.Element
    xmlEntry :: Entry -> Element
    xmlEntry e :: Entry
    e =
      (Text -> [Node] -> Element
    atomNode "entry" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
       (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
    forall a b. (a -> b) -> a -> b
    $
       [Text -> Element
    xmlId (Entry -> Text
    entryId Entry
    e)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       [TextContent -> Element
    xmlTitle (Entry -> TextContent
    entryTitle Entry
    e)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       [Text -> Element
    xmlUpdated (Entry -> Text
    entryUpdated Entry
    e)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Person -> Element) -> [Person] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Person -> Element
    xmlAuthor (Entry -> [Person]
    entryAuthors Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Category -> Element) -> [Category] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Category -> Element
    xmlCategory (Entry -> [Category]
    entryCategories Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (EntryContent -> Element) -> Maybe EntryContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb EntryContent -> Element
    xmlContent (Entry -> Maybe EntryContent
    entryContent Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Person -> Element) -> [Person] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Person -> Element
    xmlContributor (Entry -> [Person]
    entryContributor Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Link -> Element) -> [Link] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Link -> Element
    xmlLink (Entry -> [Link]
    entryLinks Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlPublished (Entry -> Maybe Text
    entryPublished Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlRights (Entry -> Maybe TextContent
    entryRights Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (Source -> Element) -> Maybe Source -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Source -> Element
    xmlSource (Entry -> Maybe Source
    entrySource Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlSummary (Entry -> Maybe TextContent
    entrySummary Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
       (InReplyTo -> Element) -> Maybe InReplyTo -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb InReplyTo -> Element
    xmlInReplyTo (Entry -> Maybe InReplyTo
    entryInReplyTo Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (InReplyTotal -> Element) -> Maybe InReplyTotal -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb InReplyTotal -> Element
    xmlInReplyTotal (Entry -> Maybe InReplyTotal
    entryInReplyTotal Entry
    e) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Entry -> [Element]
    entryOther Entry
    e)
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = Entry -> [(Name, [Content])]
    entryAttrs Entry
    e}

    xmlContent :: EntryContent -> XML.Element
    xmlContent :: EntryContent -> Element
    xmlContent cont :: EntryContent
    cont =
      case EntryContent
    cont of
        TextContent t :: Text
    t -> (Text -> Text -> Element
    atomLeaf "content" Text
    t) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "text"]}
        HTMLContent t :: Text
    t -> (Text -> Text -> Element
    atomLeaf "content" Text
    t) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "html"]}
        XHTMLContent x :: Element
    x ->
          (Text -> [Node] -> Element
    atomNode "content" [Element -> Node
    NodeElement Element
    x]) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "xhtml"]}
        MixedContent mbTy :: Maybe Text
    mbTy cs :: [Node]
    cs -> (Text -> [Node] -> Element
    atomNode "content" [Node]
    cs) {elementAttributes :: [(Name, [Content])]
    elementAttributes = (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "type") Maybe Text
    mbTy}
        ExternalContent mbTy :: Maybe Text
    mbTy src :: Text
    src ->
          (Text -> [Node] -> Element
    atomNode "content" []) {elementAttributes :: [(Name, [Content])]
    elementAttributes = Text -> Text -> (Name, [Content])
    atomAttr "src" Text
    src (Name, [Content]) -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. a -> [a] -> [a]
    : (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "type") Maybe Text
    mbTy}

    xmlCategory :: Category -> XML.Element
    xmlCategory :: Category -> Element
    xmlCategory c :: Category
    c =
      (Text -> [Node] -> Element
    atomNode "category" ((Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement (Category -> [Element]
    catOther Category
    c)))
        { elementAttributes :: [(Name, [Content])]
    elementAttributes =
            [Text -> Text -> (Name, [Content])
    atomAttr "term" (Category -> Text
    catTerm Category
    c)] [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "scheme") (Category -> Maybe Text
    catScheme Category
    c) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "label") (Category -> Maybe Text
    catLabel Category
    c)
        }

    xmlLink :: Link -> XML.Element
    xmlLink :: Link -> Element
    xmlLink l :: Link
    l =
      (Text -> [Node] -> Element
    atomNode "link" ((Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement (Link -> [Element]
    linkOther Link
    l)))
        { elementAttributes :: [(Name, [Content])]
    elementAttributes =
            [Text -> Text -> (Name, [Content])
    atomAttr "href" (Link -> Text
    linkHref Link
    l)] [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Either Text Text -> (Name, [Content]))
    -> Maybe (Either Text Text) -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "rel" (Text -> (Name, [Content]))
    -> (Either Text Text -> Text)
    -> Either Text Text
    -> (Name, [Content])
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Text -> Text) -> (Text -> Text) -> Either Text Text -> Text
    forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
    either Text -> Text
    forall a. a -> a
    id Text -> Text
    forall a. a -> a
    id) (Link -> Maybe (Either Text Text)
    linkRel Link
    l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "type") (Link -> Maybe Text
    linkType Link
    l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "hreflang") (Link -> Maybe Text
    linkHrefLang Link
    l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "title") (Link -> Maybe Text
    linkTitle Link
    l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "length") (Link -> Maybe Text
    linkLength Link
    l) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++ Link -> [(Name, [Content])]
    linkAttrs Link
    l
        }

    xmlSource :: Source -> Element
    xmlSource :: Source -> Element
    xmlSource s :: Source
    s =
      Text -> [Node] -> Element
    atomNode "source" ([Node] -> Element) -> [Node] -> Element
    forall a b. (a -> b) -> a -> b
    $
      (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
    forall a b. (a -> b) -> a -> b
    $
      Source -> [Element]
    sourceOther Source
    s [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Person -> Element) -> [Person] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Person -> Element
    xmlAuthor (Source -> [Person]
    sourceAuthors Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Category -> Element) -> [Category] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Category -> Element
    xmlCategory (Source -> [Category]
    sourceCategories Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Generator -> Element) -> Maybe Generator -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Generator -> Element
    xmlGenerator (Source -> Maybe Generator
    sourceGenerator Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlIcon (Source -> Maybe Text
    sourceIcon Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlId (Source -> Maybe Text
    sourceId Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Link -> Element) -> [Link] -> [Element]
    forall a b. (a -> b) -> [a] -> [b]
    map Link -> Element
    xmlLink (Source -> [Link]
    sourceLinks Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlLogo (Source -> Maybe Text
    sourceLogo Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlRights (Source -> Maybe TextContent
    sourceRights Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlSubtitle (Source -> Maybe TextContent
    sourceSubtitle Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (TextContent -> Element) -> Maybe TextContent -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb TextContent -> Element
    xmlTitle (Source -> Maybe TextContent
    sourceTitle Source
    s) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb Text -> Element
    xmlUpdated (Source -> Maybe Text
    sourceUpdated Source
    s)

    xmlGenerator :: Generator -> Element
    xmlGenerator :: Generator -> Element
    xmlGenerator g :: Generator
    g =
      (Text -> Text -> Element
    atomLeaf "generator" (Generator -> Text
    genText Generator
    g))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "uri") (Generator -> Maybe Text
    genURI Generator
    g) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomAttr "version") (Generator -> Maybe Text
    genVersion Generator
    g)}

    xmlAuthor :: Person -> XML.Element
    xmlAuthor :: Person -> Element
    xmlAuthor p :: Person
    p = Text -> [Node] -> Element
    atomNode "author" (Person -> [Node]
    xmlPerson Person
    p)

    xmlContributor :: Person -> XML.Element
    xmlContributor :: Person -> Element
    xmlContributor c :: Person
    c = Text -> [Node] -> Element
    atomNode "contributor" (Person -> [Node]
    xmlPerson Person
    c)

    xmlPerson :: Person -> [XML.Node]
    xmlPerson :: Person -> [Node]
    xmlPerson p :: Person
    p =
      (Element -> Node) -> [Element] -> [Node]
    forall a b. (a -> b) -> [a] -> [b]
    map Element -> Node
    NodeElement ([Element] -> [Node]) -> [Element] -> [Node]
    forall a b. (a -> b) -> a -> b
    $
      [Text -> Text -> Element
    atomLeaf "name" (Person -> Text
    personName Person
    p)] [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++
      (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> Element
    atomLeaf "uri") (Person -> Maybe Text
    personURI Person
    p) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ (Text -> Element) -> Maybe Text -> [Element]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> Element
    atomLeaf "email") (Person -> Maybe Text
    personEmail Person
    p) [Element] -> [Element] -> [Element]
    forall a. [a] -> [a] -> [a]
    ++ Person -> [Element]
    personOther Person
    p

    xmlInReplyTo :: InReplyTo -> XML.Element
    xmlInReplyTo :: InReplyTo -> Element
    xmlInReplyTo irt :: InReplyTo
    irt =
      (Text -> [Node] -> Element
    atomThreadNode "in-reply-to" (InReplyTo -> [Node]
    replyToContent InReplyTo
    irt))
        { elementAttributes :: [(Name, [Content])]
    elementAttributes =
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomThreadAttr "ref") (Text -> Maybe Text
    forall a. a -> Maybe a
    Just (Text -> Maybe Text) -> Text -> Maybe Text
    forall a b. (a -> b) -> a -> b
    $ InReplyTo -> Text
    replyToRef InReplyTo
    irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomThreadAttr "href") (InReplyTo -> Maybe Text
    replyToHRef InReplyTo
    irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomThreadAttr "type") (InReplyTo -> Maybe Text
    replyToType InReplyTo
    irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++
            (Text -> (Name, [Content])) -> Maybe Text -> [(Name, [Content])]
    forall a b. (a -> b) -> Maybe a -> [b]
    mb (Text -> Text -> (Name, [Content])
    atomThreadAttr "source") (InReplyTo -> Maybe Text
    replyToSource InReplyTo
    irt) [(Name, [Content])] -> [(Name, [Content])] -> [(Name, [Content])]
    forall a. [a] -> [a] -> [a]
    ++ InReplyTo -> [(Name, [Content])]
    replyToOther InReplyTo
    irt
        }

    xmlInReplyTotal :: InReplyTotal -> XML.Element
    xmlInReplyTotal :: InReplyTotal -> Element
    xmlInReplyTotal irt :: InReplyTotal
    irt =
      (Text -> Text -> Element
    atomThreadLeaf "total" (String -> Text
    pack (String -> Text) -> String -> Text
    forall a b. (a -> b) -> a -> b
    $ Integer -> String
    forall a. Show a => a -> String
    show (Integer -> String) -> Integer -> String
    forall a b. (a -> b) -> a -> b
    $ InReplyTotal -> Integer
    replyToTotal InReplyTotal
    irt))
        {elementAttributes :: [(Name, [Content])]
    elementAttributes = InReplyTotal -> [(Name, [Content])]
    replyToTotalOther InReplyTotal
    irt}

    xmlId :: Text -> XML.Element
    xmlId :: Text -> Element
    xmlId = Text -> Text -> Element
    atomLeaf "id"

    xmlIcon :: URI -> XML.Element
    xmlIcon :: Text -> Element
    xmlIcon = Text -> Text -> Element
    atomLeaf "icon"

    xmlLogo :: URI -> XML.Element
    xmlLogo :: Text -> Element
    xmlLogo = Text -> Text -> Element
    atomLeaf "logo"

    xmlUpdated :: Date -> XML.Element
    xmlUpdated :: Text -> Element
    xmlUpdated = Text -> Text -> Element
    atomLeaf "updated"

    xmlPublished :: Date -> XML.Element
    xmlPublished :: Text -> Element
    xmlPublished = Text -> Text -> Element
    atomLeaf "published"

    xmlRights :: TextContent -> XML.Element
    xmlRights :: TextContent -> Element
    xmlRights = Text -> TextContent -> Element
    xmlTextContent "rights"

    xmlTitle :: TextContent -> XML.Element
    xmlTitle :: TextContent -> Element
    xmlTitle = Text -> TextContent -> Element
    xmlTextContent "title"

    xmlSubtitle :: TextContent -> XML.Element
    xmlSubtitle :: TextContent -> Element
    xmlSubtitle = Text -> TextContent -> Element
    xmlTextContent "subtitle"

    xmlSummary :: TextContent -> XML.Element
    xmlSummary :: TextContent -> Element
    xmlSummary = Text -> TextContent -> Element
    xmlTextContent "summary"

    xmlTextContent :: Text -> TextContent -> XML.Element
    xmlTextContent :: Text -> TextContent -> Element
    xmlTextContent tg :: Text
    tg t :: TextContent
    t =
      case TextContent
    t of
        TextString s :: Text
    s -> (Text -> Text -> Element
    atomLeaf Text
    tg Text
    s) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "text"]}
        HTMLString s :: Text
    s -> (Text -> Text -> Element
    atomLeaf Text
    tg Text
    s) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "html"]}
        XHTMLString e :: Element
    e ->
          (Text -> [Node] -> Element
    atomNode Text
    tg [Element -> Node
    XML.NodeElement Element
    e]) {elementAttributes :: [(Name, [Content])]
    elementAttributes = [Text -> Text -> (Name, [Content])
    atomAttr "type" "xhtml"]}

    --------------------------------------------------------------------------------
    mb :: (a -> b) -> Maybe a -> [b]
    mb :: (a -> b) -> Maybe a -> [b]
    mb _ Nothing = []
    mb f :: a -> b
    f (Just x :: a
    x) = [a -> b
    f a
    x]