{-# LANGUAGE Arrows #-}
module Codec.Epub.Parse.Guide
( guideP
)
where
import Control.Arrow.ListArrows
import Data.Tree.NTree.TypeDefs ( NTree )
import Text.XML.HXT.Arrow.XmlArrow
import Text.XML.HXT.DOM.TypeDefs
import Codec.Epub.Data.Guide
import Codec.Epub.Parse.Util
guideRefP :: (ArrowXml a) => a (NTree XNode) GuideRef
guideRefP :: forall (a :: * -> * -> *). ArrowXml a => a (NTree XNode) GuideRef
guideRefP = forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"reference") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>>
proc NTree XNode
x -> do
String
t <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"type" -< NTree XNode
x
Maybe String
mt <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) (Maybe String)
mbGetAttrValue String
"title" -< NTree XNode
x
String
h <- forall (a :: * -> * -> *).
ArrowXml a =>
String -> a (NTree XNode) String
getAttrValue String
"href" -< NTree XNode
x
forall (a :: * -> * -> *) b. Arrow a => a b b
returnA -< String -> Maybe String -> String -> GuideRef
GuideRef String
t Maybe String
mt String
h
guideP :: (ArrowXml a) => a (NTree XNode) [GuideRef]
guideP :: forall (a :: * -> * -> *). ArrowXml a => a (NTree XNode) [GuideRef]
guideP = (forall (a :: * -> * -> *).
ArrowXml a =>
QName -> a (NTree XNode) (NTree XNode)
atQTag (String -> QName
opfName String
"guide") forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> forall (a :: * -> * -> *) b c. ArrowList a => a b c -> a b [c]
listA forall (a :: * -> * -> *). ArrowXml a => a (NTree XNode) GuideRef
guideRefP)
forall (a :: * -> * -> *) b c. ArrowIf a => a b c -> a b c -> a b c
`orElse` forall (a :: * -> * -> *) c b. ArrowList a => c -> a b c
constA []