From e8a88a71dc6ad2ae6d18a810f627d50ec97cc62c Mon Sep 17 00:00:00 2001 From: Eevee Date: Sat, 13 Mar 2010 18:11:40 -0800 Subject: [PATCH] Make rst as_html handle errors a little more nicely. --- pokedex/db/rst.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pokedex/db/rst.py b/pokedex/db/rst.py index 80ac87e..a77feef 100644 --- a/pokedex/db/rst.py +++ b/pokedex/db/rst.py @@ -33,6 +33,8 @@ are, apparently, global. return a reST node. """ +import cgi + from docutils.frontend import OptionParser from docutils.io import Output import docutils.nodes @@ -131,8 +133,17 @@ class RstString(object): """Returns the string as HTML4.""" document = self.rest_document - destination = UnicodeOutput() + # Check for errors; don't want to leave the default error message cruft + # in here + if document.next_node(condition=docutils.nodes.system_message): + # Boo! Cruft. + return u""" +

Error in markup! Raw source is below.

+
{0}
+ """.format( cgi.escape(self.source_text) ) + + destination = UnicodeOutput() writer = HTMLFragmentWriter() return writer.write(document, destination) -- 2.7.4