code: def nl2br(s):
      
      if not isinstance(s, basestring):
          s = str(s)
      s = re.sub(r'\r\n|\r|\n', '\n', s)
      paragraphs = re.split('\n{2,}', s)
      paragraphs = ['<p>%s</p>' % p.strip().replace('\n', '<br />') for p in paragraphs]
      return '\n\n'.join(paragraphs)
docs: {{ s|nl2br }}
  
      Convert newlines into <p> and <br />s.