aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--markdown/__init__.py5
-rw-r--r--markdown/blockparser.py2
2 files changed, 5 insertions, 2 deletions
diff --git a/markdown/__init__.py b/markdown/__init__.py
index 9d3a262..390329a 100644
--- a/markdown/__init__.py
+++ b/markdown/__init__.py
@@ -70,6 +70,7 @@ HTML_REMOVED_TEXT = "[HTML_REMOVED]" # text used instead of HTML in safe mode
BLOCK_LEVEL_ELEMENTS = re.compile("p|div|h[1-6]|blockquote|pre|table|dl|ol|ul"
"|script|noscript|form|fieldset|iframe|math"
"|ins|del|hr|hr/|style|li|dt|dd|tr")
+DOC_TAG = "div" # Element used to wrap document - later removed
# Placeholders
STX = u'\u0002' # Use STX ("Start of text") for start-of-placeholder
@@ -338,7 +339,9 @@ class Markdown:
# Serialize _properly_. Strip top-level tags.
xml, length = codecs.utf_8_decode(etree.tostring(root, encoding="utf8"))
if self.stripTopLevelTags:
- xml = xml.strip()[44:-7] + "\n"
+ start = xml.index('<%s>'%DOC_TAG)+len(DOC_TAG)+2
+ end = xml.rindex('</%s>'%DOC_TAG)
+ xml = xml[start:end].strip()
# Run the text post-processors
for pp in self.postprocessors.values():
diff --git a/markdown/blockparser.py b/markdown/blockparser.py
index 328d069..d9a9b2e 100644
--- a/markdown/blockparser.py
+++ b/markdown/blockparser.py
@@ -56,7 +56,7 @@ class BlockParser:
"""
# Create a ElementTree from the lines
- root = markdown.etree.Element("div")
+ root = markdown.etree.Element(markdown.DOC_TAG)
self.parseChunk(root, '\n'.join(lines))
return markdown.etree.ElementTree(root)