From 7bfdc831d2ad4fc0350ec4f020a4a79ff8d2845f Mon Sep 17 00:00:00 2001 From: Waylan Limberg Date: Fri, 5 Jun 2009 15:28:05 -0400 Subject: Fixed Ticket 34. stripToLevelTags now accounts for an empty document being returned (such as when a document only contains link references) and acts accordingly. --- markdown/__init__.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/markdown/__init__.py b/markdown/__init__.py index 641cbab..086fde9 100644 --- a/markdown/__init__.py +++ b/markdown/__init__.py @@ -397,9 +397,17 @@ class Markdown: # Serialize _properly_. Strip top-level tags. output, length = codecs.utf_8_decode(self.serializer(root, encoding="utf8")) if self.stripTopLevelTags: - start = output.index('<%s>'%DOC_TAG)+len(DOC_TAG)+2 - end = output.rindex(''%DOC_TAG) - output = output[start:end].strip() + try: + start = output.index('<%s>'%DOC_TAG)+len(DOC_TAG)+2 + end = output.rindex(''%DOC_TAG) + output = output[start:end].strip() + except ValueError: + if output.strip().endswith('<%s />'%DOC_TAG): + # We have an empty document + output = '' + else: + # We have a serious problem + message(CRITICAL, 'Failed to strip top level tags.') # Run the text post-processors for pp in self.postprocessors.values(): -- cgit v1.2.3