33{-# LANGUAGE MultiParamTypeClasses #-}
44{-# LANGUAGE OverloadedStrings #-}
55{-# LANGUAGE ScopedTypeVariables #-}
6+ {-# LANGUAGE TypeApplications #-}
67
78module HaskellWorks.Data.Xml.RawValue
89 ( RawValue (.. )
@@ -15,7 +16,7 @@ import Data.Text (Text)
1516import HaskellWorks.Data.Xml.Grammar
1617import HaskellWorks.Data.Xml.Internal.Show
1718import HaskellWorks.Data.Xml.Succinct.Index
18- import Text.PrettyPrint.ANSI.Leijen hiding ( (<$>) , (<>) )
19+ import Prettyprinter
1920
2021import qualified Data.Attoparsec.ByteString.Char8 as ABC
2122import qualified Data.ByteString as BS
@@ -34,35 +35,49 @@ data RawValue
3435 | RawError Text
3536 deriving (Eq , Show )
3637
38+ -- TODO use colors and styles
39+
40+ red :: Doc ann -> Doc ann
41+ red = id
42+
43+ dullwhite :: Doc ann -> Doc ann
44+ dullwhite = id
45+
46+ bold :: Doc ann -> Doc ann
47+ bold = id
48+
49+ dullgreen :: Doc ann -> Doc ann
50+ dullgreen = id
51+
3752instance Pretty RawValue where
3853 pretty mjpv = case mjpv of
39- RawText s -> ctext $ text (T. unpack s)
40- RawAttrName s -> text (T. unpack s)
41- RawAttrValue s -> (ctext . dquotes . text ) (T. unpack s)
54+ RawText s -> ctext $ pretty (T. unpack s)
55+ RawAttrName s -> pretty (T. unpack s)
56+ RawAttrValue s -> (ctext . dquotes . pretty ) (T. unpack s)
4257 RawAttrList ats -> formatAttrs ats
43- RawComment s -> text $ " <!-- " <> show s <> " -->"
58+ RawComment s -> pretty $ " <!-- " <> show s <> " -->"
4459 RawElement s xs -> formatElem (T. unpack s) xs
4560 RawDocument xs -> formatMeta " ?" " xml" xs
46- RawError s -> red $ text " [error " <> text (T. unpack s) <> text " ]"
47- RawCData s -> cangle " <!" <> ctag (text " [CDATA[" ) <> text (T. unpack s) <> cangle (text " ]]>" )
61+ RawError s -> red $ " [error " <> pretty (T. unpack s) <> " ]"
62+ RawCData s -> cangle " <!" <> ctag " [CDATA[" <> pretty (T. unpack s) <> cangle " ]]>"
4863 RawMeta s xs -> formatMeta " !" (T. unpack s) xs
4964 where
5065 formatAttr at = case at of
51- RawAttrName a -> text " " <> pretty (RawAttrName a)
52- RawAttrValue a -> text " =" <> pretty (RawAttrValue a)
53- RawAttrList _ -> red $ text " ATTRS"
54- _ -> red $ text " booo"
66+ RawAttrName a -> " " <> pretty (RawAttrName a)
67+ RawAttrValue a -> " =" <> pretty (RawAttrValue a)
68+ RawAttrList _ -> red " ATTRS"
69+ _ -> red " booo"
5570 formatAttrs ats = hcat (formatAttr <$> ats)
5671 formatElem s xs =
5772 let (ats, es) = partition isAttrL xs
58- in cangle langle <> ctag (text s)
73+ in cangle langle <> ctag (pretty s)
5974 <> hcat (pretty <$> ats)
6075 <> cangle rangle
6176 <> hcat (pretty <$> es)
62- <> cangle (text " </" ) <> ctag (text s) <> cangle rangle
77+ <> cangle " </" <> ctag (pretty s) <> cangle rangle
6378 formatMeta b s xs =
6479 let (ats, es) = partition isAttr xs
65- in cangle (langle <> text b) <> ctag (text s)
80+ in cangle (langle <> pretty @ String b) <> ctag (pretty @ String s)
6681 <> hcat (pretty <$> ats)
6782 <> cangle rangle
6883 <> hcat (pretty <$> es)
@@ -102,13 +117,13 @@ instance RawValueAt XmlIndex where
102117 ABC. Partial _ -> decodeErr " Unexpected end of attr name, expected" bs
103118 ABC. Done _ r -> Right r
104119
105- cangle :: Doc -> Doc
120+ cangle :: Doc ann -> Doc ann
106121cangle = dullwhite
107122
108- ctag :: Doc -> Doc
123+ ctag :: Doc ann -> Doc ann
109124ctag = bold
110125
111- ctext :: Doc -> Doc
126+ ctext :: Doc ann -> Doc ann
112127ctext = dullgreen
113128
114129isAttrL :: RawValue -> Bool
0 commit comments