From 3b881e20b213ec51ce8b5376e412bc6c6441acd0 Mon Sep 17 00:00:00 2001 From: aarne Date: Tue, 3 Mar 2009 10:41:36 +0000 Subject: [PATCH] newlines and indentation in XML printing --- src/GF/Data/XML.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/GF/Data/XML.hs b/src/GF/Data/XML.hs index 4b3a9b509..bdc6f98a1 100644 --- a/src/GF/Data/XML.hs +++ b/src/GF/Data/XML.hs @@ -25,14 +25,18 @@ showsXMLDoc xml = encodeUTF8 . showString header . showsXML xml where header = "" showsXML :: XML -> ShowS -showsXML (Data s) = showString s -showsXML (CData s) = showString "" -showsXML (ETag t as) = showChar '<' . showString t . showsAttrs as . showString "/>" -showsXML (Tag t as cs) = - showChar '<' . showString t . showsAttrs as . showChar '>' - . concatS (map showsXML cs) . showString "' -showsXML (Comment c) = showString "" -showsXML (Empty) = id +showsXML = showsX 0 where + showsX i x = ind i . case x of + (Data s) -> showString s + (CData s) -> showString "" + (ETag t as) -> showChar '<' . showString t . showsAttrs as . showString "/>" + (Tag t as cs) -> + showChar '<' . showString t . showsAttrs as . showChar '>' . + concatS (map (showsX (i+1)) cs) . ind i . + showString "' + (Comment c) -> showString "" + (Empty) -> id + ind i = showString ("\n" ++ replicate (2*i) ' ') showsAttrs :: [Attr] -> ShowS showsAttrs = concatS . map (showChar ' ' .) . map showsAttr