{-# LANGUAGE CPP #-}
module Text.XML.HaXml.ShowXmlLazy (showXmlLazy) where
import Text.XML.HaXml.Types
import Text.XML.HaXml.Namespaces
import Text.XML.HaXml.TypeMapping
#if MIN_VERSION_base(4,11,0)
import Prelude hiding (maybe,either,(<>))
#else
import Prelude hiding (maybe,either)
#endif
import qualified Text.XML.HaXml.XmlContent as X
import Data.Maybe hiding (maybe)
import Data.List
showXmlLazy :: X.XmlContent a => Bool -> a -> String
showXmlLazy :: Bool -> a -> String
showXmlLazy dtd :: Bool
dtd x :: a
x =
case a -> [Content ()]
forall a. XmlContent a => a -> [Content ()]
X.toContents a
x of
[CElem _ _] -> Document () -> String
forall i. Document i -> String
document (Document () -> String) -> Document () -> String
forall a b. (a -> b) -> a -> b
$ Bool -> a -> Document ()
forall a. XmlContent a => Bool -> a -> Document ()
toXmlLazy Bool
dtd a
x
_ -> ""
toXmlLazy :: X.XmlContent a => Bool -> a -> Document ()
toXmlLazy :: Bool -> a -> Document ()
toXmlLazy dtd :: Bool
dtd value :: a
value =
let ht :: HType
ht = a -> HType
forall a. HTypeable a => a -> HType
toHType a
value in
Prolog -> SymTab EntityDef -> Element () -> [Misc] -> Document ()
forall i.
Prolog -> SymTab EntityDef -> Element i -> [Misc] -> Document i
Document (Maybe XMLDecl -> [Misc] -> Maybe DocTypeDecl -> [Misc] -> Prolog
Prolog (XMLDecl -> Maybe XMLDecl
forall a. a -> Maybe a
Just (String -> Maybe EncodingDecl -> Maybe Bool -> XMLDecl
XMLDecl "1.0" Maybe EncodingDecl
forall a. Maybe a
Nothing Maybe Bool
forall a. Maybe a
Nothing))
[] (if Bool
dtd then DocTypeDecl -> Maybe DocTypeDecl
forall a. a -> Maybe a
Just (HType -> DocTypeDecl
toDTD HType
ht) else Maybe DocTypeDecl
forall a. Maybe a
Nothing) [])
SymTab EntityDef
forall a. SymTab a
emptyST
( case (HType
ht, a -> [Content ()]
forall a. XmlContent a => a -> [Content ()]
X.toContents a
value) of
(Tuple _, cs :: [Content ()]
cs) -> QName -> [Attribute] -> [Content ()] -> Element ()
forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N (String -> QName) -> String -> QName
forall a b. (a -> b) -> a -> b
$ HType -> ShowS
showHType HType
ht "") [] [Content ()]
cs
(Defined _ _ _, cs :: [Content ()]
cs) -> QName -> [Attribute] -> [Content ()] -> Element ()
forall i. QName -> [Attribute] -> [Content i] -> Element i
Elem (String -> QName
N (String -> QName) -> String -> QName
forall a b. (a -> b) -> a -> b
$ HType -> ShowS
showHType HType
ht "-XML") [] [Content ()]
cs
(_, [CElem e :: Element ()
e ()]) -> Element ()
e )
[]
type Doc = String
empty :: [Char]
empty :: String
empty = ""
($$) :: [Char] -> [Char] -> [Char]
$$ :: String -> ShowS
($$) a :: String
a b :: String
b = String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ "\n" String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b
vcat :: [[Char]] -> [Char]
vcat :: [String] -> String
vcat a :: [String]
a = (String -> ShowS) -> String -> [String] -> String
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr String -> ShowS
($$) [] [String]
a
hcat :: [[a]] -> [a]
hcat :: [[a]] -> [a]
hcat = [[a]] -> [a]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
(<>) :: [a] -> [a] -> [a]
<> :: [a] -> [a] -> [a]
(<>) = [a] -> [a] -> [a]
forall a. [a] -> [a] -> [a]
(++)
(<+>) :: [Char] -> [Char] -> [Char]
<+> :: String -> ShowS
(<+>) a :: String
a b :: String
b = String
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ " " String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
b
fsep :: [[Char]] -> [Char]
fsep :: [String] -> String
fsep = [String] -> String
vcat
text :: t -> t
text :: t -> t
text string :: t
string = t
string
parens :: [Char] -> [Char]
parens :: ShowS
parens string :: String
string = "("String -> ShowS
forall a. [a] -> [a] -> [a]
++String
stringString -> ShowS
forall a. [a] -> [a] -> [a]
++")"
nest :: t -> t1 -> t1
nest :: t -> t1 -> t1
nest _ string :: t1
string = t1
string
either :: (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either :: (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either f :: t -> t1
f _ (Left x :: t
x) = t -> t1
f t
x
either _ g :: t2 -> t1
g (Right x :: t2
x) = t2 -> t1
g t2
x
maybe :: (t -> [Char]) -> Maybe t -> [Char]
maybe :: (t -> String) -> Maybe t -> String
maybe _ Nothing = String
empty
maybe f :: t -> String
f (Just x :: t
x) = t -> String
f t
x
document :: Document i -> Doc
prolog :: Prolog -> Doc
xmldecl :: XMLDecl -> Doc
misc :: Misc -> Doc
sddecl :: Bool -> Doc
doctypedecl :: DocTypeDecl -> Doc
markupdecl :: MarkupDecl -> Doc
cp :: CP -> Doc
element :: Element i -> Doc
attribute :: Attribute -> Doc
content :: Content i -> Doc
document :: Document i -> String
document (Document p :: Prolog
p _ e :: Element i
e m :: [Misc]
m)= Prolog -> String
prolog Prolog
p String -> ShowS
$$ Element i -> String
forall i. Element i -> String
element Element i
e String -> ShowS
$$ [String] -> String
vcat ((Misc -> String) -> [Misc] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m)
prolog :: Prolog -> String
prolog (Prolog x :: Maybe XMLDecl
x m1 :: [Misc]
m1 dtd :: Maybe DocTypeDecl
dtd m2 :: [Misc]
m2)= (XMLDecl -> String) -> Maybe XMLDecl -> String
forall t. (t -> String) -> Maybe t -> String
maybe XMLDecl -> String
xmldecl Maybe XMLDecl
x String -> ShowS
$$
[String] -> String
vcat ((Misc -> String) -> [Misc] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m1) String -> ShowS
$$
(DocTypeDecl -> String) -> Maybe DocTypeDecl -> String
forall t. (t -> String) -> Maybe t -> String
maybe DocTypeDecl -> String
doctypedecl Maybe DocTypeDecl
dtd String -> ShowS
$$
[String] -> String
vcat ((Misc -> String) -> [Misc] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> String
misc [Misc]
m2)
xmldecl :: XMLDecl -> String
xmldecl (XMLDecl v :: String
v e :: Maybe EncodingDecl
e sd :: Maybe Bool
sd) = ShowS
forall t. t -> t
text "<?xml version='" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
v String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "'" String -> ShowS
<+>
(EncodingDecl -> String) -> Maybe EncodingDecl -> String
forall t. (t -> String) -> Maybe t -> String
maybe EncodingDecl -> String
encodingdecl Maybe EncodingDecl
e String -> ShowS
<+>
(Bool -> String) -> Maybe Bool -> String
forall t. (t -> String) -> Maybe t -> String
maybe Bool -> String
sddecl Maybe Bool
sd String -> ShowS
<+>
ShowS
forall t. t -> t
text "?>"
misc :: Misc -> String
misc (Comment s :: String
s) = ShowS
forall t. t -> t
text "<!--" String -> ShowS
<+> ShowS
forall t. t -> t
text String
s String -> ShowS
<+> ShowS
forall t. t -> t
text "-->"
misc (PI (n :: String
n,s :: String
s)) = ShowS
forall t. t -> t
text "<?" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
n String -> ShowS
<+> ShowS
forall t. t -> t
text String
s String -> ShowS
<+> ShowS
forall t. t -> t
text "?>"
sddecl :: Bool -> String
sddecl sd :: Bool
sd | Bool
sd = ShowS
forall t. t -> t
text "standalone='yes'"
| Bool
otherwise = ShowS
forall t. t -> t
text "standalone='no'"
doctypedecl :: DocTypeDecl -> String
doctypedecl (DTD n :: QName
n eid :: Maybe ExternalID
eid ds :: [MarkupDecl]
ds) = if [MarkupDecl] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [MarkupDecl]
ds then
String
hd String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ">"
else String
hd String -> ShowS
<+> ShowS
forall t. t -> t
text " [" String -> ShowS
$$
[String] -> String
vcat ((MarkupDecl -> String) -> [MarkupDecl] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map MarkupDecl -> String
markupdecl [MarkupDecl]
ds) String -> ShowS
$$ ShowS
forall t. t -> t
text "]>"
where hd :: String
hd = ShowS
forall t. t -> t
text "<!DOCTYPE" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
(ExternalID -> String) -> Maybe ExternalID -> String
forall t. (t -> String) -> Maybe t -> String
maybe ExternalID -> String
externalid Maybe ExternalID
eid
markupdecl :: MarkupDecl -> String
markupdecl (Element e :: ElementDecl
e) = ElementDecl -> String
elementdecl ElementDecl
e
markupdecl (AttList a :: AttListDecl
a) = AttListDecl -> String
attlistdecl AttListDecl
a
markupdecl (Entity e :: EntityDecl
e) = EntityDecl -> String
entitydecl EntityDecl
e
markupdecl (Notation n :: NotationDecl
n) = NotationDecl -> String
notationdecl NotationDecl
n
markupdecl (MarkupMisc m :: Misc
m) = Misc -> String
misc Misc
m
element :: Element i -> String
element (Elem n :: QName
n as :: [Attribute]
as []) = ShowS
forall t. t -> t
text "<" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+>
[String] -> String
fsep ((Attribute -> String) -> [Attribute] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "/>"
element e :: Element i
e@(Elem n :: QName
n as :: [Attribute]
as cs :: [Content i]
cs)
| Content i -> Bool
forall t. Content t -> Bool
isText ([Content i] -> Content i
forall a. [a] -> a
head [Content i]
cs) = ShowS
forall t. t -> t
text "<" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep ((Attribute -> String) -> [Attribute] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text ">" String -> ShowS
forall a. [a] -> [a] -> [a]
<> [String] -> String
forall a. [[a]] -> [a]
hcat ((Content i -> String) -> [Content i] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Content i -> String
forall i. Content i -> String
content [Content i]
cs) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text "</" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ">"
| Bool
otherwise = let (d :: String
d,c :: String
c) = Element i -> String -> (String, String)
forall t. Element t -> String -> (String, String)
carryelem Element i
e String
empty
in String
d String -> ShowS
forall a. [a] -> [a] -> [a]
<> String
c
isText :: Content t -> Bool
isText :: Content t -> Bool
isText (CString _ _ _) = Bool
True
isText (CRef _ _) = Bool
True
isText _ = Bool
False
carryelem :: Element t -> String -> (String, String)
carryelem (Elem n :: QName
n as :: [Attribute]
as []) c :: String
c
= ( String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text "<" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep ((Attribute -> String) -> [Attribute] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as)
, ShowS
forall t. t -> t
text "/>")
carryelem (Elem n :: QName
n as :: [Attribute]
as cs :: [Content t]
cs) c :: String
c
| Bool
otherwise = let (cs0 :: [String]
cs0,d0 :: String
d0) = (Content t -> String -> (String, String))
-> [Content t] -> String -> ([String], String)
forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan Content t -> String -> (String, String)
forall t. Content t -> String -> (String, String)
carrycontent [Content t]
cs (ShowS
forall t. t -> t
text ">")
in
( String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text "<" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n String -> ShowS
<+> [String] -> String
fsep ((Attribute -> String) -> [Attribute] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> String
attribute [Attribute]
as) String -> ShowS
$$
Int -> ShowS
forall t t1. t -> t1 -> t1
nest (2 :: Int) ([String] -> String
vcat [String]
cs0) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
String
d0 String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "</" String -> ShowS
forall a. [a] -> [a] -> [a]
<> QName -> String
qname QName
n
, ShowS
forall t. t -> t
text ">")
carrycontent :: Content t -> [Char] -> ([Char], [Char])
carryelem :: Element t -> [Char] -> ([Char], [Char])
carrycontent :: Content t -> String -> (String, String)
carrycontent (CElem e :: Element t
e _) c :: String
c = Element t -> String -> (String, String)
forall t. Element t -> String -> (String, String)
carryelem Element t
e String
c
carrycontent (CString False s :: String
s _) c :: String
c = (String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
chardata String
s, String
empty)
carrycontent (CString True s :: String
s _) c :: String
c = (String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
cdsect String
s, String
empty)
carrycontent (CRef r :: Reference
r _) c :: String
c = (String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<> Reference -> String
reference Reference
r, String
empty)
carrycontent (CMisc m :: Misc
m _) c :: String
c = (String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<> Misc -> String
misc Misc
m, String
empty)
carryscan :: (a->c->(b,c)) -> [a] -> c -> ([b],c)
carryscan :: (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan _ [] c :: c
c = ([],c
c)
carryscan f :: a -> c -> (b, c)
f (a :: a
a:as :: [a]
as) c :: c
c = let (b :: b
b, c0 :: c
c0) = a -> c -> (b, c)
f a
a c
c
(bs :: [b]
bs,c1 :: c
c1) = (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
forall a c b. (a -> c -> (b, c)) -> [a] -> c -> ([b], c)
carryscan a -> c -> (b, c)
f [a]
as c
c0
in (b
bb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
bs, c
c1)
attribute :: Attribute -> String
attribute (n :: QName
n,v :: AttValue
v) = QName -> String
qname QName
n String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "=" String -> ShowS
forall a. [a] -> [a] -> [a]
<> AttValue -> String
attvalue AttValue
v
content :: Content i -> String
content (CElem e :: Element i
e _) = Element i -> String
forall i. Element i -> String
element Element i
e
content (CString False s :: String
s _) = ShowS
forall t. t -> t
chardata String
s
content (CString True s :: String
s _) = ShowS
cdsect String
s
content (CRef r :: Reference
r _) = Reference -> String
reference Reference
r
content (CMisc m :: Misc
m _) = Misc -> String
misc Misc
m
elementdecl :: ElementDecl -> [Char]
elementdecl :: ElementDecl -> String
elementdecl (ElementDecl n :: QName
n cs :: ContentSpec
cs) = ShowS
forall t. t -> t
text "<!ELEMENT" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
ContentSpec -> String
contentspec ContentSpec
cs String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ">"
contentspec :: ContentSpec -> [Char]
contentspec :: ContentSpec -> String
contentspec EMPTY = ShowS
forall t. t -> t
text "EMPTY"
contentspec ANY = ShowS
forall t. t -> t
text "ANY"
contentspec (Mixed m :: Mixed
m) = Mixed -> String
mixed Mixed
m
contentspec (ContentSpec c :: CP
c) = CP -> String
cp CP
c
cp :: CP -> String
cp (TagName n :: QName
n m :: Modifier
m) = QName -> String
qname QName
n String -> ShowS
forall a. [a] -> [a] -> [a]
<> Modifier -> String
modifier Modifier
m
cp (Choice cs :: [CP]
cs m :: Modifier
m) = ShowS
parens ([String] -> String
forall a. [[a]] -> [a]
hcat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse (ShowS
forall t. t -> t
text "|") ((CP -> String) -> [CP] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map CP -> String
cp [CP]
cs))) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
Modifier -> String
modifier Modifier
m
cp (Seq cs :: [CP]
cs m :: Modifier
m) = ShowS
parens ([String] -> String
forall a. [[a]] -> [a]
hcat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse (ShowS
forall t. t -> t
text ",") ((CP -> String) -> [CP] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map CP -> String
cp [CP]
cs))) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
Modifier -> String
modifier Modifier
m
modifier :: Modifier -> [Char]
modifier :: Modifier -> String
modifier None = String
empty
modifier Query = ShowS
forall t. t -> t
text "?"
modifier Star = ShowS
forall t. t -> t
text "*"
modifier Plus = ShowS
forall t. t -> t
text "+"
mixed :: Mixed -> [Char]
mixed :: Mixed -> String
mixed PCDATA = ShowS
forall t. t -> t
text "(#PCDATA)"
mixed (PCDATAplus ns :: [QName]
ns) = ShowS
forall t. t -> t
text "(#PCDATA |" String -> ShowS
<+>
[String] -> String
forall a. [[a]] -> [a]
hcat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse (ShowS
forall t. t -> t
text "|") ((QName -> String) -> [QName] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map QName -> String
qname [QName]
ns)) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text ")*"
attlistdecl :: AttListDecl -> [Char]
attlistdecl :: AttListDecl -> String
attlistdecl (AttListDecl n :: QName
n ds :: [AttDef]
ds) = ShowS
forall t. t -> t
text "<!ATTLIST" String -> ShowS
<+> QName -> String
qname QName
n String -> ShowS
<+>
[String] -> String
fsep ((AttDef -> String) -> [AttDef] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map AttDef -> String
attdef [AttDef]
ds) String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ">"
attdef :: AttDef -> [Char]
attdef :: AttDef -> String
attdef (AttDef n :: QName
n t :: AttType
t d :: DefaultDecl
d) = QName -> String
qname QName
n String -> ShowS
<+> AttType -> String
atttype AttType
t String -> ShowS
<+> DefaultDecl -> String
defaultdecl DefaultDecl
d
atttype :: AttType -> [Char]
atttype :: AttType -> String
atttype StringType = ShowS
forall t. t -> t
text "CDATA"
atttype (TokenizedType t :: TokenizedType
t) = TokenizedType -> String
tokenizedtype TokenizedType
t
atttype (EnumeratedType t :: EnumeratedType
t) = EnumeratedType -> String
enumeratedtype EnumeratedType
t
tokenizedtype :: TokenizedType -> [Char]
tokenizedtype :: TokenizedType -> String
tokenizedtype ID = ShowS
forall t. t -> t
text "ID"
tokenizedtype IDREF = ShowS
forall t. t -> t
text "IDREF"
tokenizedtype IDREFS = ShowS
forall t. t -> t
text "IDREFS"
tokenizedtype ENTITY = ShowS
forall t. t -> t
text "ENTITY"
tokenizedtype ENTITIES = ShowS
forall t. t -> t
text "ENTITIES"
tokenizedtype NMTOKEN = ShowS
forall t. t -> t
text "NMTOKEN"
tokenizedtype NMTOKENS = ShowS
forall t. t -> t
text "NMTOKENS"
enumeratedtype :: EnumeratedType -> [Char]
enumeratedtype :: EnumeratedType -> String
enumeratedtype (NotationType n :: [String]
n)= [String] -> String
notationtype [String]
n
enumeratedtype (Enumeration e :: [String]
e) = [String] -> String
enumeration [String]
e
notationtype :: [[Char]] -> [Char]
notationtype :: [String] -> String
notationtype ns :: [String]
ns = ShowS
forall t. t -> t
text "NOTATION" String -> ShowS
<+>
ShowS
parens ([String] -> String
forall a. [[a]] -> [a]
hcat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse (ShowS
forall t. t -> t
text "|") (ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShowS
forall t. t -> t
text [String]
ns)))
enumeration :: [[Char]] -> [Char]
enumeration :: [String] -> String
enumeration ns :: [String]
ns = ShowS
parens ([String] -> String
forall a. [[a]] -> [a]
hcat (String -> [String] -> [String]
forall a. a -> [a] -> [a]
intersperse (ShowS
forall t. t -> t
text "|") (ShowS -> [String] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map ShowS
forall t. t -> t
nmtoken [String]
ns)))
defaultdecl :: DefaultDecl -> [Char]
defaultdecl :: DefaultDecl -> String
defaultdecl REQUIRED = ShowS
forall t. t -> t
text "#REQUIRED"
defaultdecl IMPLIED = ShowS
forall t. t -> t
text "#IMPLIED"
defaultdecl (DefaultTo a :: AttValue
a f :: Maybe FIXED
f) = (FIXED -> String) -> Maybe FIXED -> String
forall t. (t -> String) -> Maybe t -> String
maybe (String -> FIXED -> String
forall a b. a -> b -> a
const (ShowS
forall t. t -> t
text "#FIXED")) Maybe FIXED
f String -> ShowS
<+> AttValue -> String
attvalue AttValue
a
reference :: Reference -> [Char]
reference :: Reference -> String
reference (RefEntity er :: String
er) = ShowS
entityref String
er
reference (RefChar cr :: Int
cr) = Int -> String
forall a. Show a => a -> String
charref Int
cr
entityref :: [Char] -> [Char]
entityref :: ShowS
entityref n :: String
n = ShowS
forall t. t -> t
text "&" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
n String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ";"
charref :: (Show a) => a -> [Char]
charref :: a -> String
charref c :: a
c = ShowS
forall t. t -> t
text "&#" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text (a -> String
forall a. Show a => a -> String
show a
c) String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text ";"
entitydecl :: EntityDecl -> [Char]
entitydecl :: EntityDecl -> String
entitydecl (EntityGEDecl d :: GEDecl
d) = GEDecl -> String
gedecl GEDecl
d
entitydecl (EntityPEDecl d :: PEDecl
d) = PEDecl -> String
pedecl PEDecl
d
gedecl :: GEDecl -> [Char]
gedecl :: GEDecl -> String
gedecl (GEDecl n :: String
n ed :: EntityDef
ed) = ShowS
forall t. t -> t
text "<!ENTITY" String -> ShowS
<+> ShowS
forall t. t -> t
text String
n String -> ShowS
<+> EntityDef -> String
entitydef EntityDef
ed String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text ">"
pedecl :: PEDecl -> [Char]
pedecl :: PEDecl -> String
pedecl (PEDecl n :: String
n pd :: PEDef
pd) = ShowS
forall t. t -> t
text "<!ENTITY %" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
n String -> ShowS
<+> PEDef -> String
pedef PEDef
pd String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text ">"
entitydef :: EntityDef -> [Char]
entitydef :: EntityDef -> String
entitydef (DefEntityValue ew :: EntityValue
ew) = EntityValue -> String
entityvalue EntityValue
ew
entitydef (DefExternalID i :: ExternalID
i nd :: Maybe NDataDecl
nd) = ExternalID -> String
externalid ExternalID
i String -> ShowS
<+> (NDataDecl -> String) -> Maybe NDataDecl -> String
forall t. (t -> String) -> Maybe t -> String
maybe NDataDecl -> String
ndatadecl Maybe NDataDecl
nd
pedef :: PEDef -> [Char]
pedef :: PEDef -> String
pedef (PEDefEntityValue ew :: EntityValue
ew) = EntityValue -> String
entityvalue EntityValue
ew
pedef (PEDefExternalID eid :: ExternalID
eid) = ExternalID -> String
externalid ExternalID
eid
externalid :: ExternalID -> [Char]
externalid :: ExternalID -> String
externalid (SYSTEM sl :: SystemLiteral
sl) = ShowS
forall t. t -> t
text "SYSTEM" String -> ShowS
<+> SystemLiteral -> String
systemliteral SystemLiteral
sl
externalid (PUBLIC i :: PubidLiteral
i sl :: SystemLiteral
sl) = ShowS
forall t. t -> t
text "PUBLIC" String -> ShowS
<+> PubidLiteral -> String
pubidliteral PubidLiteral
i String -> ShowS
<+>
SystemLiteral -> String
systemliteral SystemLiteral
sl
ndatadecl :: NDataDecl -> [Char]
ndatadecl :: NDataDecl -> String
ndatadecl (NDATA n :: String
n) = ShowS
forall t. t -> t
text "NDATA" String -> ShowS
<+> ShowS
forall t. t -> t
text String
n
notationdecl :: NotationDecl -> [Char]
notationdecl :: NotationDecl -> String
notationdecl (NOTATION n :: String
n e :: Either ExternalID PublicID
e) = ShowS
forall t. t -> t
text "<!NOTATION" String -> ShowS
<+> ShowS
forall t. t -> t
text String
n String -> ShowS
<+>
(ExternalID -> String)
-> (PublicID -> String) -> Either ExternalID PublicID -> String
forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either ExternalID -> String
externalid PublicID -> String
publicid Either ExternalID PublicID
e String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text ">"
publicid :: PublicID -> [Char]
publicid :: PublicID -> String
publicid (PUBLICID p :: PubidLiteral
p) = ShowS
forall t. t -> t
text "PUBLICID" String -> ShowS
<+> PubidLiteral -> String
pubidliteral PubidLiteral
p
encodingdecl :: EncodingDecl -> [Char]
encodingdecl :: EncodingDecl -> String
encodingdecl (EncodingDecl s :: String
s) = ShowS
forall t. t -> t
text "encoding='" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
s String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "'"
nmtoken :: t -> t
nmtoken :: t -> t
nmtoken s :: t
s = t -> t
forall t. t -> t
text t
s
attvalue :: AttValue -> [Char]
attvalue :: AttValue -> String
attvalue (AttValue esr :: [Either String Reference]
esr) = ShowS
forall t. t -> t
text "\"" String -> ShowS
forall a. [a] -> [a] -> [a]
<>
[String] -> String
forall a. [[a]] -> [a]
hcat ((Either String Reference -> String)
-> [Either String Reference] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (ShowS -> (Reference -> String) -> Either String Reference -> String
forall t t1 t2. (t -> t1) -> (t2 -> t1) -> Either t t2 -> t1
either ShowS
forall t. t -> t
text Reference -> String
reference) [Either String Reference]
esr) String -> ShowS
forall a. [a] -> [a] -> [a]
<>
ShowS
forall t. t -> t
text "\""
entityvalue :: EntityValue -> [Char]
entityvalue :: EntityValue -> String
entityvalue (EntityValue evs :: [EV]
evs)
| [EV] -> Bool
containsDoubleQuote [EV]
evs = ShowS
forall t. t -> t
text "'" String -> ShowS
forall a. [a] -> [a] -> [a]
<> [String] -> String
forall a. [[a]] -> [a]
hcat ((EV -> String) -> [EV] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map EV -> String
ev [EV]
evs) String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "'"
| Bool
otherwise = ShowS
forall t. t -> t
text "\"" String -> ShowS
forall a. [a] -> [a] -> [a]
<> [String] -> String
forall a. [[a]] -> [a]
hcat ((EV -> String) -> [EV] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map EV -> String
ev [EV]
evs) String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "\""
ev :: EV -> String
ev :: EV -> String
ev (EVString s :: String
s) = ShowS
forall t. t -> t
text String
s
ev (EVRef r :: Reference
r) = Reference -> String
reference Reference
r
pubidliteral :: PubidLiteral -> [Char]
pubidliteral :: PubidLiteral -> String
pubidliteral (PubidLiteral s :: String
s)
| '"' Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s = ShowS
forall t. t -> t
text "'" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
s String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "'"
| Bool
otherwise = ShowS
forall t. t -> t
text "\"" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
s String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "\""
systemliteral :: SystemLiteral -> [Char]
systemliteral :: SystemLiteral -> String
systemliteral (SystemLiteral s :: String
s)
| '"' Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s = ShowS
forall t. t -> t
text "'" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
s String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "'"
| Bool
otherwise = ShowS
forall t. t -> t
text "\"" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text String
s String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "\""
chardata :: t -> t
chardata :: t -> t
chardata s :: t
s = t -> t
forall t. t -> t
text t
s
cdsect :: [Char] -> [Char]
cdsect :: ShowS
cdsect c :: String
c = ShowS
forall t. t -> t
text "<![CDATA[" String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
chardata String
c String -> ShowS
forall a. [a] -> [a] -> [a]
<> ShowS
forall t. t -> t
text "]]>"
qname :: QName -> String
qname n :: QName
n = ShowS
forall t. t -> t
text (QName -> String
printableName QName
n)
containsDoubleQuote :: [EV] -> Bool
containsDoubleQuote :: [EV] -> Bool
containsDoubleQuote evs :: [EV]
evs = (EV -> Bool) -> [EV] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any EV -> Bool
csq [EV]
evs
where csq :: EV -> Bool
csq (EVString s :: String
s) = '"' Char -> String -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` String
s
csq _ = Bool
False