aboutsummaryrefslogtreecommitdiff
path: root/Text/XML/Light.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-01 00:45:07 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2008-08-01 00:45:07 +0000
commit0c6dd105b73e95d61d3a3d3213d8f80f3d8a22d4 (patch)
treed8cad0cbbdc02fee41bd55ba9938371c8278cf18 /Text/XML/Light.hs
parent8440385f45e18f43172c0cf4409cf4b8b538bbeb (diff)
downloadpandoc-0c6dd105b73e95d61d3a3d3213d8f80f3d8a22d4.tar.gz
Added code for xml library (Text.XML.Light) to source tree,
since there is currently no debian package. Removed dependency on xml library. Added license to debian/copyright. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1351 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'Text/XML/Light.hs')
-rw-r--r--Text/XML/Light.hs96
1 files changed, 96 insertions, 0 deletions
diff --git a/Text/XML/Light.hs b/Text/XML/Light.hs
new file mode 100644
index 000000000..f2d75290b
--- /dev/null
+++ b/Text/XML/Light.hs
@@ -0,0 +1,96 @@
+{-# LANGUAGE FlexibleInstances #-}
+--------------------------------------------------------------------
+-- |
+-- Module : Text.XML.Light
+-- Copyright : (c) Galois, Inc. 2007
+-- License : BSD3
+--
+-- Maintainer: Iavor S. Diatchki <diatchki@galois.com>
+-- Stability : provisional
+-- Portability: portability
+--
+-- A lightweight XML parsing, filtering and generating library.
+--
+-- This module reexports functions from:
+--
+-- * "Text.XML.Light.Types"
+--
+-- * "Text.XML.Light.Proc"
+--
+-- * "Text.XML.Light.Input"
+--
+-- * "Text.XML.Light.Output"
+--
+
+module Text.XML.Light (
+
+ module Text.XML.Light,
+ module Text.XML.Light.Types,
+ module Text.XML.Light.Proc,
+ module Text.XML.Light.Input,
+ module Text.XML.Light.Output
+
+ ) where
+
+import Text.XML.Light.Types
+import Text.XML.Light.Proc
+import Text.XML.Light.Input
+import Text.XML.Light.Output
+
+-- | Add an attribute to an element.
+add_attr :: Attr -> Element -> Element
+add_attr a e = add_attrs [a] e
+
+-- | Add some attributes to an element.
+add_attrs :: [Attr] -> Element -> Element
+add_attrs as e = e { elAttribs = as ++ elAttribs e }
+
+-- | Create an unqualified name.
+unqual :: String -> QName
+unqual x = blank_name { qName = x }
+
+-- | A smart element constructor which uses the type of its argument
+-- to determine what sort of element to make.
+class Node t where
+ node :: QName -> t -> Element
+
+instance Node ([Attr],[Content]) where
+ node n (attrs,cont) = blank_element { elName = n
+ , elAttribs = attrs
+ , elContent = cont
+ }
+
+instance Node [Attr] where node n as = node n (as,[]::[Content])
+instance Node Attr where node n a = node n [a]
+instance Node () where node n () = node n ([]::[Attr])
+
+instance Node [Content] where node n cs = node n ([]::[Attr],cs)
+instance Node Content where node n c = node n [c]
+instance Node ([Attr],Content) where node n (as,c) = node n (as,[c])
+instance Node (Attr,Content) where node n (a,c) = node n ([a],[c])
+
+instance Node ([Attr],[Element]) where
+ node n (as,cs) = node n (as,map Elem cs)
+
+instance Node ([Attr],Element) where node n (as,c) = node n (as,[c])
+instance Node (Attr,Element) where node n (a,c) = node n ([a],c)
+instance Node ([Element]) where node n es = node n ([]::[Attr],es)
+instance Node (Element) where node n e = node n [e]
+
+instance Node ([Attr],[CData]) where
+ node n (as,cs) = node n (as,map Text cs)
+
+instance Node ([Attr],CData) where node n (as,c) = node n (as,[c])
+instance Node (Attr,CData) where node n (a,c) = node n ([a],c)
+instance Node [CData] where node n es = node n ([]::[Attr],es)
+instance Node CData where node n e = node n [e]
+
+instance Node ([Attr],String) where
+ node n (as,t) = node n (as,blank_cdata { cdData = t })
+
+instance Node (Attr,String) where node n (a,t) = node n ([a],t)
+instance Node [Char] where node n t = node n ([]::[Attr],t)
+
+-- | Create node with unqualified name
+unode :: Node t => String -> t -> Element
+unode = node . unqual