27
27
28
28
"""
29
29
30
- version = "1.7 "
31
- version_info = (1 , 7 ,0 ,"final " )
30
+ version = "2.0 "
31
+ version_info = (2 , 0 ,0 , "beta " )
32
32
__revision__ = "$Rev$"
33
33
34
34
@@ -92,7 +92,7 @@ def importETree():
92
92
def indentETree (elem , level = 0 ):
93
93
94
94
if level > 1 :
95
- i = "\n " + (level - 1 )* " "
95
+ i = "\n " + (level - 1 ) * " "
96
96
else :
97
97
i = "\n "
98
98
@@ -394,9 +394,7 @@ def run (self, lines):
394
394
395
395
class LinePreprocessor (Preprocessor ):
396
396
"""
397
- Convert HR lines to raw html and store (needs to be done before
398
- processing lists).
399
-
397
+ Convert HR lines to "___" format
400
398
"""
401
399
402
400
blockquote_re = re .compile (r'^(> )+' )
@@ -410,7 +408,6 @@ def run (self, lines):
410
408
if m :
411
409
prefix = m .group (0 )
412
410
if self ._isLine (lines [i ][len (prefix ):]):
413
- #lines[i] = prefix + self.stash.store("<hr />", safe=True)
414
411
lines [i ] = prefix + "___"
415
412
return lines
416
413
@@ -525,8 +522,6 @@ def run (self, lines):
525
522
else :
526
523
EMPHASIS_2_RE = r'(_)(.*?)\2' # _emphasis_
527
524
528
- #LINK_RE = NOIMG + BRK + r'\s*\(([^\)]*)\)' # [text](url)
529
-
530
525
LINK_RE = NOIMG + BRK + \
531
526
r'''\(\s*(<.*?>|((?:(?:\(.*?\))|[^\(\)]))*?)\s*((['"])(.*)\12)?\)''' # [text](url) or [text](<url>)
532
527
@@ -536,7 +531,7 @@ def run (self, lines):
536
531
NOT_STRONG_RE = r'( \* )' # stand-alone * or _
537
532
AUTOLINK_RE = r'<((?:f|ht)tps?://[^>]*)>' # <http://www.123.com>
538
533
AUTOMAIL_RE = r'<([^> \!]*@[^> ]*)>' # <[email protected] >
539
- #HTML_RE = r'(\<[^\>]*\>)' # <...>
534
+
540
535
HTML_RE = r'(\<([a-zA-Z/][^\>]*?|\!--.*?--)\>)' # <...>
541
536
ENTITY_RE = r'(&[\#a-zA-Z0-9]*;)' # &
542
537
LINE_BREAK_RE = r' \n' # two spaces at end of line
@@ -844,11 +839,11 @@ class Postprocessor:
844
839
845
840
"""
846
841
847
- def run (self , et ):
842
+ def run (self , root ):
848
843
"""
849
844
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.
852
847
"""
853
848
pass
854
849
@@ -956,6 +951,10 @@ def store(self, html, safe=False):
956
951
placeholder = HTML_PLACEHOLDER % self .html_counter
957
952
self .html_counter += 1
958
953
return placeholder
954
+
955
+ def rest (self ):
956
+ self .html_counter = 0
957
+ self .rawHtmlBlocks = []
959
958
960
959
961
960
class BlockGuru :
@@ -1090,6 +1089,9 @@ def add(self, node, type):
1090
1089
self ._nodes [id ] = node
1091
1090
return pholder
1092
1091
1092
+ def rest (self ):
1093
+ self ._nodes = {}
1094
+
1093
1095
"""
1094
1096
======================================================================
1095
1097
========================== CORE MARKDOWN =============================
@@ -1207,8 +1209,9 @@ def __init__(self, source=None, # depreciated
1207
1209
]
1208
1210
1209
1211
self .inlineStash = InlineStash ()
1210
-
1211
- self ._inlineOperationID = None
1212
+ self .references = {}
1213
+ self .htmlStash = HtmlStash ()
1214
+
1212
1215
1213
1216
self .registerExtensions (extensions = extensions ,
1214
1217
configs = extension_configs )
@@ -1249,9 +1252,9 @@ def reset(self):
1249
1252
"""
1250
1253
Resets all state variables so that we can start with a new text.
1251
1254
"""
1252
- self .references = {}
1253
- self .htmlStash = HtmlStash ()
1254
- self .inlineStash = InlineStash ()
1255
+ self .inlineStash . rest ()
1256
+ self .htmlStash . rest ()
1257
+ self .references . clear ()
1255
1258
1256
1259
HTML_BLOCK_PREPROCESSOR .stash = self .htmlStash
1257
1260
LINE_PREPROCESSOR .stash = self .htmlStash
0 commit comments