From 9f7a4f2f71c929c8a2154008b70b039450afcc85 Mon Sep 17 00:00:00 2001 From: Yuri Takhteyev Date: Mon, 19 Mar 2007 00:58:14 +0000 Subject: Fixed a bug introduced in the previous version (ampersands were no longer normalized) and added support for a CDATA node in NanoDom. --- markdown.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'markdown.py') diff --git a/markdown.py b/markdown.py index 93851e5..c57ef47 100644 --- a/markdown.py +++ b/markdown.py @@ -84,6 +84,11 @@ Importantly, NanoDom does not do normalization, which is what we want. It also adds extra white space when converting DOM to string """ +ENTITY_NORMALIZATION_EXPRESSIONS = [ (re.compile("&(?!\#)"), "&"), + (re.compile("<"), "<"), + (re.compile(">"), ">"), + (re.compile("\""), """)] + class Document : @@ -109,19 +114,18 @@ class Document : self.entities[entity] = EntityReference(entity) return self.entities[entity] + def createCDATA(self, text) : + node = CDATA(text) + node.doc = self + return node + def toxml (self) : return self.documentElement.toxml() def normalizeEntities(self, text) : - pairs = [ ("&(?!#)", "&"), - ("<", "<"), - (">", ">"), - ("\"", """)] - - - for old, new in pairs : - text = text.replace(old, new) + for regexp, substitution in ENTITY_NORMALIZATION_EXPRESSIONS : + text = regexp.sub(substitution, text) return text def find(self, test) : @@ -132,6 +136,19 @@ class Document : self.documentElement = None +class CDATA : + + type = "cdata" + + def __init__ (self, text) : + self.text = text + + def handleAttributes(self) : + pass + + def toxml (self) : + return "" + class Element : type = "element" -- cgit v1.2.3