diff options
author | Toshio Kuratomi <toshio@fedoraproject.org> | 2010-07-05 22:40:01 -0400 |
---|---|---|
committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2010-07-05 22:40:01 -0400 |
commit | a91f766c57d67cebbfc35020f89016ceb4358926 (patch) | |
tree | 03502b7e8ebd6b473b49307fd4319427e5d13c74 | |
parent | ac77988cc6434cf14e1c07e6955ca00a13e50ed0 (diff) | |
download | markdown-a91f766c57d67cebbfc35020f89016ceb4358926.tar.gz markdown-a91f766c57d67cebbfc35020f89016ceb4358926.tar.bz2 markdown-a91f766c57d67cebbfc35020f89016ceb4358926.zip |
Actually commit the files with the code moved out of __init__.py
-rw-r--r-- | markdown/misc.py | 73 | ||||
-rw-r--r-- | markdown/misc_logging.py | 36 |
2 files changed, 109 insertions, 0 deletions
diff --git a/markdown/misc.py b/markdown/misc.py new file mode 100644 index 0000000..f9c7894 --- /dev/null +++ b/markdown/misc.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +import re +from misc_logging import CRITICAL + +import etree_loader + + +""" +CONSTANTS +============================================================================= +""" + +""" +Constants you might want to modify +----------------------------------------------------------------------------- +""" + +# default logging level for command-line use +COMMAND_LINE_LOGGING_LEVEL = CRITICAL +TAB_LENGTH = 4 # expand tabs to this many spaces +ENABLE_ATTRIBUTES = True # @id = xyz -> <... id="xyz"> +SMART_EMPHASIS = True # this_or_that does not become this<i>or</i>that +DEFAULT_OUTPUT_FORMAT = 'xhtml1' # xhtml or html4 output +HTML_REMOVED_TEXT = "[HTML_REMOVED]" # text used instead of HTML in safe mode +BLOCK_LEVEL_ELEMENTS = re.compile("p|div|h[1-6]|blockquote|pre|table|dl|ol|ul" + "|script|noscript|form|fieldset|iframe|math" + "|ins|del|hr|hr/|style|li|dt|dd|thead|tbody" + "|tr|th|td") +DOC_TAG = "div" # Element used to wrap document - later removed + +# 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 +INLINE_PLACEHOLDER_PREFIX = STX+"klzzwxh:" +INLINE_PLACEHOLDER = INLINE_PLACEHOLDER_PREFIX + "%s" + ETX +AMP_SUBSTITUTE = STX+"amp"+ETX + + +""" +Constants you probably do not need to change +----------------------------------------------------------------------------- +""" + +RTL_BIDI_RANGES = ( (u'\u0590', u'\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 + ) + +# Extensions should use "markdown.misc.etree" instead of "etree" (or do `from +# markdown.misc import etree`). Do not import it by yourself. + +etree = etree_loader.importETree() + +""" +AUXILIARY GLOBAL FUNCTIONS +============================================================================= +""" + + +def isBlockLevel(tag): + """Check if the tag is a block level HTML tag.""" + return BLOCK_LEVEL_ELEMENTS.match(tag) + +""" +MISC AUXILIARY CLASSES +============================================================================= +""" + +class AtomicString(unicode): + """A string which should not be further processed.""" + pass diff --git a/markdown/misc_logging.py b/markdown/misc_logging.py new file mode 100644 index 0000000..463be15 --- /dev/null +++ b/markdown/misc_logging.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +import logging +from logging import DEBUG, INFO, WARN, ERROR, CRITICAL +import sys +import warnings + +# +# Exceptions +# + +class MarkdownException(Exception): + """ A Markdown Exception. """ + pass + + +class MarkdownWarning(Warning): + """ A Markdown Warning. """ + pass + + +# +# Global functions +# + +def message(level, text): + """ A wrapper method for logging debug messages. """ + logger = logging.getLogger('MARKDOWN') + if logger.handlers: + # The logger is configured + logger.log(level, text) + if level > WARN: + sys.exit(0) + elif level > WARN: + raise MarkdownException, text + else: + warnings.warn(text, MarkdownWarning)
\ No newline at end of file |