-- | Parsing of documentation nodes.
module Data.GI.GIR.Documentation
    ( Documentation(..)
    , queryDocumentation
    ) where

import Data.Text (Text)
import Text.XML (Element)

import Data.GI.GIR.XMLUtils (firstChildWithLocalName, getElementContent,
                             lookupAttr)

-- | Documentation for a given element. The documentation text is
-- typically encoded in the gtk-doc format, see
-- https://developer.gnome.org/gtk-doc-manual/ . This can be parsed
-- with `Data.GI.GIR.parseGtkDoc`.
data Documentation = Documentation { Documentation -> Maybe Text
rawDocText   :: Maybe Text
                                   , Documentation -> Maybe Text
sinceVersion :: Maybe Text
                                   } deriving (Int -> Documentation -> ShowS
[Documentation] -> ShowS
Documentation -> String
(Int -> Documentation -> ShowS)
-> (Documentation -> String)
-> ([Documentation] -> ShowS)
-> Show Documentation
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Documentation -> ShowS
showsPrec :: Int -> Documentation -> ShowS
$cshow :: Documentation -> String
show :: Documentation -> String
$cshowList :: [Documentation] -> ShowS
showList :: [Documentation] -> ShowS
Show, Documentation -> Documentation -> Bool
(Documentation -> Documentation -> Bool)
-> (Documentation -> Documentation -> Bool) -> Eq Documentation
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Documentation -> Documentation -> Bool
== :: Documentation -> Documentation -> Bool
$c/= :: Documentation -> Documentation -> Bool
/= :: Documentation -> Documentation -> Bool
Eq, Eq Documentation
Eq Documentation
-> (Documentation -> Documentation -> Ordering)
-> (Documentation -> Documentation -> Bool)
-> (Documentation -> Documentation -> Bool)
-> (Documentation -> Documentation -> Bool)
-> (Documentation -> Documentation -> Bool)
-> (Documentation -> Documentation -> Documentation)
-> (Documentation -> Documentation -> Documentation)
-> Ord Documentation
Documentation -> Documentation -> Bool
Documentation -> Documentation -> Ordering
Documentation -> Documentation -> Documentation
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: Documentation -> Documentation -> Ordering
compare :: Documentation -> Documentation -> Ordering
$c< :: Documentation -> Documentation -> Bool
< :: Documentation -> Documentation -> Bool
$c<= :: Documentation -> Documentation -> Bool
<= :: Documentation -> Documentation -> Bool
$c> :: Documentation -> Documentation -> Bool
> :: Documentation -> Documentation -> Bool
$c>= :: Documentation -> Documentation -> Bool
>= :: Documentation -> Documentation -> Bool
$cmax :: Documentation -> Documentation -> Documentation
max :: Documentation -> Documentation -> Documentation
$cmin :: Documentation -> Documentation -> Documentation
min :: Documentation -> Documentation -> Documentation
Ord)

-- | Parse the documentation node for the given element of the GIR file.
queryDocumentation :: Element -> Documentation
queryDocumentation :: Element -> Documentation
queryDocumentation Element
element = Documentation {
  rawDocText :: Maybe Text
rawDocText = Text -> Element -> Maybe Element
firstChildWithLocalName Text
"doc" Element
element Maybe Element -> (Element -> Maybe Text) -> Maybe Text
forall a b. Maybe a -> (a -> Maybe b) -> Maybe b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Element -> Maybe Text
getElementContent,
  sinceVersion :: Maybe Text
sinceVersion = Name -> Element -> Maybe Text
lookupAttr Name
"version" Element
element
  }