mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-24 03:52:50 -06:00
newlines and indentation in XML printing
This commit is contained in:
@@ -25,14 +25,18 @@ showsXMLDoc xml = encodeUTF8 . showString header . showsXML xml
|
|||||||
where header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
|
where header = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"
|
||||||
|
|
||||||
showsXML :: XML -> ShowS
|
showsXML :: XML -> ShowS
|
||||||
showsXML (Data s) = showString s
|
showsXML = showsX 0 where
|
||||||
showsXML (CData s) = showString "<![CDATA[" . showString s .showString "]]>"
|
showsX i x = ind i . case x of
|
||||||
showsXML (ETag t as) = showChar '<' . showString t . showsAttrs as . showString "/>"
|
(Data s) -> showString s
|
||||||
showsXML (Tag t as cs) =
|
(CData s) -> showString "<![CDATA[" . showString s .showString "]]>"
|
||||||
showChar '<' . showString t . showsAttrs as . showChar '>'
|
(ETag t as) -> showChar '<' . showString t . showsAttrs as . showString "/>"
|
||||||
. concatS (map showsXML cs) . showString "</" . showString t . showChar '>'
|
(Tag t as cs) ->
|
||||||
showsXML (Comment c) = showString "<!-- " . showString c . showString " -->"
|
showChar '<' . showString t . showsAttrs as . showChar '>' .
|
||||||
showsXML (Empty) = id
|
concatS (map (showsX (i+1)) cs) . ind i .
|
||||||
|
showString "</" . showString t . showChar '>'
|
||||||
|
(Comment c) -> showString "<!-- " . showString c . showString " -->"
|
||||||
|
(Empty) -> id
|
||||||
|
ind i = showString ("\n" ++ replicate (2*i) ' ')
|
||||||
|
|
||||||
showsAttrs :: [Attr] -> ShowS
|
showsAttrs :: [Attr] -> ShowS
|
||||||
showsAttrs = concatS . map (showChar ' ' .) . map showsAttr
|
showsAttrs = concatS . map (showChar ' ' .) . map showsAttr
|
||||||
|
|||||||
Reference in New Issue
Block a user