#!/usr/bin/env python import re p_emphasis = ur'(?%s%s' % (link, text, punctuation) def hypertext(text): text = text.replace('<', '<') text = r_link.sub(s_link, text) text = r_emphasis.sub(r'\g<1>', text) text = r_paragraph.sub('

', text) text = text.replace(' \\n\n', '
\n') return text.replace('\\*', '*') example = """ The *commonly used* http://example.org/ example domains *changed recently*, tech.slashdot.org/story/11/01/30/1823241/Examplecom-Has-Changed and now redirect to an *IANA page* www.iana.org/domains/example/ instead. The IANA is operated by *ICANN*. icann.org *[ICANN Logo]* inamidst.com/stuff/2011/icann *The ICANN Logo* """ if __name__ == '__main__': print hypertext(example)