[Zope3-Users] Disable raw directive in restructured text
Florian Lindner
mailinglists at xgm.de
Thu Mar 15 18:14:19 EDT 2007
Am Donnerstag, 15. März 2007 22:01 schrieb Jonathan:
> ----- Original Message -----
> From: "Florian Lindner" <mailinglists at xgm.de>
> To: <zope3-users at zope.org>
> Cc: "Jonathan" <dev101 at magma.ca>
> Sent: Thursday, March 15, 2007 4:56 PM
> Subject: Re: [Zope3-Users] Disable raw directive in restructured text
>
> > Am Donnerstag, 15. März 2007 21:14 schrieb Jonathan:
> >> ----- Original Message -----
> >> From: "Florian Lindner" <mailinglists at xgm.de>
> >> To: <zope3-users at zope.org>
> >> Sent: Thursday, March 15, 2007 3:46 PM
> >> Subject: [Zope3-Users] Disable raw directive in restructured text
> >>
> >> > Hello,
> >> > I'm using this code to render a rest snippet to HTML:
> >> >
> >> > def convertToHTML(self, comment):
> >> > """ Converts a comment from restructured text to HTML. """
> >> > text = unicode(comment.content)
> >> > renderer = ReStructuredTextToHTMLRenderer(text, self.request)
> >> > return renderer.render().strip()
> >> >
> >> > Since the text in entered by users I want to disable the raw directive
> >> > [1].
> >> > How can I do this? (only while rendering this text, not globally)
> >>
> >> How about passing the original (ie. user-entered) ReST data to your
> >> display
> >> widget which then strips the 'raw::' string from the rest data before
> >> calling convertToHTML?
> >>
> >> Alternatively, pass an additional arguement to convToHTML which is a
> >> flag that tells the routine whether or not to strip the raw command from
> >> the passed text string before processing it.
> >
> > Of course it's possible to strip it before passing the text to the rest
> > renderer. But maybe somebody wants to really print .. raw:: html, maybe
> > giving an example of the directive. If I would have stripped the raw
> > there would be no text at all, but I want the raw to be treated just like
> > any other
> > text.
>
> If you want to preserve the raw command, how about swaping the 'raw::'
> directive for a placeholder (eg. ||rw|| ), process the ReST data normally,
> then swap the 'raw::' command back in place of the placeholder?
I've found out it could partly be achieved by using:
def convertToHTML(self, comment):
""" Converts a comment from restructured text to HTML. """
text = unicode(comment.content)
settings_override = {}
settings_override["raw_enabled"] = False
settings_override["file_insertion_enabled"] = False
# settings_override["report_level"] = "quiet"
renderer = ReStructuredTextToHTMLRenderer(text, self.request)
return renderer.render(settings_override).strip()
but now a raw directive generates an error message whereas it is completely
swallowed when uncommenting the report_level.
Regards,
Florian
More information about the Zope3-users
mailing list