Commits

Anonymous committed e9a1976

[svn] refactored rtf formatter, added support for backtick highlighting in php lexer

Comments (0)

Files changed (2)

pygments/formatters/rtf.py

 
         # highlight stream
         for ttype, value in tokensource:
-            try:
-                style = self.style.style_for_token(ttype)
-            except KeyError:
-                start = ''
-            else:
-                buf = []
-                if style['bgcolor']:
-                    buf.append(r'\cb%d' % color_mapping[style['bgcolor']])
-                if style['color']:
-                    buf.append(r'\cf%d' % color_mapping[style['color']])
-                if style['bold']:
-                    buf.append(r'\b')
-                if style['italic']:
-                    buf.append(r'\i')
-                if style['underline']:
-                    buf.append(r'\ul')
-                if style['border']:
-                    buf.append(r'\chbrdr\chcfpat%d' % color_mapping[style['border']])
-                start = ''.join(buf)
+            while ttype not in self.style and ttype.parent:
+                ttype = ttype.parent
+            style = self.style.style_for_token(ttype)
+            buf = []
+            if style['bgcolor']:
+                buf.append(r'\cb%d' % color_mapping[style['bgcolor']])
+            if style['color']:
+                buf.append(r'\cf%d' % color_mapping[style['color']])
+            if style['bold']:
+                buf.append(r'\b')
+            if style['italic']:
+                buf.append(r'\i')
+            if style['underline']:
+                buf.append(r'\ul')
+            if style['border']:
+                buf.append(r'\chbrdr\chcfpat%d' % color_mapping[style['border']])
+            start = ''.join(buf)
             if start:
                 outfile.write('{%s ' % start)
             outfile.write(self._escape_text(value))

pygments/lexers/web.py

             (r"[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|"
              r"0[xX][0-9a-fA-F]+[Ll]?", Number),
             (r'"(\\\\|\\"|[^"])*"', String.Double),
-            (r"'(\\\\|\\'|[^'])*'", String.Single)
+            (r"'(\\\\|\\'|[^'])*'", String.Single),
+            (r'`(\\\\|\\`|[^`])*`', String.Backtick)
         ],
         'classname': [
             (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')