aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWaylan Limberg <waylan@gmail.com>2009-06-05 15:28:05 -0400
committerWaylan Limberg <waylan@gmail.com>2009-06-05 15:28:05 -0400
commit7bfdc831d2ad4fc0350ec4f020a4a79ff8d2845f (patch)
tree15f577ea4dc10f340453d0fdc12336af366873fb
parentb5036e91f7b9294cbe1777e3d4751cec5064c029 (diff)
downloadmarkdown-7bfdc831d2ad4fc0350ec4f020a4a79ff8d2845f.tar.gz
markdown-7bfdc831d2ad4fc0350ec4f020a4a79ff8d2845f.tar.bz2
markdown-7bfdc831d2ad4fc0350ec4f020a4a79ff8d2845f.zip
Fixed Ticket 34. stripToLevelTags now accounts for an empty document being returned (such as when a document only contains link references) and acts accordingly.
-rw-r--r--markdown/__init__.py14
1 files 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('</%s>'%DOC_TAG)
- output = output[start:end].strip()
+ try:
+ start = output.index('<%s>'%DOC_TAG)+len(DOC_TAG)+2
+ end = output.rindex('</%s>'%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():