{-# LANGUAGE CPP #-}
-- | This is a separate pretty-printer for HTML documents, recognising
--   some of the differences between HTML and true XML.

module Text.XML.HaXml.Html.Pretty
  ( document
  , element
  , attribute
  , content
  ) where

#if MIN_VERSION_base(4,11,0)
import Prelude hiding (maybe,either,(<>))
#else
import Prelude hiding (maybe,either)
#endif

import Data.Maybe hiding (maybe)
import Data.List (intersperse)
import Data.Char (isSpace)
import Text.PrettyPrint.HughesPJ
import Text.XML.HaXml.Types
import Text.XML.HaXml.Namespaces

either :: (a->c) -> (b->c) -> Either a b -> c
either :: (a -> c) -> (b -> c) -> Either a b -> c
either  f :: a -> c
f _g :: b -> c
_g (Left x :: a
x)  = a -> c
f a
x
either _f :: a -> c
_f  g :: b -> c
g (Right x :: b
x) = b -> c
g b
x

maybe :: (a->Doc) -> Maybe a -> Doc
maybe :: (a -> Doc) -> Maybe a -> Doc
maybe _f :: a -> Doc
_f Nothing  = Doc
empty
maybe  f :: a -> Doc
f (Just x :: a
x) = a -> Doc
f a
x

--peref p   = text "%" <> text p <> text ";"

----

document :: Document i -> Doc
prolog   :: Prolog -> Doc
xmldecl  :: XMLDecl -> Doc
misc     :: Misc -> Doc
sddecl   :: Bool -> Doc

doctypedecl :: DocTypeDecl -> Doc
markupdecl  :: MarkupDecl -> Doc
--extsubset   :: ExtSubset -> Doc
--extsubsetdecl :: ExtSubsetDecl -> Doc

element   :: Element i -> Doc
attribute :: Attribute -> Doc                     --etc
content   :: Content i -> Doc

----

document :: Document i -> Doc
document (Document p :: Prolog
p _ e :: Element i
e m :: [Misc]
m)= Prolog -> Doc
prolog Prolog
p Doc -> Doc -> Doc
$$ Element i -> Doc
forall i. Element i -> Doc
element Element i
e Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat ((Misc -> Doc) -> [Misc] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> Doc
misc [Misc]
m)
prolog :: Prolog -> Doc
prolog (Prolog x :: Maybe XMLDecl
x m1 :: [Misc]
m1 dtd :: Maybe DocTypeDecl
dtd m2 :: [Misc]
m2)= (XMLDecl -> Doc) -> Maybe XMLDecl -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe XMLDecl -> Doc
xmldecl Maybe XMLDecl
x Doc -> Doc -> Doc
$$
                             [Doc] -> Doc
vcat ((Misc -> Doc) -> [Misc] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> Doc
misc [Misc]
m1) Doc -> Doc -> Doc
$$
                             (DocTypeDecl -> Doc) -> Maybe DocTypeDecl -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe DocTypeDecl -> Doc
doctypedecl Maybe DocTypeDecl
dtd Doc -> Doc -> Doc
$$
                             [Doc] -> Doc
vcat ((Misc -> Doc) -> [Misc] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Misc -> Doc
misc [Misc]
m2)
xmldecl :: XMLDecl -> Doc
xmldecl (XMLDecl v :: VersionInfo
v e :: Maybe EncodingDecl
e sd :: Maybe SDDecl
sd)   = VersionInfo -> Doc
text "<?xml version='" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
v Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "'" Doc -> Doc -> Doc
<+>
                             (EncodingDecl -> Doc) -> Maybe EncodingDecl -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe EncodingDecl -> Doc
encodingdecl Maybe EncodingDecl
e Doc -> Doc -> Doc
<+>
                             (SDDecl -> Doc) -> Maybe SDDecl -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe SDDecl -> Doc
sddecl Maybe SDDecl
sd Doc -> Doc -> Doc
<+>
                             VersionInfo -> Doc
text "?>"
misc :: Misc -> Doc
misc (Comment s :: VersionInfo
s)           = VersionInfo -> Doc
text "<!--" Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text VersionInfo
s Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text "-->"
misc (PI (n :: VersionInfo
n,s :: VersionInfo
s))            = VersionInfo -> Doc
text "<?" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
n Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text VersionInfo
s Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text "?>"
sddecl :: SDDecl -> Doc
sddecl sd :: SDDecl
sd   | SDDecl
sd           = VersionInfo -> Doc
text "standalone='yes'"
            | SDDecl
otherwise    = VersionInfo -> Doc
text "standalone='no'"
doctypedecl :: DocTypeDecl -> Doc
doctypedecl (DTD n :: QName
n eid :: Maybe ExternalID
eid ds :: [MarkupDecl]
ds) = if [MarkupDecl] -> SDDecl
forall (t :: * -> *) a. Foldable t => t a -> SDDecl
null [MarkupDecl]
ds then 
                                  Doc
hd Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ">"
                             else Doc
hd Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text " [" Doc -> Doc -> Doc
$$
                                  [Doc] -> Doc
vcat ((MarkupDecl -> Doc) -> [MarkupDecl] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map MarkupDecl -> Doc
markupdecl [MarkupDecl]
ds) Doc -> Doc -> Doc
$$ VersionInfo -> Doc
text "]>"
                           where hd :: Doc
hd = VersionInfo -> Doc
text "<!DOCTYPE" Doc -> Doc -> Doc
<+> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+>
                                      (ExternalID -> Doc) -> Maybe ExternalID -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe ExternalID -> Doc
externalid Maybe ExternalID
eid
markupdecl :: MarkupDecl -> Doc
markupdecl (Element e :: ElementDecl
e)     = ElementDecl -> Doc
elementdecl ElementDecl
e
markupdecl (AttList a :: AttListDecl
a)     = AttListDecl -> Doc
attlistdecl AttListDecl
a
markupdecl (Entity e :: EntityDecl
e)      = EntityDecl -> Doc
entitydecl EntityDecl
e
markupdecl (Notation n :: NotationDecl
n)    = NotationDecl -> Doc
notationdecl NotationDecl
n
markupdecl (MarkupMisc m :: Misc
m)  = Misc -> Doc
misc Misc
m
--markupdecl (MarkupPE p m)  = peref p

--extsubset (ExtSubset t ds) = maybe textdecl t $$
--                             vcat (map extsubsetdecl ds)
--extsubsetdecl (ExtMarkupDecl m)      = markupdecl m
--extsubsetdecl (ExtConditionalSect c) = conditionalsect c
-- --extsubsetdecl (ExtPEReference p e)   = peref p

element :: Element i -> Doc
element (Elem n :: QName
n as :: [Attribute]
as []) = VersionInfo -> Doc
text "<" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+>
                         [Doc] -> Doc
fsep ((Attribute -> Doc) -> [Attribute] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> Doc
attribute [Attribute]
as) Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "/>"
element e :: Element i
e@(Elem n :: QName
n as :: [Attribute]
as cs :: [Content i]
cs)
--  | any isText cs    = text "<" <> qname n <+> fsep (map attribute as) <>
--                       text ">" <> hcat (map content cs) <>
--                       text "</" <> qname n <> text ">"
    | Content i -> SDDecl
forall i. Content i -> SDDecl
isText ([Content i] -> Content i
forall a. [a] -> a
head [Content i]
cs) = VersionInfo -> Doc
text "<" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Attribute -> Doc) -> [Attribute] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> Doc
attribute [Attribute]
as) Doc -> Doc -> Doc
<>
                         VersionInfo -> Doc
