mercurial/templatefilters.py
changeset 10282 08a0f04b56bd
parent 10263 25e572394f5c
child 10601 b98b6a7363ae
equal deleted inserted replaced
10281:e7d3b509af8b 10282:08a0f04b56bd
    62         start = 0
    62         start = 0
    63         while True:
    63         while True:
    64             m = para_re.search(text, start)
    64             m = para_re.search(text, start)
    65             if not m:
    65             if not m:
    66                 w = len(text)
    66                 w = len(text)
    67                 while w > start and text[w-1].isspace(): w -= 1
    67                 while w > start and text[w - 1].isspace():
       
    68                     w -= 1
    68                 yield text[start:w], text[w:]
    69                 yield text[start:w], text[w:]
    69                 break
    70                 break
    70             yield text[start:m.start(0)], m.group(1)
    71             yield text[start:m.start(0)], m.group(1)
    71             start = m.end(1)
    72             start = m.end(1)
    72 
    73 
    89     return ''.join(['&#%d;' % ord(c) for c in text])
    90     return ''.join(['&#%d;' % ord(c) for c in text])
    90 
    91 
    91 def domain(author):
    92 def domain(author):
    92     '''get domain of author, or empty string if none.'''
    93     '''get domain of author, or empty string if none.'''
    93     f = author.find('@')
    94     f = author.find('@')
    94     if f == -1: return ''
    95     if f == -1:
    95     author = author[f+1:]
    96         return ''
       
    97     author = author[f + 1:]
    96     f = author.find('>')
    98     f = author.find('>')
    97     if f >= 0: author = author[:f]
    99     if f >= 0:
       
   100         author = author[:f]
    98     return author
   101     return author
    99 
   102 
   100 def person(author):
   103 def person(author):
   101     '''get name of author, or else username.'''
   104     '''get name of author, or else username.'''
   102     if not '@' in author: return author
   105     if not '@' in author:
       
   106         return author
   103     f = author.find('<')
   107     f = author.find('<')
   104     if f == -1: return util.shortuser(author)
   108     if f == -1:
       
   109         return util.shortuser(author)
   105     return author[:f].rstrip()
   110     return author[:f].rstrip()
   106 
   111 
   107 def indent(text, prefix):
   112 def indent(text, prefix):
   108     '''indent each non-empty line of text after first with prefix.'''
   113     '''indent each non-empty line of text after first with prefix.'''
   109     lines = text.splitlines()
   114     lines = text.splitlines()