[Moin-user] Displaying HTML source code as attachment
cpghost
cpghost at cordula.ws
Mon Aug 18 09:34:57 EDT 2008
>> Date: Wed, 23 Jul 2008 21:52:10 +0200
>> From: cpghost <cpghost at cordula.ws>
>> Subject: [Moin-user] Displaying HTML source code as attachment
>>
>> Hello,
>>
>> after upgrading from MoinMoin 1.5.8 to 1.7.0, files ending
>> with .html (and .xml), attached with {{attachment:file.html}}
>> don't appear as source code anymore, but are rendered by the
>> browser.
>>
>> Is there a way to turn off this behavior and revert back to
>> the old way of displaying the content of those files as
>> plain boring text/plain inline attachment (short of renaming
>> them by appending a .txt as in file.html.txt which I'd prefer
>> to avoid)?
>>
>> I've tried to add the following to the file
>> $PYTHON_PATH/site-packages/MoinMoin/wikiutil.py
>> but while it works for the additional extensions
>> like '.dat', '.cxx' etc. it doesn't work for '.html'
>> nor '.xml':
>>
>> MIMETYPES_MORE = {
>> # ...
>> '.dat': 'text/plain',
>> '.cxx': 'text/x-c++src',
>> '.i': 'text/x-c++src',
>> '.schema': 'text/plain',
>> '.rpy': 'text/x-python',
>> '.wsgi': 'text/x-python',
>> '.php': 'text/plain', # see MIMETYPES_sanitize_mapping
>> '.html': 'text/plain', # don't render as HTML! (won't work)
>> '.xml': 'text/plain', # don't render as HTML! (won't work)
>> }
>>
>> MIMETYPES_sanitize_mapping = {
>> # ...
>> ('application', 'x-httpd-php'): ('text', 'plain'),
>> ('text', 'html'): ('text', 'plain'), # (won't work)
>> }
>
> Date: Thu, 24 Jul 2008 15:33:39 +0200
> From: Thomas Waldmann <tw-public at gmx.de>
> Subject: Re: [Moin-user] Displaying HTML source code as attachment
>
>> after upgrading from MoinMoin 1.5.8 to 1.7.0,
>
> BTW (unrelated to your post) 1.7.1 is out.
Thanks. Since I'm using a set of patches to MoinMoin itself (not only
in $INSTANCE_HOME) to generate LaTeX, I'm a bit slow to catch up... ;)
> > files ending
> > with .html (and .xml), attached with {{attachment:file.html}}
> > don't appear as source code anymore, but are rendered by the
> > browser.
>
> Moin 1.5 didn't have that syntax.
>
> {{...}} means transclude ("render here")
> [[...]] means link.
You're right. I meant 'attachment:file.html' without the curlies
before 1.7.0 and {{attachment:file.html}} for transcludes with
1.7.X...
> > Is there a way to turn off this behavior and revert back to
> > the old way of displaying the content of those files as
> > plain boring text/plain inline attachment (short of renaming
> > them by appending a .txt as in file.html.txt which I'd prefer
> > to avoid)?
>
> Well, appending .txt might be the only way currently, because it detects
> the mimetype from the suffix (and then, also sends that mimetype to the
> browser).
>
> Of course you can use a parser section / pre section and paste the stuff
> there, but maybe you don't want to handle it that way.
What I've done for now is this:
In $INSTANCE_HOME/data/plugin/parser, I've added a file html.py
which contains this:
---------------- BEGIN html.py ------------------------------------------
# -*- coding: iso-8859-1 -*-
Dependencies = []
class Parser:
"""
Send plain text in a HTML <pre> element.
"""
extensions = ['.html']
Dependencies = []
def __init__(self, raw, request, **kw):
self.raw = raw
self.request = request
self.form = request.form
self._ = request.getText
def format(self, formatter):
""" Send the text. """
self.request.write(formatter.preformatted(1))
self.request.write(formatter.text(self.raw.expandtabs()))
self.request.write(formatter.preformatted(0))
---------------- END html.py ------------------------------------------
It does work quite well...
> > I've tried to add the following to the file
> > $PYTHON_PATH/site-packages/MoinMoin/wikiutil.py
> > but while it works for the additional extensions
> > like '.dat', '.cxx' etc. it doesn't work for '.html'
> > nor '.xml':
> >
> > MIMETYPES_MORE = {
> > # ...
> > '.dat': 'text/plain',
> > '.cxx': 'text/x-c++src',
> > '.i': 'text/x-c++src',
> > '.schema': 'text/plain',
> > '.rpy': 'text/x-python',
> > '.wsgi': 'text/x-python',
> > '.php': 'text/plain', # see MIMETYPES_sanitize_mapping
> > '.html': 'text/plain', # don't render as HTML! (won't work)
> > '.xml': 'text/plain', # don't render as HTML! (won't work)
> > }
> >
> > MIMETYPES_sanitize_mapping = {
> > # ...
> > ('application', 'x-httpd-php'): ('text', 'plain'),
> > ('text', 'html'): ('text', 'plain'), # (won't work)
> > }
>
> That SHOULD work. Did you restart moin after changing configuration?
Yes, of course I did that. But it was useless...
> Your python version?
2.5.2
Anyway, using a custom parser for '.html' that renders preformatted
text solved the problem quite nicely. ;)
Thanks again,
-cpghost.
--
Cordula's Web. http://www.cordula.ws/
More information about the Moin-user
mailing list