text ">" Doc -> Doc -> Doc
<> [Doc] -> Doc
hcat ((Content i -> Doc) -> [Content i] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Content i -> Doc
forall i. Content i -> Doc
content [Content i]
cs) Doc -> Doc -> Doc
<>
                         VersionInfo -> Doc
text "</" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ">"
    | SDDecl
otherwise        = let (d :: Doc
d,c :: Doc
c) = Element i -> Doc -> (Doc, Doc)
forall i. Element i -> Doc -> (Doc, Doc)
carryelem Element i
e Doc
empty
                         in Doc
d Doc -> Doc -> Doc
<> Doc
c

isText :: Content i -> Bool
isText :: Content i -> SDDecl
isText (CString _ _ _) = SDDecl
True
isText (CRef _ _)      = SDDecl
True
isText _               = SDDecl
False

carryelem :: Element i -> Doc -> (Doc, Doc)
carryelem :: Element i -> Doc -> (Doc, Doc)
carryelem (Elem n :: QName
n as :: [Attribute]
as []) c :: Doc
c
                       = ( Doc
c Doc -> Doc -> Doc
<>
                           VersionInfo -> Doc
text "<" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Attribute -> Doc) -> [Attribute] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> Doc
attribute [Attribute]
as)
                         , VersionInfo -> Doc
