Skip to content

Commit 2373a07

Browse files
author
Artem Yunusov
committed
Added reset methods for InlineStash and HtmlStash. Some cleanups and comments modifications.
1 parent 3f9ea69 commit 2373a07

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

markdown.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
2828
"""
2929

30-
version = "1.7"
31-
version_info = (1,7,0,"final")
30+
version = "2.0"
31+
version_info = (2,0,0, "beta")
3232
__revision__ = "$Rev$"
3333

3434

@@ -92,7 +92,7 @@ def importETree():
9292
def indentETree(elem, level=0):
9393

9494
if level > 1:
95-
i = "\n" + (level-1)*" "
95+
i = "\n" + (level-1) * " "
9696
else:
9797
i = "\n"
9898

@@ -394,9 +394,7 @@ def run (self, lines):
394394

395395
class LinePreprocessor(Preprocessor):
396396
"""
397-
Convert HR lines to raw html and store (needs to be done before
398-
processing lists).
399-
397+
Convert HR lines to "___" format
400398
"""
401399

402400
blockquote_re = re.compile(r'^(> )+')
@@ -410,7 +408,6 @@ def run (self, lines):
410408
if m:
411409
prefix = m.group(0)
412410
if self._isLine(lines[i][len(prefix):]):
413-
#lines[i] = prefix + self.stash.store("<hr />", safe=True)
414411
lines[i] = prefix + "___"
415412
return lines
416413

@@ -525,8 +522,6 @@ def run (self, lines):
525522
else:
526523
EMPHASIS_2_RE = r'(_)(.*?)\2' # _emphasis_
527524

528-
#LINK_RE = NOIMG + BRK + r'\s*\(([^\)]*)\)' # [text](url)
529-
530525
LINK_RE = NOIMG + BRK + \
531526
r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*)\12)?\)''' # [text](url) or [text](<url>)
532527

@@ -536,7 +531,7 @@ def run (self, lines):
536531
NOT_STRONG_RE = r'( \* )' # stand-alone * or _
537532
AUTOLINK_RE = r'<((?:f|ht)tps?://[^>]*)>' # <http://www.123.com>
538533
AUTOMAIL_RE = r'<([^> \!]*@[^> ]*)>' # <[email protected]>
539-
#HTML_RE = r'(\<[^\>]*\>)' # <...>
534+
540535
HTML_RE = r'(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)' # <...>
541536
ENTITY_RE = r'(&[\#a-zA-Z0-9]*;)' # &amp;
542537
LINE_BREAK_RE = r' \n' # two spaces at end of line
@@ -844,11 +839,11 @@ class Postprocessor:
844839
845840
"""
846841

847-
def run(self, et):
842+
def run(self, root):
848843
"""
849844
Subclasses of Postprocessor should implement a `run` method, which
850-
takes a ElementTree and returns a (possably modified) ElementTree.
851-
845+
takes a root Element. Method can return another Element, and global
846+
root Element will be replaced, or just mnodify current and return None.
852847
"""
853848
pass
854849

@@ -956,6 +951,10 @@ def store(self, html, safe=False):
956951
placeholder = HTML_PLACEHOLDER % self.html_counter
957952
self.html_counter += 1
958953
return placeholder
954+
955+
def rest(self):
956+
self.html_counter = 0
957+
self.rawHtmlBlocks = []
959958

960959

961960
class BlockGuru:
@@ -1090,6 +1089,9 @@ def add(self, node, type):
10901089
self._nodes[id] = node
10911090
return pholder
10921091

1092+
def rest(self):
1093+
self._nodes = {}
1094+
10931095
"""
10941096
======================================================================
10951097
========================== CORE MARKDOWN =============================
@@ -1207,8 +1209,9 @@ def __init__(self, source=None, # depreciated
12071209
]
12081210

12091211
self.inlineStash = InlineStash()
1210-
1211-
self._inlineOperationID = None
1212+
self.references = {}
1213+
self.htmlStash = HtmlStash()
1214+
12121215

12131216
self.registerExtensions(extensions = extensions,
12141217
configs = extension_configs)
@@ -1249,9 +1252,9 @@ def reset(self):
12491252
"""
12501253
Resets all state variables so that we can start with a new text.
12511254
"""
1252-
self.references={}
1253-
self.htmlStash = HtmlStash()
1254-
self.inlineStash = InlineStash()
1255+
self.inlineStash.rest()
1256+
self.htmlStash.rest()
1257+
self.references.clear()
12551258

12561259
HTML_BLOCK_PREPROCESSOR.stash = self.htmlStash
12571260
LINE_PREPROCESSOR.stash = self.htmlStash

mdx_tables.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,14 @@ def handleMatch(self, m):
2929
# otherwise it is a <td>
3030
td = etree.Element('td')
3131

32-
# apply inline patterns on chunks
33-
'''for n in self.md._handleInline(t):
34-
if(type(n) == unicode):
35-
td.text = n
36-
else:
37-
td.appendChild(n)'''
32+
# add text ot inline section, later it will be
33+
# processed by core
3834
inline = etree.SubElement(td, "inline")
3935
inline.text = t
4036

4137
tr.append(td)
4238
tr.tail = "\n"
4339

44-
#print etree.tostring(tr)
4540
return tr
4641

4742

test-markdown.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,9 @@ def get_benchmark_html (actual, expected) :
358358
testDirectory("tests/markdown-test", measure_time=True)
359359

360360
testDirectory("tests/misc", measure_time=True)
361+
361362
testDirectory("tests/extensions-x-tables")
362363
#testDirectory("tests/extensions-x-footnotes")
363-
#testDirectory("tests/extensions-x-tables")
364364
#testDirectory("tests/extensions-x-ext1-ext2")
365365
testDirectory("tests/safe_mode", measure_time=True, safe_mode="escape")
366366
#testDirectory("tests/extensions-x-codehilite")

0 commit comments

Comments
 (0)