diff options
author | Artem <artem@artem.(none)> | 2008-06-24 20:03:10 +0500 |
---|---|---|
committer | Artem <artem@artem.(none)> | 2008-06-24 20:03:10 +0500 |
commit | eede42cb87a74b1a91b360a218d05f9a5c703e55 (patch) | |
tree | a6ab44d84a5b9f1ad1d1883c21c74ccc4d3f7b07 | |
parent | 356cd58e06e38ace4a4ea65ac0cbbdbe910e5dfc (diff) | |
download | markdown-eede42cb87a74b1a91b360a218d05f9a5c703e55.tar.gz markdown-eede42cb87a74b1a91b360a218d05f9a5c703e55.tar.bz2 markdown-eede42cb87a74b1a91b360a218d05f9a5c703e55.zip |
first commit
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | markdown.py | 32 | ||||
-rw-r--r-- | test-markdown.py | 7 |
3 files changed, 25 insertions, 15 deletions
@@ -2,3 +2,4 @@ *.bak *.tmp tmp/* +__init__.py diff --git a/markdown.py b/markdown.py index 422cde4..131e318 100644 --- a/markdown.py +++ b/markdown.py @@ -152,7 +152,9 @@ def getBidiType(text): Get Bi-directional text type. Used by TextNode to determine text direction. """ - if not text: return None + if not text: + return None + ch = text[0] @@ -182,7 +184,8 @@ class Document: """ Add a dom element as a child of the document root. """ self.documentElement = child child.isDocumentElement = True - child.parent = self + child.parentNode = self + self.entities = {} def setBidi(self, bidi): @@ -284,7 +287,8 @@ class Element: if not self.bidi or self.isDocumentElement: # Once the bidi is set don't change it (except for doc element) self.bidi = bidi - self.parent.setBidi(bidi) + self.parentNode.setBidi(bidi) + def unlink(self): @@ -306,13 +310,13 @@ class Element: def insertChild(self, position, child): """ Insert a child Element at the given position. """ self.childNodes.insert(position, child) - child.parent = self + child.parentNode = self def removeChild(self, child): """ Remove the given child from the Element. """ self.childNodes.remove(child) - def replaceChild(self, oldChild, newChild): + def replaceChild(self, newChild, oldChild): """ Replace an old child Element with a new child Element. """ position = self.childNodes.index(oldChild) self.removeChild(oldChild) @@ -321,7 +325,7 @@ class Element: def appendChild(self, child): """ Append a new child Element to the end of the child Elements. """ self.childNodes.append(child) - child.parent = self + child.parentNode = self def handleAttributes(self): """ Not implemented for Element node type. """ @@ -410,7 +414,7 @@ class TextNode: def attributeCallback(self, match): """ Regex callback method to set attribute on parent. """ - self.parent.setAttribute(match.group(1), match.group(2)) + self.parentNode.setAttribute(match.group(1), match.group(2)) def handleAttributes(self): """ Parse and assign attributes to the parent Element. """ @@ -420,13 +424,16 @@ class TextNode: """ Return the TextNode as a string. """ text = self.value - self.parent.setBidi(getBidiType(text)) - + self.parentNode.setBidi(getBidiType(text)) + if not text.startswith(HTML_PLACEHOLDER_PREFIX): - if self.parent.nodeName == "p": + if self.parentNode.nodeName == "p": + text = text.replace("\n", "\n ") - elif (self.parent.nodeName == "li" - and self.parent.childNodes[0]==self): + + elif (self.parentNode.nodeName == "li" + and self.parentNode.childNodes[0]==self): + text = "\n " + text.replace("\n", "\n ") text = self.doc.normalizeEntities(text) return text @@ -448,7 +455,6 @@ class EntityReference: """ Return the EntityReference as a string. """ return "&" + self.entity + ";" - """ ====================================================================== ========================== PRE-PROCESSORS ============================ diff --git a/test-markdown.py b/test-markdown.py index bc2b891..219db50 100644 --- a/test-markdown.py +++ b/test-markdown.py @@ -353,11 +353,14 @@ print MARKDOWN_FILE markdown = __import__(MARKDOWN_FILE) - +""" #testDirectory("tests/basic") testDirectory("tests/markdown-test", measure_time=True) testDirectory("tests/misc", measure_time=True) #testDirectory("tests/extensions-x-footnotes") # testDirectory("tests/extensions-x-ext1-ext2") -testDirectory("tests/safe_mode", measure_time=True, safe_mode="escape") +testDirectory("tests/safe_mode", measure_time=True, safe_mode="escape") """ + +testDirectory("tests2/php-markdown-cases-new", measure_time=True) +testDirectory("tests2/tm-cases-new", measure_time=True) |