text "/>")
--carryelem e@(Elem n as cs) c
----  | any isText cs    =  ( c <> element e, empty)
--    | otherwise        =  let (cs',d') = carryscan carrycontent cs (text ">")
--                          in
--                          ( c <>
--                            text "<" <> qname n <+> fsep (map attribute as) $$
--                            nest 2 (vcat cs') <> -- $$
--                            c' <> text "</" <> qname n
--                          , text ">")
--carrycontent (CElem e) c   = carryelem e c
--carrycontent (CString _ s) c = (c <> chardata s, empty)
--carrycontent (CRef r) c    = (c <> reference r, empty)
--carrycontent (CMisc m) c   = (c <> misc m, empty)
--
--carryscan :: (a->c->(b,c)) -> [a] -> c -> ([b],c)
--carryscan f []     c = ([],c)
--carryscan f (a:as) c = let (b, c')   = f a c
--                           (bs,c'') = carryscan f as c'
--                       in (b:bs, c'')

carryelem (Elem n :: QName
n as :: [Attribute]
as cs :: [Content i]
cs) c :: Doc
c
  | Content i -> SDDecl
forall i. Content i -> SDDecl
isText ([Content i] -> Content i
forall a. [a] -> a
head [Content i]
cs) =
        ( Doc
start Doc -> Doc -> Doc
<>
          VersionInfo -> Doc
text ">" Doc -> Doc -> Doc
<> [Doc] -> Doc
hcat ((Content i -> Doc) -> [Content i] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Content i -> Doc
forall i. Content i -> Doc
content [Content i]
cs) Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "</" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n
        , VersionInfo -> Doc
text ">")
  | SDDecl
otherwise =
        let (d :: Doc
d,c' :: Doc
c') = ((Doc, Doc) -> Content i -> (Doc, Doc))
-> (Doc, Doc) -> [Content i] -> (Doc, Doc)
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl (Doc, Doc) -> Content i -> (Doc, Doc)
forall i. (Doc, Doc) -> Content i -> (Doc, Doc)
carrycontent (Doc
start, VersionInfo -> Doc
text ">") [Content i]
cs in
        ( Doc
d Doc -> Doc -> Doc
<> Doc
c' Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "</" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n
        , VersionInfo -> Doc
text ">")
  where start :: Doc
start = Doc
c Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "<" Doc -> Doc -> Doc
<> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Attribute -> Doc) -> [Attribute] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Attribute -> Doc
attribute [Attribute]
as)

carrycontent :: (Doc, Doc) -> Content i -> (Doc, Doc)
carrycontent :: (Doc, Doc) -> Content i -> (Doc, Doc)
carrycontent (d :: Doc
d,c :: Doc
c) (CElem e :: Element i
e _)     = let (d' :: Doc
d',c' :: Doc
c') = Element i -> Doc -> (Doc, Doc)
forall i. Element i -> Doc -> (Doc, Doc)
carryelem Element i
e Doc
c in
                                     (Doc
d Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest 2 Doc
d',       Doc
c')
carrycontent (d :: Doc
d,c :: Doc
c) (CString _ s :: VersionInfo
s _) = (Doc
d Doc -> Doc -> Doc
<> Doc
c Doc -> Doc -> Doc
<> VersionInfo -> Doc
chardata VersionInfo
s, Doc
empty)
carrycontent (d :: Doc
d,c :: Doc
c) (CRef r :: Reference
r _)      = (Doc
d Doc -> Doc -> Doc
<> Doc
c Doc -> Doc -> Doc
<> Reference -> Doc
reference Reference
r,Doc
empty)
carrycontent (d :: Doc
d,c :: Doc
c) (CMisc m :: Misc
m _)     = (Doc
d Doc -> Doc -> Doc
$$ Doc
c Doc -> Doc -> Doc
<> Misc -> Doc
misc Misc
m,     Doc
empty)


attribute :: Attribute -> Doc
attribute (n :: QName
n,v :: AttValue
v)          = QName -> Doc
qname QName
n Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "=" Doc -> Doc -> Doc
<> AttValue -> Doc
attvalue AttValue
v
content :: Content i -> Doc
content (CElem e :: Element i
e _)      = Element i -> Doc
forall i. Element i -> Doc
element Element i
e
content (CString _ s :: VersionInfo
s _)  = VersionInfo -> Doc
chardata VersionInfo
s
content (CRef r :: Reference
r _)       = Reference -> Doc
reference Reference
r
content (CMisc m :: Misc
m _)      = Misc -> Doc
misc Misc
m

elementdecl	:: ElementDecl -> Doc
contentspec	:: ContentSpec -> Doc
cp		:: CP -> Doc
modifier	:: Modifier -> Doc
mixed		:: Mixed -> Doc
attlistdecl	:: AttListDecl -> Doc
attdef		:: AttDef -> Doc
atttype		:: AttType -> Doc
tokenizedtype	:: TokenizedType -> Doc
enumeratedtype	:: EnumeratedType -> Doc
notationtype	:: [String] -> Doc
enumeration	:: [String] -> Doc
defaultdecl	:: DefaultDecl -> Doc
reference	:: Reference -> Doc
entityref	:: String -> Doc
charref		:: (Show a) => a -> Doc
entitydecl	:: EntityDecl -> Doc
gedecl		:: GEDecl -> Doc
pedecl		:: PEDecl -> Doc
entitydef	:: EntityDef -> Doc
pedef		:: PEDef -> Doc
externalid	:: ExternalID -> Doc
ndatadecl	:: NDataDecl -> Doc
notationdecl	:: NotationDecl -> Doc
publicid	:: PublicID -> Doc
encodingdecl	:: EncodingDecl -> Doc
nmtoken		:: String -> Doc
attvalue	:: AttValue -> Doc
entityvalue	:: EntityValue -> Doc
ev		:: EV -> Doc
pubidliteral	:: PubidLiteral -> Doc
systemliteral	:: SystemLiteral -> Doc
chardata	:: [Char] -> Doc


elementdecl :: ElementDecl -> Doc
elementdecl (ElementDecl n :: QName
n cs :: ContentSpec
cs) = VersionInfo -> Doc
text "<!ELEMENT" Doc -> Doc -> Doc
<+> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+>
                                 ContentSpec -> Doc
contentspec ContentSpec
cs Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ">"
contentspec :: ContentSpec -> Doc
contentspec EMPTY              = VersionInfo -> Doc
text "EMPTY"
contentspec ANY                = VersionInfo -> Doc
text "ANY"
contentspec (Mixed m :: Mixed
m)          = Mixed -> Doc
mixed Mixed
m
contentspec (ContentSpec c :: CP
c)    = CP -> Doc
cp CP
c
--contentspec (ContentPE p cs)   = peref p
cp :: CP -> Doc
cp (TagName n :: QName
n m :: Modifier
m)       = QName -> Doc
qname QName
n Doc -> Doc -> Doc
<> Modifier -> Doc
modifier Modifier
m
cp (Choice cs :: [CP]
cs m :: Modifier
m)       = Doc -> Doc
parens ([Doc] -> Doc
hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (VersionInfo -> Doc
text "|") ((CP -> Doc) -> [CP] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map CP -> Doc
cp [CP]
cs))) Doc -> Doc -> Doc
<>
                           Modifier -> Doc
modifier Modifier
m
cp (Seq cs :: [CP]
cs m :: Modifier
m)          = Doc -> Doc
parens ([Doc] -> Doc
hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (VersionInfo -> Doc
text ",") ((CP -> Doc) -> [CP] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map CP -> Doc
cp [CP]
cs))) Doc -> Doc -> Doc
<>
                           Modifier -> Doc
modifier Modifier
m
--cp (CPPE p c)          = peref p
modifier :: Modifier -> Doc
modifier None          = Doc
empty
modifier Query         = VersionInfo -> Doc
text "?"
modifier Star          = VersionInfo -> Doc
text "*"
modifier Plus          = VersionInfo -> Doc
text "+"
mixed :: Mixed -> Doc
mixed  PCDATA          = VersionInfo -> Doc
text "(#PCDATA)"
mixed (PCDATAplus ns :: [QName]
ns)  = VersionInfo -> Doc
text "(#PCDATA |" Doc -> Doc -> Doc
<+>
                         [Doc] -> Doc
hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (VersionInfo -> Doc
text "|") ((QName -> Doc) -> [QName] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map QName -> Doc
qname [QName]
ns)) Doc -> Doc -> Doc
<>
                         VersionInfo -> Doc
