def langs(match): if end_tag.match(match.string[match.end():]): # if the next tag is the end tag of a link, then don't link again! return match.string[match.start():match.end()] name = normalize_whitespace(match.group('name')) return '<a href="/contributions/%s">%s</a>%s' % (lookup[name], name, match.group('s'))
def test_normalize_whitespace(self): from souplib import normalize_whitespace self.assertEquals(normalize_whitespace(' \xa0 \n\t '), '') self.assertEquals(normalize_whitespace(' \ta \n\t b '), ' a b')
def popover(number, note): # we use BeautifulSoup to fix broken markup, e.g. incomplete span tags. note = BeautifulSoup(normalize_whitespace(note)).find('body') note.name = 'div' a = new_tag( soup, 'a', new_tag(soup, 'sup', number), **{ 'style': 'text-decoration: underline; cursor: pointer;', 'class': 'popover-note', 'data-original-title': 'Note %s' % number, 'data-content': unicode(note), }) return unicode(a)