changeset 1989:6d6379c9a1c9

AttachFile.send_viewfile: uses now colorizing parsers on view for mimetype text
author Reimar Bauer <rb.proj AT googlemail DOT com>
date Thu, 12 Apr 2007 23:45:48 +0200
parents dbf2b7426385
children 9051a3a23124
files MoinMoin/action/AttachFile.py
diffstat 1 files changed, 14 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Tue Apr 10 00:13:49 2007 +0200
+++ b/MoinMoin/action/AttachFile.py	Thu Apr 12 23:45:48 2007 +0200
@@ -979,9 +979,21 @@
             getAttachUrl(pagename, filename, request, escaped=1), timestamp, wikiutil.escape(filename, 1)))
         return
     elif mt.major == 'text':
+        ext = os.path.splitext(filename)[1]
+        Parser = wikiutil.getParserForExtension(request.cfg, ext)
+        if Parser is not None:
+            try:
+                content = file(fpath, 'r').read()
+                content = wikiutil.decodeUnknownInput(content)
+                colorizer = Parser(content, request, filename=filename)
+                colorizer.format(request.formatter)
+                return
+            except IOError:
+                pass
+
+
         request.write(request.formatter.preformatted(1))
-        # Try to decode file contents. It may return junk, but we
-        # don't have enough information on attachments.
+        # If we have text but no colorizing parser we try to decode file contents. 
         content = open(fpath, 'r').read()
         content = wikiutil.decodeUnknownInput(content)
         content = wikiutil.escape(content)