##// END OF EJS Templates
Merge pull request #4696 from minrk/etree-fail...
Matthias Bussonnier -
r13884:730129d3 merge
parent child Browse files
Show More
@@ -72,7 +72,11 b' def html2text(element):'
72 Analog of jQuery's $(element).text()
72 Analog of jQuery's $(element).text()
73 """
73 """
74 if isinstance(element, py3compat.string_types):
74 if isinstance(element, py3compat.string_types):
75 element = ElementTree.fromstring(element)
75 try:
76 element = ElementTree.fromstring(element)
77 except Exception:
78 # failed to parse, just return it unmodified
79 return element
76
80
77 text = element.text or ""
81 text = element.text or ""
78 for child in element:
82 for child in element:
@@ -86,7 +90,11 b' def add_anchor(html):'
86
90
87 For use in heading cells
91 For use in heading cells
88 """
92 """
89 h = ElementTree.fromstring(py3compat.cast_bytes_py2(html, encoding='utf-8'))
93 try:
94 h = ElementTree.fromstring(py3compat.cast_bytes_py2(html, encoding='utf-8'))
95 except Exception:
96 # failed to parse, just return it unmodified
97 return html
90 link = html2text(h).replace(' ', '-')
98 link = html2text(h).replace(' ', '-')
91 h.set('id', link)
99 h.set('id', link)
92 a = ElementTree.Element("a", {"class" : "anchor-link", "href" : "#" + link})
100 a = ElementTree.Element("a", {"class" : "anchor-link", "href" : "#" + link})
@@ -60,7 +60,12 b' class TestStrings(TestsBase):'
60 assert '<b' in results
60 assert '<b' in results
61 assert '</b>' in results
61 assert '</b>' in results
62
62
63
63 def test_add_anchor_fail(self):
64 """add_anchor does nothing when it fails"""
65 html = '<h1>Hello <br>World!</h1>'
66 results = add_anchor(html)
67 self.assertEqual(html, results)
68
64 def test_strip_dollars(self):
69 def test_strip_dollars(self):
65 """strip_dollars test"""
70 """strip_dollars test"""
66 tests = [
71 tests = [
General Comments 0
You need to be logged in to leave comments. Login now