Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions xmodule/annotator_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ def __init__(self):
self.reset()
self.fed = []

def handle_starttag(self, tag, attrs):
if tag != 'img':
return
for attr in attrs:
if len(attr) >= 2 and attr[0] == 'alt':
self.fed.append(attr[1])

def handle_data(self, data):
"""takes the data in separate chunks"""
self.fed.append(data)
Expand Down
14 changes: 14 additions & 0 deletions xmodule/tests/test_annotator_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class HelperFunctionTest(unittest.TestCase):
sample_sourceurl = "http://video-js.zencoder.com/oceans-clip.mp4"
sample_youtubeurl = "http://www.youtube.com/watch?v=yxLIu-scR9Y"
sample_html = '<p><b>Testing here</b> and not bolded here</p>'
# pylint: disable=line-too-long
sample_html_with_image_alt = '''<p>Testing here with image: </p><p><img src="/static/image.jpg" alt="the alt text" width="560" height="315" /></p>'''
# pylint: disable=line-too-long
sample_html_with_no_image_alt = '''<p>Testing here with image: </p><p><img src="/static/image.jpg" width="560" height="315" /></p>'''

def test_get_instructions(self):
"""
Expand Down Expand Up @@ -54,3 +58,13 @@ def test_html_to_text(self):
expectedtext = "Testing here and not bolded here"
result = html_to_text(self.sample_html)
assert expectedtext == result

def test_html_image_with_alt_text(self):
expectedtext = "Testing here with image: the alt text"
result = html_to_text(self.sample_html_with_image_alt)
assert expectedtext == result

def test_html_image_with_no_alt_text(self):
expectedtext = "Testing here with image: "
result = html_to_text(self.sample_html_with_no_image_alt)
assert expectedtext == result