def safemarkdown(text, div=True): from contrib.markdown import markdown if text: # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") text = wrap_urls(text) try: text = markdown(text) except RuntimeError: text = "<p><em>Comment Broken</em></p>" #wipe malicious javascript text = jscript_url.sub('', text) def href_handler(m): x = m.group(1).replace('&', '&') if c.cname: return '<a target="_top" href="%s"' % x else: return '<a href="%s"' % x def code_handler(m): l = m.group(1) return '<code>%s</code>' % l.replace('&','&') #unescape double escaping in links def inner_a_handler(m): l = m.group(1) return '>%s</a>' % l.replace('&','&') # remove the "&" escaping in urls text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) return MD_START + text + MD_END if div else text
def safemarkdown(text, nofollow=False, target=None): from contrib.markdown import markdown if text: # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") #wrap urls in "<>" so that markdown will handle them as urls text = r_url.sub(r'<\1>', text) try: text = markdown(text) except RuntimeError: text = "<p><em>Comment Broken</em></p>" #remove images text = img.sub('', text) #wipe malicious javascript text = jscript_url.sub('', text) def href_handler(m): url = m.group(1).replace('&', '&') link = '<a href="%s"' % url if target: link += ' target="%s"' % target elif c.cname: link += ' target="_top"' if nofollow: link += ' rel="nofollow"' return link def code_handler(m): l = m.group(1) return '<code>%s</code>' % l.replace('&','&') #unescape double escaping in links def inner_a_handler(m): l = m.group(1) return '>%s</a>' % l.replace('&','&') # remove the "&" escaping in urls text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) text = fix_url.sub(r'\1', text) return SC_OFF + '<div class="md">' + text + '</div>' + SC_ON
def safemarkdown(text): from contrib.markdown import markdown if text: # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") #wrap urls in "<>" so that markdown will handle them as urls text = r_url.sub(r'<\1>', text) try: text = markdown(text) except RuntimeError: text = "<p><em>Comment Broken</em></p>" #wipe malicious javascript text = jscript_url.sub('', text) def href_handler(m): return '<a href="%s"' % m.group(1).replace('&', '&') def code_handler(m): l = m.group(1) return '<code>%s</code>' % l.replace('&','&') # remove the "&" escaping in urls text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) return MD_START + text + MD_END
def py_markdown(text, nofollow=False, target=None): # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") #wrap urls in "<>" so that markdown will handle them as urls text = r_url.sub(r'<\1>', text) text = markdown(text) text = img.sub('', text) #remove images # remove the "&" escaping in urls text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) #remove images text = img.sub('', text) #wipe malicious javascript text = jscript_url.sub('', text) # remove the "&" escaping in urls def href_handler(m): url = m.group(1).replace('&', '&') link = '<a href="%s"' % url if target: link += ' target="%s"' % target if nofollow: link += ' rel="nofollow"' return link text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) text = fix_url.sub(r'\1', text) return text
def py_markdown(text, nofollow=False, target=None): # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") #wrap urls in "<>" so that markdown will handle them as urls text = r_url.sub(r'<\1>', text) text = markdown(text) text = img.sub('', text) #remove images # remove the "&" escaping in urls text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) #remove images text = img.sub('', text) #wipe malicious javascript text = jscript_url.sub('', text) # remove the "&" escaping in urls def href_handler(m): url = m.group(1).replace('&', '&') link = '<a href="%s"' % url if target: link += ' target="%s"' % target if nofollow: link += ' rel="nofollow"' return link text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) text = fix_url.sub(r'\1', text) return text
def safemarkdown(text, div=True): from contrib.markdown import markdown if text: # increase escaping of &, < and > once text = text.replace("&", "&").replace("<", "<").replace(">", ">") text = wrap_urls(text) try: text = markdown(text) except RuntimeError: text = "<p><em>Comment Broken</em></p>" #wipe malicious javascript text = jscript_url.sub('', text) def href_handler(m): x = m.group(1).replace('&', '&') if c.cname: return '<a target="_top" href="%s"' % x else: return '<a href="%s"' % x def code_handler(m): l = m.group(1) return '<code>%s</code>' % l.replace('&', '&') #unescape double escaping in links def inner_a_handler(m): l = m.group(1) return '>%s</a>' % l.replace('&', '&') # remove the "&" escaping in urls text = href_re.sub(href_handler, text) text = code_re.sub(code_handler, text) text = a_re.sub(inner_a_handler, text) return MD_START + text + MD_END if div else text