text ")*"

attlistdecl :: AttListDecl -> Doc
attlistdecl (AttListDecl n :: QName
n ds :: [AttDef]
ds) = VersionInfo -> Doc
text "<!ATTLIST" Doc -> Doc -> Doc
<+> QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+>
                                 [Doc] -> Doc
fsep ((AttDef -> Doc) -> [AttDef] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map AttDef -> Doc
attdef [AttDef]
ds) Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ">"
attdef :: AttDef -> Doc
attdef (AttDef n :: QName
n t :: AttType
t d :: DefaultDecl
d)          = QName -> Doc
qname QName
n Doc -> Doc -> Doc
<+> AttType -> Doc
atttype AttType
t Doc -> Doc -> Doc
<+> DefaultDecl -> Doc
defaultdecl DefaultDecl
d
atttype :: AttType -> Doc
atttype  StringType            = VersionInfo -> Doc
text "CDATA"
atttype (TokenizedType t :: TokenizedType
t)      = TokenizedType -> Doc
tokenizedtype TokenizedType
t
atttype (EnumeratedType t :: EnumeratedType
t)     = EnumeratedType -> Doc
enumeratedtype EnumeratedType
t
tokenizedtype :: TokenizedType -> Doc
tokenizedtype ID               = VersionInfo -> Doc
text "ID"
tokenizedtype IDREF            = VersionInfo -> Doc
text "IDREF"
tokenizedtype IDREFS           = VersionInfo -> Doc
text "IDREFS"
tokenizedtype ENTITY           = VersionInfo -> Doc
text "ENTITY"
tokenizedtype ENTITIES         = VersionInfo -> Doc
text "ENTITIES"
tokenizedtype NMTOKEN          = VersionInfo -> Doc
text "NMTOKEN"
tokenizedtype NMTOKENS         = VersionInfo -> Doc
text "NMTOKENS"
enumeratedtype :: EnumeratedType -> Doc
enumeratedtype (NotationType n :: NotationType
n)= NotationType -> Doc
notationtype NotationType
n
enumeratedtype (Enumeration e :: NotationType
e) = NotationType -> Doc
enumeration NotationType
e
notationtype :: NotationType -> Doc
notationtype ns :: NotationType
ns                = VersionInfo -> Doc
text "NOTATION" Doc -> Doc -> Doc
<+>
                                 Doc -> Doc
