@@ 14,7 14,8 @@ import Data.Maybe (fromMaybe)
import qualified Text.XML as XML
import Data.CSS.Syntax.StyleSheet
import Data.CSS.Style
-import Data.CSS.Syntax.Tokens (tokenize)
+import Data.CSS.StyleTree
+import Data.CSS.Syntax.Tokens
import Data.CSS.Preprocessor.Conditions
import qualified Data.CSS.Preprocessor.Conditions.Expr as Query
import Network.URI
@@ 115,10 116,30 @@ elToStylish (XML.Element (XML.Name name ns _) attrs _) parent previous =
parent = parent,
previous = previous
}
-addPsuedoclasses el psuedoclasses
- | (Attribute "" "" value : attrs) <- attributes el = el {
- attributes = Attribute "" "" (psuedoclasses ++ value) : attrs
- }
- | otherwise = el {
- attributes = Attribute "" "" psuedoclasses : attributes el
- }
+
+el2stylist el = nodes2stylist [XML.NodeElement el] Nothing Nothing
+nodes2stylist (XML.NodeElement (XML.Element (XML.Name name ns _) attrs childs):nodes) parent previous =
+ let el = ElementNode {
+ name = name,
+ namespace = fromMaybe "" ns,
+ attributes = L.sort [
+ Attribute name (fromMaybe "" ns) (Txt.unpack value)
+ | (XML.Name name ns _, value) <- M.toList attrs
+ ],
+ parent = parent,
+ previous = previous
+ } in StyleTree {
+ style = el,
+ children = nodes2stylist childs (Just el) Nothing
+ } : nodes2stylist nodes parent previous
+nodes2stylist (XML.NodeContent txt:nodes) parent previous = StyleTree {
+ style = ElementNode {
+ name = "", namespace = "",
+ attributes = [Attribute "style" "" $ Txt.unpack $
+ Txt.append "content: " $ serialize [String txt]],
+ parent = parent, previous = previous
+ },
+ children = []
+ } : nodes2stylist nodes parent previous
+nodes2stylist (_:nodes) parent previous = nodes2stylist nodes parent previous
+nodes2stylist [] _ _ = []