74
74
DOC_TAG = "div" # Element used to wrap document - later removed
75
75
76
76
# Placeholders
77
- STX = u '\u0002 ' # Use STX ("Start of text") for start-of-placeholder
78
- ETX = u '\u0003 ' # Use ETX ("End of text") for end-of-placeholder
77
+ STX = '\u0002 ' # Use STX ("Start of text") for start-of-placeholder
78
+ ETX = '\u0003 ' # Use ETX ("End of text") for end-of-placeholder
79
79
INLINE_PLACEHOLDER_PREFIX = STX + "klzzwxh:"
80
80
INLINE_PLACEHOLDER = INLINE_PLACEHOLDER_PREFIX + "%s" + ETX
81
81
AMP_SUBSTITUTE = STX + "amp" + ETX
86
86
-----------------------------------------------------------------------------
87
87
"""
88
88
89
- RTL_BIDI_RANGES = ( (u '\u0590 ' , u '\u07FF ' ),
89
+ RTL_BIDI_RANGES = ( ('\u0590 ' , '\u07FF ' ),
90
90
# Hebrew (0590-05FF), Arabic (0600-06FF),
91
91
# Syriac (0700-074F), Arabic supplement (0750-077F),
92
92
# Thaana (0780-07BF), Nko (07C0-07FF).
93
- (u '\u2D30 ' , u '\u2D7F ' ), # Tifinagh
93
+ ('\u2D30 ' , '\u2D7F ' ), # Tifinagh
94
94
)
95
95
96
96
@@ -109,7 +109,7 @@ def message(level, text):
109
109
if level > WARN :
110
110
sys .exit (0 )
111
111
elif level > WARN :
112
- raise MarkdownException , text
112
+ raise MarkdownException ( text )
113
113
else :
114
114
warnings .warn (text , MarkdownWarning )
115
115
@@ -123,7 +123,7 @@ def isBlockLevel(tag):
123
123
=============================================================================
124
124
"""
125
125
126
- class AtomicString (unicode ):
126
+ class AtomicString (str ):
127
127
"""A string which should not be further processed."""
128
128
pass
129
129
@@ -158,22 +158,22 @@ class MarkdownWarning(Warning):
158
158
159
159
"""
160
160
161
- import preprocessors
162
- import blockprocessors
163
- import treeprocessors
164
- import inlinepatterns
165
- import postprocessors
166
- import blockparser
167
- import etree_loader
168
- import odict
161
+ from . import preprocessors
162
+ from . import blockprocessors
163
+ from . import treeprocessors
164
+ from . import inlinepatterns
165
+ from . import postprocessors
166
+ from . import blockparser
167
+ from . import etree_loader
168
+ from . import odict
169
169
170
170
# Extensions should use "markdown.etree" instead of "etree" (or do `from
171
171
# markdown import etree`). Do not import it by yourself.
172
172
173
173
etree = etree_loader .importETree ()
174
174
175
175
# Adds the ability to output html4
176
- import html4
176
+ from . import html4
177
177
178
178
179
179
class Markdown :
@@ -325,12 +325,12 @@ def registerExtensions(self, extensions, configs):
325
325
326
326
"""
327
327
for ext in extensions :
328
- if isinstance (ext , basestring ):
328
+ if isinstance (ext , str ):
329
329
ext = load_extension (ext , configs .get (ext , []))
330
330
if isinstance (ext , Extension ):
331
331
try :
332
332
ext .extendMarkdown (self , globals ())
333
- except NotImplementedError , e :
333
+ except NotImplementedError as e :
334
334
message (ERROR , e )
335
335
else :
336
336
message (ERROR , 'Extension "%s.%s" must be of type: "markdown.Extension".' \
@@ -356,7 +356,7 @@ def set_output_format(self, format):
356
356
self .serializer = self .output_formats [format .lower ()]
357
357
except KeyError :
358
358
message (CRITICAL , 'Invalid Output Format: "%s". Use one of %s.' \
359
- % (format , self .output_formats .keys ()))
359
+ % (format , list ( self .output_formats .keys () )))
360
360
361
361
def convert (self , source ):
362
362
"""
@@ -370,12 +370,12 @@ def convert(self, source):
370
370
371
371
# Fixup the source text
372
372
if not source .strip ():
373
- return u "" # a blank unicode string
373
+ return "" # a blank unicode string
374
374
try :
375
- source = unicode (source )
375
+ source = str (source )
376
376
except UnicodeDecodeError :
377
377
message (CRITICAL , 'UnicodeDecodeError: Markdown only accepts unicode or ascii input.' )
378
- return u ""
378
+ return ""
379
379
380
380
source = source .replace (STX , "" ).replace (ETX , "" )
381
381
source = source .replace ("\r \n " , "\n " ).replace ("\r " , "\n " ) + "\n \n "
@@ -384,14 +384,14 @@ def convert(self, source):
384
384
385
385
# Split into lines and run the line preprocessors.
386
386
self .lines = source .split ("\n " )
387
- for prep in self .preprocessors .values ():
387
+ for prep in list ( self .preprocessors .values () ):
388
388
self .lines = prep .run (self .lines )
389
389
390
390
# Parse the high-level elements.
391
391
root = self .parser .parseDocument (self .lines ).getroot ()
392
392
393
393
# Run the tree-processors
394
- for treeprocessor in self .treeprocessors .values ():
394
+ for treeprocessor in list ( self .treeprocessors .values () ):
395
395
newRoot = treeprocessor .run (root )
396
396
if newRoot :
397
397
root = newRoot
@@ -412,7 +412,7 @@ def convert(self, source):
412
412
message (CRITICAL , 'Failed to strip top level tags.' )
413
413
414
414
# Run the text post-processors
415
- for pp in self .postprocessors .values ():
415
+ for pp in list ( self .postprocessors .values () ):
416
416
output = pp .run (output )
417
417
418
418
return output .strip ()
@@ -443,13 +443,13 @@ def convertFile(self, input=None, output=None, encoding=None):
443
443
input_file = codecs .open (input , mode = "r" , encoding = encoding )
444
444
text = input_file .read ()
445
445
input_file .close ()
446
- text = text .lstrip (u '\ufeff ' ) # remove the byte-order mark
446
+ text = text .lstrip ('\ufeff ' ) # remove the byte-order mark
447
447
448
448
# Convert
449
449
html = self .convert (text )
450
450
451
451
# Write to file or stdout
452
- if isinstance (output , ( str , unicode ) ):
452
+ if isinstance (output , str ):
453
453
output_file = codecs .open (output , "w" , encoding = encoding )
454
454
output_file .write (html )
455
455
output_file .close ()
@@ -482,7 +482,7 @@ def getConfig(self, key):
482
482
483
483
def getConfigInfo (self ):
484
484
""" Return all config settings as a list of tuples. """
485
- return [(key , self .config [key ][1 ]) for key in self .config .keys ()]
485
+ return [(key , self .config [key ][1 ]) for key in list ( self .config .keys () )]
486
486
487
487
def setConfig (self , key , value ):
488
488
""" Set a config setting for `key` with the given `value`. """
@@ -501,8 +501,8 @@ def extendMarkdown(self, md, md_globals):
501
501
* md_globals: Global variables in the markdown module namespace.
502
502
503
503
"""
504
- raise NotImplementedError , 'Extension "%s.%s" must define an "extendMarkdown"' \
505
- 'method.' % (self .__class__ .__module__ , self .__class__ .__name__ )
504
+ raise NotImplementedError ( 'Extension "%s.%s" must define an "extendMarkdown"' \
505
+ 'method.' % (self .__class__ .__module__ , self .__class__ .__name__ ))
506
506
507
507
508
508
def load_extension (ext_name , configs = []):
@@ -542,7 +542,7 @@ def load_extension(ext_name, configs = []):
542
542
# If the module is loaded successfully, we expect it to define a
543
543
# function called makeExtension()
544
544
try :
545
- return module .makeExtension (configs .items ())
545
+ return module .makeExtension (list ( configs .items () ))
546
546
except AttributeError :
547
547
message (CRITICAL , "Failed to initiate extension '%s'" % ext_name )
548
548
0 commit comments