parens ([Doc] -> Doc
hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (VersionInfo -> Doc
text "|") ((VersionInfo -> Doc) -> NotationType -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map VersionInfo -> Doc
text NotationType
ns)))
enumeration :: NotationType -> Doc
enumeration ns :: NotationType
ns                 = Doc -> Doc
parens ([Doc] -> Doc
hcat (Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
intersperse (VersionInfo -> Doc
text "|") ((VersionInfo -> Doc) -> NotationType -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map VersionInfo -> Doc
nmtoken NotationType
ns)))
defaultdecl :: DefaultDecl -> Doc
defaultdecl  REQUIRED          = VersionInfo -> Doc
text "#REQUIRED"
defaultdecl  IMPLIED           = VersionInfo -> Doc
text "#IMPLIED"
defaultdecl (DefaultTo a :: AttValue
a f :: Maybe FIXED
f)    = (FIXED -> Doc) -> Maybe FIXED -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe (Doc -> FIXED -> Doc
forall a b. a -> b -> a
const (VersionInfo -> Doc
text "#FIXED")) Maybe FIXED
f Doc -> Doc -> Doc
<+> AttValue -> Doc
attvalue AttValue
a
--conditionalsect (IncludeSect i)= text "<![INCLUDE [" <+>
--                                 vcat (map extsubsetdecl i) <+> text "]]>"
--conditionalsect (IgnoreSect i) = text "<![IGNORE [" <+>
--                                 fsep (map ignoresectcontents i) <+> text "]]>"
--ignore (Ignore)                = empty
--ignoresectcontents (IgnoreSectContents i is)
--                               = ignore i <+> vcat (map internal is)
--                          where internal (ics,i) = text "<![[" <+>
--                                                   ignoresectcontents ics <+>
--                                                   text "]]>" <+> ignore i
reference :: Reference -> Doc
reference (RefEntity er :: VersionInfo
er)       = VersionInfo -> Doc
entityref VersionInfo
er
reference (RefChar cr :: Int
cr)         = Int -> Doc
forall a. Show a => a -> Doc
charref Int
cr
entityref :: VersionInfo -> Doc
entityref n :: VersionInfo
n                    = VersionInfo -> Doc
text "&" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
n Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ";"
charref :: a -> Doc
charref c :: a
c                      = VersionInfo -> Doc
text "&#" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text (a -> VersionInfo
forall a. Show a => a -> VersionInfo
show a
c) Doc -> Doc -> Doc
<> VersionInfo -> Doc
text ";"
entitydecl :: EntityDecl -> Doc
entitydecl (EntityGEDecl d :: GEDecl
d)    = GEDecl -> Doc
gedecl GEDecl
d
entitydecl (EntityPEDecl d :: PEDecl
d)    = PEDecl -> Doc
pedecl PEDecl
d
gedecl :: GEDecl -> Doc
gedecl (GEDecl n :: VersionInfo
n ed :: EntityDef
ed)           = VersionInfo -> Doc
text "<!ENTITY" Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text VersionInfo
n Doc -> Doc -> Doc
<+> EntityDef -> Doc
entitydef EntityDef
ed Doc -> Doc -> Doc
<>
                                 VersionInfo -> Doc
