30
30
License: BSD (see LICENSE for details).
31
31
"""
32
32
33
- version = "2.1.1 "
34
- version_info = (2 ,1 , 1 , "final " )
33
+ version = "2.2.0 "
34
+ version_info = (2 ,2 , 0 , "alpha " )
35
35
36
36
import re
37
37
import codecs
@@ -55,15 +55,15 @@ class Markdown:
55
55
"""Convert Markdown to HTML."""
56
56
57
57
doc_tag = "div" # Element used to wrap document - later removed
58
-
58
+
59
59
option_defaults = {
60
60
'html_replacement_text' : '[HTML_REMOVED]' ,
61
61
'tab_length' : 4 ,
62
62
'enable_attributes' : True ,
63
63
'smart_emphasis' : True ,
64
64
'lazy_ol' : True ,
65
65
}
66
-
66
+
67
67
output_formats = {
68
68
'html' : to_html_string ,
69
69
'html4' : to_html_string ,
@@ -73,9 +73,9 @@ class Markdown:
73
73
'xhtml5' : to_xhtml_string ,
74
74
}
75
75
76
- ESCAPED_CHARS = ['\\ ' , '`' , '*' , '_' , '{' , '}' , '[' , ']' ,
76
+ ESCAPED_CHARS = ['\\ ' , '`' , '*' , '_' , '{' , '}' , '[' , ']' ,
77
77
'(' , ')' , '>' , '#' , '+' , '-' , '.' , '!' ]
78
-
78
+
79
79
def __init__ (self , * args , ** kwargs ):
80
80
"""
81
81
Creates a new Markdown instance.
@@ -119,7 +119,7 @@ def __init__(self, *args, **kwargs):
119
119
120
120
# Loop through kwargs and assign defaults
121
121
for option , default in self .option_defaults .items ():
122
- setattr (self , option , kwargs .get (option , default ))
122
+ setattr (self , option , kwargs .get (option , default ))
123
123
124
124
self .safeMode = kwargs .get ('safe_mode' , False )
125
125
if self .safeMode and not kwargs .has_key ('enable_attributes' ):
@@ -142,7 +142,7 @@ def __init__(self, *args, **kwargs):
142
142
def build_parser (self ):
143
143
""" Build the parser from the various parts. """
144
144
self .preprocessors = build_preprocessors (self )
145
- self .parser = build_block_parser (self )
145
+ self .parser = build_block_parser (self )
146
146
self .inlinePatterns = build_inlinepatterns (self )
147
147
self .treeprocessors = build_treeprocessors (self )
148
148
self .postprocessors = build_postprocessors (self )
@@ -213,7 +213,7 @@ def build_extension(self, ext_name, configs = []):
213
213
except AttributeError , e :
214
214
logger .warn ("Failed to initiate extension '%s': %s" % (ext_name , e ))
215
215
return None
216
-
216
+
217
217
def registerExtension (self , extension ):
218
218
""" This gets called by the extension """
219
219
self .registeredExtensions .append (extension )
@@ -254,10 +254,10 @@ def convert(self, source):
254
254
1. A bunch of "preprocessors" munge the input text.
255
255
2. BlockParser() parses the high-level structural elements of the
256
256
pre-processed text into an ElementTree.
257
- 3. A bunch of "treeprocessors" are run against the ElementTree. One
258
- such treeprocessor runs InlinePatterns against the ElementTree,
257
+ 3. A bunch of "treeprocessors" are run against the ElementTree. One
258
+ such treeprocessor runs InlinePatterns against the ElementTree,
259
259
detecting inline markup.
260
- 4. Some post-processors are run against the text after the ElementTree
260
+ 4. Some post-processors are run against the text after the ElementTree
261
261
has been serialized into text.
262
262
5. The output is written to a string.
263
263
@@ -266,7 +266,7 @@ def convert(self, source):
266
266
# Fixup the source text
267
267
if not source .strip ():
268
268
return u"" # a blank unicode string
269
-
269
+
270
270
try :
271
271
source = unicode (source )
272
272
except UnicodeDecodeError , e :
@@ -358,8 +358,8 @@ def convertFile(self, input=None, output=None, encoding=None):
358
358
# Write to file or stdout
359
359
if output :
360
360
if isinstance (output , str ):
361
- output_file = codecs .open (output , "w" ,
362
- encoding = encoding ,
361
+ output_file = codecs .open (output , "w" ,
362
+ encoding = encoding ,
363
363
errors = "xmlcharrefreplace" )
364
364
output_file .write (html )
365
365
output_file .close ()
@@ -403,17 +403,17 @@ def markdown(text, *args, **kwargs):
403
403
404
404
def markdownFromFile (* args , ** kwargs ):
405
405
"""Read markdown code from a file and write it to a file or a stream.
406
-
406
+
407
407
This is a shortcut function which initializes an instance of Markdown,
408
408
and calls the convertFile method rather than convert.
409
-
409
+
410
410
Keyword arguments:
411
-
411
+
412
412
* input: a file name or readable object.
413
413
* output: a file name or writable object.
414
414
* encoding: Encoding of input and output.
415
415
* Any arguments accepted by the Markdown class.
416
-
416
+
417
417
"""
418
418
# For backward compatibility loop through positional args
419
419
pos = ['input' , 'output' , 'extensions' , 'encoding' ]
@@ -426,7 +426,7 @@ def markdownFromFile(*args, **kwargs):
426
426
break
427
427
428
428
md = Markdown (** kwargs )
429
- md .convertFile (kwargs .get ('input' , None ),
429
+ md .convertFile (kwargs .get ('input' , None ),
430
430
kwargs .get ('output' , None ),
431
431
kwargs .get ('encoding' , None ))
432
432
0 commit comments