comparison MoinMoin/action/AttachFile.py @ 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 41995fbf3d92
comparison
equal deleted inserted replaced
1988:dbf2b7426385 1989:6d6379c9a1c9
977 timestamp = htdocs_access(request) and "?%s" % time.time() or '' 977 timestamp = htdocs_access(request) and "?%s" % time.time() or ''
978 request.write('<img src="%s%s" alt="%s">' % ( 978 request.write('<img src="%s%s" alt="%s">' % (
979 getAttachUrl(pagename, filename, request, escaped=1), timestamp, wikiutil.escape(filename, 1))) 979 getAttachUrl(pagename, filename, request, escaped=1), timestamp, wikiutil.escape(filename, 1)))
980 return 980 return
981 elif mt.major == 'text': 981 elif mt.major == 'text':
982 ext = os.path.splitext(filename)[1]
983 Parser = wikiutil.getParserForExtension(request.cfg, ext)
984 if Parser is not None:
985 try:
986 content = file(fpath, 'r').read()
987 content = wikiutil.decodeUnknownInput(content)
988 colorizer = Parser(content, request, filename=filename)
989 colorizer.format(request.formatter)
990 return
991 except IOError:
992 pass
993
994
982 request.write(request.formatter.preformatted(1)) 995 request.write(request.formatter.preformatted(1))
983 # Try to decode file contents. It may return junk, but we 996 # If we have text but no colorizing parser we try to decode file contents.
984 # don't have enough information on attachments.
985 content = open(fpath, 'r').read() 997 content = open(fpath, 'r').read()
986 content = wikiutil.decodeUnknownInput(content) 998 content = wikiutil.decodeUnknownInput(content)
987 content = wikiutil.escape(content) 999 content = wikiutil.escape(content)
988 request.write(request.formatter.text(content)) 1000 request.write(request.formatter.text(content))
989 request.write(request.formatter.preformatted(0)) 1001 request.write(request.formatter.preformatted(0))