Created
July 28, 2009 15:33
-
-
Save notanumber/157458 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _do_highlight(self, content, text, tag='em'): | |
""" | |
Highlight `text` in `content` with html `tag`. | |
This method assumes that the input text (`content`) does not contain | |
any special formatting. That is, it does not contain any html tags | |
or similar markup that could be screwed up by the highlighting. | |
Required arguments: | |
`content` -- Content to search for instances of `text` | |
`text` -- The text to be highlighted | |
""" | |
for term in [term.replace('*', '') for term in text.split()]: | |
term_re = re.compile(re.escape(term), re.IGNORECASE) | |
content = term_re.sub('<%s>%s</%s>' % (tag, term, tag), content) | |
return content |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment