aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYuri Takhteyev <yuri@freewisdom.org>2007-03-19 00:58:14 +0000
committerYuri Takhteyev <yuri@freewisdom.org>2007-03-19 00:58:14 +0000
commit9f7a4f2f71c929c8a2154008b70b039450afcc85 (patch)
tree404f8ee93f9c248fb2463b8c53552ada7c7b4d2f
parentee7fa0490de7336dac569cbd5d14289b6cab8940 (diff)
downloadmarkdown-9f7a4f2f71c929c8a2154008b70b039450afcc85.tar.gz
markdown-9f7a4f2f71c929c8a2154008b70b039450afcc85.tar.bz2
markdown-9f7a4f2f71c929c8a2154008b70b039450afcc85.zip
Fixed a bug introduced in the previous version (ampersands were no
longer normalized) and added support for a CDATA node in NanoDom.
-rw-r--r--markdown.py33
1 files changed, 25 insertions, 8 deletions
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("&(?!\#)"), "&amp;"),
+ (re.compile("<"), "&lt;"),
+ (re.compile(">"), "&gt;"),
+ (re.compile("\""), "&quot;")]
+
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 = [ ("&(?!#)", "&amp;"),
- ("<", "&lt;"),
- (">", "&gt;"),
- ("\"", "&quot;")]
-
-
- 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 "<![CDATA[" + self.text + "]]>"
+
class Element :
type = "element"