Changeset 6efb078daff9…
Parent 9736501e4df3…
by
Changes to 2 files · Browse files at 6efb078daff9 Showing diff from parent 9736501e4df3 Diff from another changeset...
@@ -10,6 +10,7 @@ import shutil
import stat
import tempfile
+import re
from PyQt4.QtCore import *
from PyQt4.QtGui import *
@@ -145,6 +146,60 @@ msg = msg.replace('\n', '<br />')
return '<span style="%s">%s</span>' % (style, msg)
+def descriptionhtmlizer():
+ """Return a function to mark up ctx.description() as an HTML
+
+ >>> htmlize = descriptionhtmlizer()
+ >>> htmlize('foo <bar> \\n& <baz>')
+ u'foo <bar> \\n& <baz>'
+
+ changeset hash link:
+ >>> htmlize('foo af50a62e9c20 bar')
+ u'foo <a href="rev_hash_af50a62e9c20">af50a62e9c20</a> bar'
+ >>> htmlize('af50a62e9c2040dcdaf61ba6a6400bb45ab56410') # doctest: +ELLIPSIS
+ u'<a href="rev_hash_af...10">af...10</a>'
+
+ http/https links:
+ >>> s = htmlize('foo http://example.com:8000/foo?bar=baz&bax#blah')
+ >>> (s[:63], s[63:]) # doctest: +NORMALIZE_WHITESPACE
+ (u'foo <a href="http://example.com:8000/foo?bar=baz&bax#blah">',
+ u'http://example.com:8000/foo?bar=baz&bax#blah</a>')
+ >>> htmlize('https://example/')
+ u'<a href="https://example/">https://example/</a>'
+ """
+ # TODO: support tortoisehg.issue.regex and issue.link
+ csmatch = r'(\b[0-9a-f]{12}(?:[0-9a-f]{28})?\b)'
+ httpmatch = r'(\b(http|https)://([-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]))'
+ regexp = r'%s|%s' % (csmatch, httpmatch)
+ bodyre = re.compile(regexp)
+
+ revhashprefix = 'rev_hash_'
+
+ def htmlize(desc):
+ """Mark up ctx.description() [localstr] as an HTML [unicode]"""
+ desc = unicode(Qt.escape(hglib.tounicode(desc)))
+
+ buf = ''
+ pos = 0
+ for m in bodyre.finditer(desc):
+ a, b = m.span()
+ if a >= pos:
+ buf += desc[pos:a]
+ pos = b
+ groups = m.groups()
+ if groups[0]:
+ cslink = groups[0]
+ buf += '<a href="%s%s">%s</a>' % (revhashprefix, cslink, cslink)
+ if groups[1]:
+ urllink = groups[1]
+ buf += '<a href="%s">%s</a>' % (urllink, urllink)
+ if pos < len(desc):
+ buf += desc[pos:]
+
+ return buf
+
+ return htmlize
+
_iconcache = {}
def geticon(name):
|
@@ -14,23 +14,11 @@ # this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-import re
-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
-from tortoisehg.util.util import xml_escape
-from tortoisehg.util.hglib import tounicode
-
-from tortoisehg.hgqt.i18n import _
from tortoisehg.hgqt import qtlib
-# initialize changeset and url link regex
-csmatch = r'(\b[0-9a-f]{12}(?:[0-9a-f]{28})?\b)'
-httpmatch = r'(\b(http|https)://([-A-Za-z0-9+&@#/%?=~_()|!:,.;]*[-A-Za-z0-9+&@#/%=~_()|]))'
-regexp = r'%s|%s' % (csmatch, httpmatch)
-bodyre = re.compile(regexp)
-
revhashprefix = 'rev_hash_'
class RevMessage(QWidget):
@@ -53,6 +41,8 @@
self.setLayout(vb)
+ self._htmlize = qtlib.descriptionhtmlizer()
+
self._message.anchorClicked.connect(self.anchorClicked)
def anchorClicked(self, qurl):
@@ -65,28 +55,8 @@
def displayRevision(self, ctx):
self.ctx = ctx
-
- desc = xml_escape(tounicode(ctx.description()))
-
- buf = ''
- pos = 0
- for m in bodyre.finditer(desc):
- a, b = m.span()
- if a >= pos:
- buf += desc[pos:a]
- pos = b
- groups = m.groups()
- if groups[0]:
- cslink = groups[0]
- buf += '<a href="%s%s">%s</a>' % (revhashprefix, cslink, cslink)
- if groups[1]:
- urllink = groups[1]
- buf += '<a href="%s">%s</a>' % (urllink, urllink)
- if pos < len(desc):
- buf += desc[pos:]
-
- buf = '<pre>%s</pre>' % buf
- self._message.setHtml(buf)
+ self._message.setHtml('<pre>%s</pre>'
+ % self._htmlize(ctx.description()))
def minimumSizeHint(self):
return QSize(0, 25)
|
Loading...