[Zope3-checkins] CVS: zopeproducts/zwiki/renderer - rest.py:1.1 configure.zcml:1.2
Stephan Richter
srichter@cbu.edu
Wed, 9 Apr 2003 11:16:40 -0400
Update of /cvs-repository/zopeproducts/zwiki/renderer
In directory cvs.zope.org:/tmp/cvs-serv17101/renderer
Modified Files:
configure.zcml
Added Files:
rest.py
Log Message:
Added restructured text (reST) support as source type.
Note: **You must install the CVS version of docutils to make it work for
you!**
=== Added File zopeproducts/zwiki/renderer/rest.py ===
##############################################################################
#
# Copyright (c) 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Structured Text Renderer Classes
$Id: rest.py,v 1.1 2003/04/09 15:16:40 srichter Exp $
"""
import re
try:
import docutils.core, docutils.io
except:
docutils = None
from datetime import datetime
from zope.publisher.browser import BrowserView
from zopeproducts.zwiki.interfaces import IStructuredTextSource
from StructuredText import HTML
class ReStructuredTextToHTMLRenderer(BrowserView):
__implements__ = BrowserView.__implements__
__used_for__ = IStructuredTextSource
def render(self, context):
if docutils == None:
return "<h2>You do not have Python docutils installed.</h2>"
# format with strings
pub = docutils.core.Publisher()
pub.set_reader('standalone', None, 'restructuredtext')
pub.set_writer('html')
# go with the defaults
pub.get_settings()
# this is needed, but doesn't seem to do anything
pub.settings._destination = ''
# use the Wiki stylesheet
pub.settings.stylesheet = 'zwiki.css'
# set the reporting level to something sane
pub.settings.report_level = 0
# don't break if we get errors
pub.settings.halt_level = 6
# input
pub.source = docutils.io.StringInput(source=self.context)
# output - not that it's needed
pub.destination = docutils.io.StringOutput(encoding='UTF-8')
# parse!
document = pub.reader.read(pub.source, pub.parser, pub.settings)
# transform
pub.apply_transforms(document)
# do the format
html = pub.writer.write(document, pub.destination)
html = re.sub(
r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1', html)
return html
def createComment(self, comment, number):
date = self.request.locale.getDateTimeFormatter('medium').format(
datetime.now())
user = self.request.user.getLogin()
if number == 1:
return first_comment_template %(number, user, date, comment)
else:
return comment_template %(number, user, date, comment)
comment_template = '''
Comment #%i by **%s** (%s)
%s'''
first_comment_template = '''
----------
Comment #%i by **%s** (%s)
%s'''
=== zopeproducts/zwiki/renderer/configure.zcml 1.1 => 1.2 ===
--- zopeproducts/zwiki/renderer/configure.zcml:1.1 Tue Apr 8 22:49:11 2003
+++ zopeproducts/zwiki/renderer/configure.zcml Wed Apr 9 11:16:40 2003
@@ -11,11 +11,19 @@
</wiki:sourcetype>
<wiki:sourcetype
- title="Structured Text"
+ title="Structured Text (STX)"
interface="zopeproducts.zwiki.interfaces.IStructuredTextSource">
<wiki:renderer
for="zope.publisher.interfaces.browser.IBrowserPresentation"
factory=".stx.StructuredTextToHTMLRenderer" />
+</wiki:sourcetype>
+
+<wiki:sourcetype
+ title="reStructured Text (reST)"
+ interface="zopeproducts.zwiki.interfaces.IReStructuredTextSource">
+ <wiki:renderer
+ for="zope.publisher.interfaces.browser.IBrowserPresentation"
+ factory=".rest.ReStructuredTextToHTMLRenderer" />
</wiki:sourcetype>
</zopeConfigure>