El Mon, Jul 24, 2006 at 01:34:52PM +0200, Thomas Sturm va escriure: > Hello, > > I have several *.html files in my repositroy (the documentation > of 'cppunit'). > They have all the "svn:mimetype text/html". > > If I refer to them, I get the 'normal' source code view, i.e. the > HTML source. With a link at the bottom: "Original Form" I can get > the real rendered HTML. > > What can I do in the wiki, with wiki syntax, to get real rendered > HTML documentation and not the HTML source?
I wrote a macro to do this kind of thing (I use it to show on the wiki parsed reStructuredText files, but it should also work for HTML). Install the attached file into your projects wiki-macros directory and write the following on a Wiki page: [[IncludeSVNFile(/path/to/file.html,text/html)]] Note that inline images will not be shown (the same happens when viewing the html files on the svn browser, anyway). If it works for you and you feel it is useful tell me and I'll add the macro to the trac-hacks site (I tried to add it to the edgewall wiki sometime ago but it failed and I forgot about it until now). Greetings, Sergio. -- Sergio Talens-Oliag <[EMAIL PROTECTED]> <http://people.debian.org/~sto/> Key fingerprint = 29DF 544F 1BD9 548C 8F15 86EF 6770 052B B8C1 FA69
# ------------
# Trac Add-ons
# ------------
# Module: wiki-macros
# File: IncludeSVNFile.py
# Author: Sergio Talens-Oliag <[EMAIL PROTECTED]>
# Copyright: (c) 2006 Sergio Talens-Oliag <[EMAIL PROTECTED]>
# SVN Id: $Id: IncludeSVNFile.py 11 2006-03-27 16:30:12Z sto $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
# ---------------------
# -*- coding: utf-8 -*-
# ---------------------
"""
Trac Wiki-Macro that takes the PATH of a svn file (relative to the svn root)
and includes it on a wiki page parsed as in the 'browser' view.
The macro takes two arguments separated by commas, the PATH and an optional
mime-type that will be used instead of the one guessed by get_mimetype.
Examples:
- This will include the formated python file:
[[IncludeSVNFile(/tools/trac/wiki-macros/IncludeSVNFile.py)]]
- This will include the same file formated as a plain text file
[[IncludeSVNFile(/tools/trac/wiki-macros/IncludeSVNFile.py,text/plain)]]
"""
from trac import util
from trac.mimeview import Mimeview, get_mimetype
from StringIO import StringIO
def execute(hdf, args, env):
path = None
mime_type = None
buf = StringIO()
# Process args
args = args.replace('\'', '\'\'')
argv = [arg.strip() for arg in args.split(',')]
if len(argv) > 0:
path = argv[0]
if len(argv) > 1:
mime_type = argv[1]
# Get svn node
try:
repos = env.get_repository()
node = repos.get_node(path)
except Exception, e:
raise util.TracError(\
'The string "%s" doesn\'t seem to be a valid SVN path.\n' \
'The error was: "%s"' % (path, e))
# Parse file
if node != None:
try:
mimeview = Mimeview(env)
if not mime_type:
mime_type = node.content_type
if not mime_type or mime_type == 'application/octet-stream':
mime_type = get_mimetype(node.name) or mime_type or 'text/plain'
content = node.get_content().read(mimeview.max_preview_size())
buf.write(mimeview.render(None, mime_type, content))
except Exception, e:
raise util.TracError('Error parsing "%s" of type "%s".'
' The error was "%s"' % (path, mime_type, e))
return buf.getvalue()
# ------
# SVN Id: $Id: IncludeSVNFile.py 11 2006-03-27 16:30:12Z sto $
signature.asc
Description: Digital signature
_______________________________________________ Trac mailing list [email protected] http://lists.edgewall.com/mailman/listinfo/trac
