Commits

Tom Morris committed df4f515

adding backcompat

Comments (0)

Files changed (5)

+from xml.dom.minidom import Element
+import dom_addins
+
+def apply_backcompat_rules(self):
+    for el in self.getElementsByClassName("hcard"):
+        el.addClassName("h-card")
+
+Element.__dict__.update({'apply_backcompat_rules': apply_backcompat_rules})
 def getElementsByClassName(self, classname):
     return [x for x in self.getElementsByTagName("*") if x.hasAttribute("class") and classname in x.getAttribute("class").split(" ")]
 
+def addClassName(self, classname):
+    classnames = set(self.getAttribute("class").split(" "))
+    classnames.add(classname)
+    self.setAttribute("class", ' '.join(list(classnames)))
+
 Element.__dict__.update({'getElementsByClassName': getElementsByClassName})
+Element.__dict__.update({'addClassName': addClassName})
 
 import json
 import html5lib
 import dom_addins
-import implied
+import backcompat
 from urlparse import urlparse
 import xml.dom.minidom
 
 
         if self.__doc__ is not None:
             # parse!
+            self.__doc__.documentElement.apply_backcompat_rules()
             self.parse()
 
     def parse(self):

test/examples/backcompat.html

+<!DOCTYPE html>
+<html>
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=utf-8">
+  <title>Backcompat Properties</title>
+</head>
+<body>
+	<span class="hcard">Tom Morris</span>
+</body>
+</html>
+
     assert result["items"][4]["properties"]["photo"][0] == "http://tommorris.org/photo.png"
     assert result["items"][4]["properties"]["name"][0] == "Tom Morris"
 
+def test_backcompat():
+    result = parse_fixture("backcompat.html")
+    assert set(result["items"][0]["type"]) == set(["h-card"])
+
 if __name__ == '__main__':
     result = parse_fixture("nested_multiple_classnames.html")
     pprint(result)