aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmarkdown.py39
-rwxr-xr-xmdx_tables.py9
-rw-r--r--test-markdown.py2
3 files changed, 24 insertions, 26 deletions
diff --git a/markdown.py b/markdown.py
index 7c78b18..c2910ca 100755
--- a/markdown.py
+++ b/markdown.py
@@ -27,8 +27,8 @@ License: [GPL 2](http://www.gnu.org/copyleft/gpl.html) or BSD
"""
-version = "1.7"
-version_info = (1,7,0,"final")
+version = "2.0"
+version_info = (2,0,0, "beta")
__revision__ = "$Rev$"
@@ -92,7 +92,7 @@ etree = importETree()
def indentETree(elem, level=0):
if level > 1:
- i = "\n" + (level-1)*" "
+ i = "\n" + (level-1) * " "
else:
i = "\n"
@@ -394,9 +394,7 @@ HEADER_PREPROCESSOR = HeaderPreprocessor()
class LinePreprocessor(Preprocessor):
"""
- Convert HR lines to raw html and store (needs to be done before
- processing lists).
-
+ Convert HR lines to "___" format
"""
blockquote_re = re.compile(r'^(> )+')
@@ -410,7 +408,6 @@ class LinePreprocessor(Preprocessor):
if m:
prefix = m.group(0)
if self._isLine(lines[i][len(prefix):]):
- #lines[i] = prefix + self.stash.store("<hr />", safe=True)
lines[i] = prefix + "___"
return lines
@@ -525,8 +522,6 @@ if SMART_EMPHASIS:
else:
EMPHASIS_2_RE = r'(_)(.*?)\2' # _emphasis_
-#LINK_RE = NOIMG + BRK + r'\s*\(([^\)]*)\)' # [text](url)
-
LINK_RE = NOIMG + BRK + \
r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*)\12)?\)''' # [text](url) or [text](<url>)
@@ -536,7 +531,7 @@ IMAGE_REFERENCE_RE = r'\!' + BRK + '\s*\[([^\]]*)\]' # ![alt text][2]
NOT_STRONG_RE = r'( \* )' # stand-alone * or _
AUTOLINK_RE = r'<((?:f|ht)tps?://[^>]*)>' # <http://www.123.com>
AUTOMAIL_RE = r'<([^> \!]*@[^> ]*)>' # <me@example.com>
-#HTML_RE = r'(\<[^\>]*\>)' # <...>
+
HTML_RE = r'(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)' # <...>
ENTITY_RE = r'(&[\#a-zA-Z0-9]*;)' # &amp;
LINE_BREAK_RE = r' \n' # two spaces at end of line
@@ -844,11 +839,11 @@ class Postprocessor:
"""
- def run(self, et):
+ def run(self, root):
"""
Subclasses of Postprocessor should implement a `run` method, which
- takes a ElementTree and returns a (possably modified) ElementTree.
-
+ takes a root Element. Method can return another Element, and global
+ root Element will be replaced, or just mnodify current and return None.
"""
pass
@@ -956,6 +951,10 @@ class HtmlStash:
placeholder = HTML_PLACEHOLDER % self.html_counter
self.html_counter += 1
return placeholder
+
+ def rest(self):
+ self.html_counter = 0
+ self.rawHtmlBlocks = []
class BlockGuru:
@@ -1090,6 +1089,9 @@ class InlineStash:
self._nodes[id] = node
return pholder
+ def rest(self):
+ self._nodes = {}
+
"""
======================================================================
========================== CORE MARKDOWN =============================
@@ -1207,8 +1209,9 @@ class Markdown:
]
self.inlineStash = InlineStash()
-
- self._inlineOperationID = None
+ self.references = {}
+ self.htmlStash = HtmlStash()
+
self.registerExtensions(extensions = extensions,
configs = extension_configs)
@@ -1249,9 +1252,9 @@ class Markdown:
"""
Resets all state variables so that we can start with a new text.
"""
- self.references={}
- self.htmlStash = HtmlStash()
- self.inlineStash = InlineStash()
+ self.inlineStash.rest()
+ self.htmlStash.rest()
+ self.references.clear()
HTML_BLOCK_PREPROCESSOR.stash = self.htmlStash
LINE_PREPROCESSOR.stash = self.htmlStash
diff --git a/mdx_tables.py b/mdx_tables.py
index 5c7881a..829044c 100755
--- a/mdx_tables.py
+++ b/mdx_tables.py
@@ -29,19 +29,14 @@ class TablePattern(markdown.Pattern) :
# otherwise it is a <td>
td = etree.Element('td')
- # apply inline patterns on chunks
- '''for n in self.md._handleInline(t):
- if(type(n) == unicode):
- td.text = n
- else:
- td.appendChild(n)'''
+ # add text ot inline section, later it will be
+ # processed by core
inline = etree.SubElement(td, "inline")
inline.text = t
tr.append(td)
tr.tail = "\n"
- #print etree.tostring(tr)
return tr
diff --git a/test-markdown.py b/test-markdown.py
index 3ada7dd..041523d 100644
--- a/test-markdown.py
+++ b/test-markdown.py
@@ -358,9 +358,9 @@ markdown = __import__(MARKDOWN_FILE)
testDirectory("tests/markdown-test", measure_time=True)
testDirectory("tests/misc", measure_time=True)
+
testDirectory("tests/extensions-x-tables")
#testDirectory("tests/extensions-x-footnotes")
-#testDirectory("tests/extensions-x-tables")
#testDirectory("tests/extensions-x-ext1-ext2")
testDirectory("tests/safe_mode", measure_time=True, safe_mode="escape")
#testDirectory("tests/extensions-x-codehilite")