Edgewall Software

Ticket #3326: mimeview-php-spans.diff

File mimeview-php-spans.diff, 1.8 KB (added by Tim Hatch <trac@…>, 2 years ago)

Diff against trunk@3483

  • trac/mimeview/php.py

     
    2121from trac.mimeview.api import IHTMLPreviewRenderer, content_to_unicode 
    2222from trac.util import NaivePopen 
    2323from trac.util.markup import Deuglifier 
     24import re 
    2425 
    2526__all__ = ['PHPRenderer'] 
    2627 
     
    3031 
    3132class PhpDeuglifier(Deuglifier): 
    3233 
     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 
    3347    def rules(cls): 
    3448        colors = dict(comment='FF8000', lang='0000BB', keyword='007700', 
    3549                      string='DD0000') 
     
    7185            err = 'Running (%s) failed: %s, %s.' % (cmdline, np.errorlevel, 
    7286                                                    np.err) 
    7387            raise Exception, err 
    74         odata = ''.join(np.out.splitlines()[1:-1]) 
     88        odata = ''.join(np.out.splitlines()[1:-2]) 
    7589        if odata.startswith('X-Powered-By'): 
    7690            raise TracError, 'You appear to be using the PHP CGI binary.  ' \ 
    7791                             'Trac requires the CLI version for syntax ' \