Show More
@@ -72,7 +72,11 b' def html2text(element):' | |||
|
72 | 72 | Analog of jQuery's $(element).text() |
|
73 | 73 | """ |
|
74 | 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 | 81 | text = element.text or "" |
|
78 | 82 | for child in element: |
@@ -86,7 +90,11 b' def add_anchor(html):' | |||
|
86 | 90 | |
|
87 | 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 | 98 | link = html2text(h).replace(' ', '-') |
|
91 | 99 | h.set('id', link) |
|
92 | 100 | a = ElementTree.Element("a", {"class" : "anchor-link", "href" : "#" + link}) |
@@ -60,7 +60,12 b' class TestStrings(TestsBase):' | |||
|
60 | 60 | assert '<b' in results |
|
61 | 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 | 69 | def test_strip_dollars(self): |
|
65 | 70 | """strip_dollars test""" |
|
66 | 71 | tests = [ |
General Comments 0
You need to be logged in to leave comments.
Login now