aboutsummaryrefslogtreecommitdiffstats
path: root/markdown/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'markdown/util.py')
-rw-r--r--markdown/util.py31
1 files changed, 22 insertions, 9 deletions
diff --git a/markdown/util.py b/markdown/util.py
index 34333f0..1036197 100644
--- a/markdown/util.py
+++ b/markdown/util.py
@@ -1,11 +1,24 @@
# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
import re
+import sys
"""
-CONSTANTS
+Python 3 Stuff
=============================================================================
"""
+PY3 = sys.version_info[0] == 3
+
+if PY3:
+ string_type = str
+ text_type = str
+ int2str = chr
+else:
+ string_type = basestring
+ text_type = unicode
+ int2str = unichr
+
"""
Constants you might want to modify
@@ -19,8 +32,8 @@ BLOCK_LEVEL_ELEMENTS = re.compile("^(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul"
"|figcaption|aside|article|canvas|output"
"|progress|video)$", re.IGNORECASE)
# Placeholders
-STX = u'\u0002' # Use STX ("Start of text") for start-of-placeholder
-ETX = u'\u0003' # Use ETX ("End of text") for end-of-placeholder
+STX = '\u0002' # Use STX ("Start of text") for start-of-placeholder
+ETX = '\u0003' # Use ETX ("End of text") for end-of-placeholder
INLINE_PLACEHOLDER_PREFIX = STX+"klzzwxh:"
INLINE_PLACEHOLDER = INLINE_PLACEHOLDER_PREFIX + "%s" + ETX
INLINE_PLACEHOLDER_RE = re.compile(INLINE_PLACEHOLDER % r'([0-9]{4})')
@@ -31,11 +44,11 @@ Constants you probably do not need to change
-----------------------------------------------------------------------------
"""
-RTL_BIDI_RANGES = ( (u'\u0590', u'\u07FF'),
+RTL_BIDI_RANGES = ( ('\u0590', '\u07FF'),
# Hebrew (0590-05FF), Arabic (0600-06FF),
# Syriac (0700-074F), Arabic supplement (0750-077F),
# Thaana (0780-07BF), Nko (07C0-07FF).
- (u'\u2D30', u'\u2D7F'), # Tifinagh
+ ('\u2D30', '\u2D7F'), # Tifinagh
)
# Extensions should use "markdown.util.etree" instead of "etree" (or do `from
@@ -63,7 +76,7 @@ AUXILIARY GLOBAL FUNCTIONS
def isBlockLevel(tag):
"""Check if the tag is a block level HTML tag."""
- if isinstance(tag, basestring):
+ if isinstance(tag, string_type):
return BLOCK_LEVEL_ELEMENTS.match(tag)
# Some ElementTree tags are not strings, so return False.
return False
@@ -73,18 +86,18 @@ MISC AUXILIARY CLASSES
=============================================================================
"""
-class AtomicString(unicode):
+class AtomicString(text_type):
"""A string which should not be further processed."""
pass
-class Processor:
+class Processor(object):
def __init__(self, markdown_instance=None):
if markdown_instance:
self.markdown = markdown_instance
-class HtmlStash:
+class HtmlStash(object):
"""
This class is used for stashing HTML objects that we extract
in the beginning and replace with place-holders.