mercurial/templatefilters.py
changeset 19228 889807c79384
parent 19227 8eef5b93db9d
child 19467 1afe5d3939db
equal deleted inserted replaced
19227:8eef5b93db9d 19228:889807c79384
    97     return cgi.escape(text.replace('\0', ''), True)
    97     return cgi.escape(text.replace('\0', ''), True)
    98 
    98 
    99 para_re = None
    99 para_re = None
   100 space_re = None
   100 space_re = None
   101 
   101 
   102 def fill(text, width):
   102 def fill(text, width, initindent = '', hangindent = ''):
   103     '''fill many paragraphs.'''
   103     '''fill many paragraphs with optional indentation.'''
   104     global para_re, space_re
   104     global para_re, space_re
   105     if para_re is None:
   105     if para_re is None:
   106         para_re = re.compile('(\n\n|\n\\s*[-*]\\s*)', re.M)
   106         para_re = re.compile('(\n\n|\n\\s*[-*]\\s*)', re.M)
   107         space_re = re.compile(r'  +')
   107         space_re = re.compile(r'  +')
   108 
   108 
   119                        uctext[w:].encode(encoding.encoding))
   119                        uctext[w:].encode(encoding.encoding))
   120                 break
   120                 break
   121             yield text[start:m.start(0)], m.group(1)
   121             yield text[start:m.start(0)], m.group(1)
   122             start = m.end(1)
   122             start = m.end(1)
   123 
   123 
   124     return "".join([space_re.sub(' ', util.wrap(para, width=width)) + rest
   124     return "".join([util.wrap(space_re.sub(' ', util.wrap(para, width)),
       
   125                               width, initindent, hangindent) + rest
   125                     for para, rest in findparas()])
   126                     for para, rest in findparas()])
   126 
   127 
   127 def fill68(text):
   128 def fill68(text):
   128     """:fill68: Any text. Wraps the text to fit in 68 columns."""
   129     """:fill68: Any text. Wraps the text to fit in 68 columns."""
   129     return fill(text, 68)
   130     return fill(text, 68)