changeset 4383:e25b00b3a308

replace the diff parser by a thin wrapper around the highlight parser (to keep syntax like {{{#!diff ... working)
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 12 Oct 2008 00:26:49 +0200
parents 5eb02932f387
children 09328e4aab45
files MoinMoin/parser/highlight.py MoinMoin/parser/text_diff.py
diffstat 2 files changed, 28 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/parser/highlight.py	Sat Oct 11 23:54:29 2008 +0200
+++ b/MoinMoin/parser/highlight.py	Sun Oct 12 00:26:49 2008 +0200
@@ -63,6 +63,16 @@
             return 'ID'
         elif ttype in Token.Comment:
             return 'Comment'
+        elif ttype in Token.Generic.Heading:
+            return 'Comment'
+        elif ttype in Token.Generic.Subheading:
+            return 'DiffSeparator'
+        elif ttype in Token.Generic.Inserted:
+            return 'DiffAdded'
+        elif ttype in Token.Generic.Deleted:
+            return 'DiffRemoved'
+        elif ttype in Token.Generic.Strong:
+            return 'DiffChanged'
         else:
             # skip tags that have no class defined
             return None
--- a/MoinMoin/parser/text_diff.py	Sat Oct 11 23:54:29 2008 +0200
+++ b/MoinMoin/parser/text_diff.py	Sun Oct 12 00:26:49 2008 +0200
@@ -1,39 +1,26 @@
 # -*- coding: iso-8859-1 -*-
 """
-    MoinMoin - Diff Parser - highlights diff tool output
+    MoinMoin - diff/patch Parser
+    
+    DEPRECATED compatibility wrapper calling the highlight parser.
+    
+    This is to support (deprecated) existing syntax like:
+    {{{#!diff ...
+    ...
+    }}}
 
-    @copyright: 2006 Emilio Lopes, inspired by previous work
-                done by Fabien Ninoles and Juergen Hermann
+    It is equivalent to the new way to highlight code:
+    {{{#!highlight diff ...
+    ...
+    }}}
+
+    @copyright: 2008 MoinMoin:ThomasWaldmann
     @license: GNU GPL, see COPYING for details.
 """
 
-from MoinMoin.parser._ParserBase import ParserBase
-
-class Parser(ParserBase):
-    parsername = "ColorizedDiff"
-    extensions = ['.diff', '.patch', ]
-    Dependencies = []
-
-    def setupRules(self):
-        ParserBase.setupRules(self)
+from MoinMoin.parser.highlight import Parser as HighlightParser
+from MoinMoin.parser.highlight import Dependencies
 
-        self.addRule("Comment", r'^(diff .*?)$')
-        self.addRule("Comment", r'^(\*\*\* .*?)$')
-        self.addRule("Comment", r'^(--- .*?)$')
-        self.addRule("Comment", r'^(\+\+\+ .*?)$')
-        self.addRule("Comment", r'^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* *$')
-
-        self.addRule("DiffSeparator", r'^(@@ .*?)$')
-        self.addRule("DiffSeparator", r'^--- *$')
+class Parser(HighlightParser):
+    parsername = 'diff'  # Lexer name pygments recognizes
 
-        self.addRule("DiffAdded", r'^(\+.*?)$')
-        self.addRule("DiffRemoved", r'^(-.*?)$')
-        self.addRule("DiffAdded", r'^(>.*?)$')
-        self.addRule("DiffRemoved", r'^(<.*?)$')
-        self.addRule("DiffChanged", r'^(!.*?)$')
-
-        self.addRuleFormat("DiffAdded")
-        self.addRuleFormat("DiffRemoved")
-        self.addRuleFormat("DiffChanged")
-        self.addRuleFormat("DiffSeparator")
-