text ">"
pedecl :: PEDecl -> Doc
pedecl (PEDecl n :: VersionInfo
n pd :: PEDef
pd)           = VersionInfo -> Doc
text "<!ENTITY %" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
n Doc -> Doc -> Doc
<+> PEDef -> Doc
pedef PEDef
pd Doc -> Doc -> Doc
<>
                                 VersionInfo -> Doc
text ">"
entitydef :: EntityDef -> Doc
entitydef (DefEntityValue ev :: EntityValue
ev)  = EntityValue -> Doc
entityvalue EntityValue
ev
entitydef (DefExternalID i :: ExternalID
i nd :: Maybe NDataDecl
nd) = ExternalID -> Doc
externalid ExternalID
i Doc -> Doc -> Doc
<+> (NDataDecl -> Doc) -> Maybe NDataDecl -> Doc
forall a. (a -> Doc) -> Maybe a -> Doc
maybe NDataDecl -> Doc
ndatadecl Maybe NDataDecl
nd
pedef :: PEDef -> Doc
pedef (PEDefEntityValue ev :: EntityValue
ev)    = EntityValue -> Doc
entityvalue EntityValue
ev
pedef (PEDefExternalID eid :: ExternalID
eid)    = ExternalID -> Doc
externalid ExternalID
eid
externalid :: ExternalID -> Doc
externalid (SYSTEM sl :: SystemLiteral
sl)         = VersionInfo -> Doc
text "SYSTEM" Doc -> Doc -> Doc
<+> SystemLiteral -> Doc
systemliteral SystemLiteral
sl
externalid (PUBLIC i :: PubidLiteral
i sl :: SystemLiteral
sl)       = VersionInfo -> Doc
text "PUBLIC" Doc -> Doc -> Doc
<+> PubidLiteral -> Doc
pubidliteral PubidLiteral
i Doc -> Doc -> Doc
<+>
                                 SystemLiteral -> Doc
