diff options
author | Waylan Limberg <waylan@gmail.com> | 2008-12-10 21:39:44 -0500 |
---|---|---|
committer | Waylan Limberg <waylan@gmail.com> | 2008-12-10 21:41:56 -0500 |
commit | d6711cf39b8043aa8c24ee80b0c126a555ebf3e0 (patch) | |
tree | 18a004485212a1f976775de7fe4245886b510e3a | |
parent | c669bf05af8a8ff89b6c7dc9b1255ef396a41a8f (diff) | |
download | markdown-d6711cf39b8043aa8c24ee80b0c126a555ebf3e0.tar.gz markdown-d6711cf39b8043aa8c24ee80b0c126a555ebf3e0.tar.bz2 markdown-d6711cf39b8043aa8c24ee80b0c126a555ebf3e0.zip |
Normalized stripTopLevelTags to be consistant regardless of any whitespace. For example, this would allow an extension to remove/replace 'Prettify' treeprocessor with something that added more or less whitespace without adverse effects.
-rw-r--r-- | markdown/__init__.py | 5 | ||||
-rw-r--r-- | markdown/blockparser.py | 2 |
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) |