Ticket #3326: mimeview-php-spans.diff
| File mimeview-php-spans.diff, 1.8 KB (added by Tim Hatch <trac@…>, 2 years ago) |
|---|
-
trac/mimeview/php.py
21 21 from trac.mimeview.api import IHTMLPreviewRenderer, content_to_unicode 22 22 from trac.util import NaivePopen 23 23 from trac.util.markup import Deuglifier 24 import re 24 25 25 26 __all__ = ['PHPRenderer'] 26 27 … … 30 31 31 32 class PhpDeuglifier(Deuglifier): 32 33 34 def format(self, indata): 35 # The PHP highlighter produces the end-span tags on the next line 36 # instead of the line they actually apply to, which causes 37 # Trac to produce lots of (useless) open-and-immediately-close 38 # spans beginning each line. This tries to curtail by bubbling 39 # the first span after a set of 1+ "<br />" to before them. 40 r_fixeol = re.compile(r"((?:<br />)+)(</(?:font|span)>)") 41 indata = r_fixeol.sub(lambda m: m.group(2) + m.group(1), indata) 42 43 # Now call superclass implementation that handles the dirty work 44 # of applying css classes. 45 return Deuglifier.format(self, indata) 46 33 47 def rules(cls): 34 48 colors = dict(comment='FF8000', lang='0000BB', keyword='007700', 35 49 string='DD0000') … … 71 85 err = 'Running (%s) failed: %s, %s.' % (cmdline, np.errorlevel, 72 86 np.err) 73 87 raise Exception, err 74 odata = ''.join(np.out.splitlines()[1:- 1])88 odata = ''.join(np.out.splitlines()[1:-2]) 75 89 if odata.startswith('X-Powered-By'): 76 90 raise TracError, 'You appear to be using the PHP CGI binary. ' \ 77 91 'Trac requires the CLI version for syntax ' \