systemliteral SystemLiteral
sl
ndatadecl :: NDataDecl -> Doc
ndatadecl (NDATA n :: VersionInfo
n)            = VersionInfo -> Doc
text "NDATA" Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text VersionInfo
n
--textdecl (TextDecl vi ed)      = text "<?xml" <+> maybe text vi <+>
--                                 encodingdecl ed <> text "?>"
--extparsedent (ExtParsedEnt t c)= maybe textdecl t <+> content c
--extpe (ExtPE t esd)            = maybe textdecl t <+>
--                                 vcat (map extsubsetdecl esd)
notationdecl :: NotationDecl -> Doc
notationdecl (NOTATION n :: VersionInfo
n e :: Either ExternalID PublicID
e)    = VersionInfo -> Doc
text "<!NOTATION" Doc -> Doc -> Doc
<+> VersionInfo -> Doc
text VersionInfo
n Doc -> Doc -> Doc
<+>
                                 (ExternalID -> Doc)
-> (PublicID -> Doc) -> Either ExternalID PublicID -> Doc
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either ExternalID -> Doc
externalid PublicID -> Doc
publicid Either ExternalID PublicID
e Doc -> Doc -> Doc
<>
                                 VersionInfo -> Doc
text ">"
publicid :: PublicID -> Doc
publicid (PUBLICID p :: PubidLiteral
p)          = VersionInfo -> Doc
text "PUBLICID" Doc -> Doc -> Doc
<+> PubidLiteral -> Doc
pubidliteral PubidLiteral
p
encodingdecl :: EncodingDecl -> Doc
encodingdecl (EncodingDecl s :: VersionInfo
s)  = VersionInfo -> Doc
text "encoding='" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
s Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "'"
nmtoken :: VersionInfo -> Doc
nmtoken s :: VersionInfo
s                      = VersionInfo -> Doc
text VersionInfo
s
attvalue :: AttValue -> Doc
attvalue (AttValue esr :: [Either VersionInfo Reference]
esr)        = VersionInfo -> Doc
text "\"" Doc -> Doc -> Doc
<>
                                 [Doc] -> Doc
hcat ((Either VersionInfo Reference -> Doc)
-> [Either VersionInfo Reference] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((VersionInfo -> Doc)
-> (Reference -> Doc) -> Either VersionInfo Reference -> Doc
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either VersionInfo -> Doc
text Reference -> Doc
reference) [Either VersionInfo Reference]
esr) Doc -> Doc -> Doc
<>
                                 VersionInfo -> Doc
text "\""
entityvalue :: EntityValue -> Doc
entityvalue (EntityValue evs :: [EV]
evs)  = VersionInfo -> Doc
text "'" Doc -> Doc -> Doc
<> [Doc] -> Doc
hcat ((EV -> Doc) -> [EV] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map EV -> Doc
ev [EV]
evs) Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "'"
ev :: EV -> Doc
ev (EVString s :: VersionInfo
s)                = VersionInfo -> Doc
text VersionInfo
s
--ev (EVPERef p e)               = peref p
ev (EVRef r :: Reference
r)                   = Reference -> Doc
reference Reference
r
pubidliteral :: PubidLiteral -> Doc
pubidliteral (PubidLiteral s :: VersionInfo
s)  = VersionInfo -> Doc
text "'" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
s Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "'"
systemliteral :: SystemLiteral -> Doc
systemliteral (SystemLiteral s :: VersionInfo
s)= VersionInfo -> Doc
text "'" Doc -> Doc -> Doc
<> VersionInfo -> Doc
text VersionInfo
s Doc -> Doc -> Doc
<> VersionInfo -> Doc
text "'"
chardata :: VersionInfo -> Doc
chardata s :: VersionInfo
s                     = if (Char -> SDDecl) -> VersionInfo -> SDDecl
forall (t :: * -> *) a.
Foldable t =>
(a -> SDDecl) -> t a -> SDDecl
all Char -> SDDecl
isSpace VersionInfo
s then Doc
empty else VersionInfo -> Doc
text VersionInfo
s
--cdsect c                       = text "<![CDATA[" <> chardata c <> text "]]>"

qname :: QName -> Doc
qname n :: QName
n                        = VersionInfo -> Doc
text (QName -> VersionInfo
printableName QName
n)

----