Some text with an ABBR and a REF. Ignore REFERENCE and ref.
+Oringinal code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/) and + [Seemant Kulleen](http://www.kulleen.org/) -Copyright 2007-2008 -* [Waylan Limberg](http://achinghead.com/) -* [Seemant Kulleen](http://www.kulleen.org/) - +All changes Copyright 2008-2014 The Python Markdown Project + +License: [BSD](http://www.opensource.org/licenses/bsd-license.php) ''' @@ -92,5 +85,5 @@ class AbbrPattern(Pattern): abbr.set('title', self.title) return abbr -def makeExtension(configs=None): - return AbbrExtension(configs=configs) +def makeExtension(*args, **kwargs): + return AbbrExtension(*args, **kwargs) diff --git a/awx/lib/site-packages/markdown/extensions/admonition.py b/awx/lib/site-packages/markdown/extensions/admonition.py index 9a45b9249c..189f2c2dd9 100644 --- a/awx/lib/site-packages/markdown/extensions/admonition.py +++ b/awx/lib/site-packages/markdown/extensions/admonition.py @@ -4,39 +4,16 @@ Admonition extension for Python-Markdown Adds rST-style admonitions. Inspired by [rST][] feature with the same name. -The syntax is (followed by an indented block with the contents): - !!! [type] [optional explicit title] - -Where `type` is used as a CSS class name of the div. If not present, `title` -defaults to the capitalized `type`, so "note" -> "Note". - -rST suggests the following `types`, but you're free to use whatever you want: - attention, caution, danger, error, hint, important, note, tip, warning - - -A simple example: - !!! note - This is the first line inside the box. - -Outputs: -Note
-This is the first line inside the box
-Did you know?
-Another line here.
-A paragraph before a fenced code block:
-Fenced code block
-
+See A paragraph before a fenced code block:
-Fenced code block
-
-Include tilde's in a code block and wrap with blank lines:
-
- >>> text = '''
- ... ~~~~~~~~
- ...
- ... ~~~~
- ... ~~~~~~~~'''
- >>> print markdown.markdown(text, extensions=['fenced_code'])
-
- ~~~~
-
-
-Language tags:
-
- >>> text = '''
- ... ~~~~{.python}
- ... # Some python code
- ... ~~~~'''
- >>> print markdown.markdown(text, extensions=['fenced_code'])
- # Some python code
-
-
-Optionally backticks instead of tildes as per how github's code block markdown is identified:
-
- >>> text = '''
- ... `````
- ... # Arbitrary code
- ... ~~~~~ # these tildes will not close the block
- ... `````'''
- >>> print markdown.markdown(text, extensions=['fenced_code'])
- # Arbitrary code
- ~~~~~ # these tildes will not close the block
-
-
-If the codehighlite extension and Pygments are installed, lines can be highlighted:
-
- >>> text = '''
- ... ```hl_lines="1 3"
- ... line 1
- ... line 2
- ... line 3
- ... ```'''
- >>> print markdown.markdown(text, extensions=['codehilite', 'fenced_code'])
- line 1
- line 2
- line 3
-
-
-Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).
-
-Project website: The body. This is paragraph one.
- >>> print md.Meta - {u'blank_data': [u''], u'author': [u'Waylan Limberg', u'John Doe'], u'title': [u'A Test Doc.']} +Original code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com). -Make sure text without Meta Data still works (markdown < 1.6b returns a). +All changes Copyright 2008-2014 The Python Markdown Project - >>> text = ' Some Code - not extra lines of meta data.' - >>> md = markdown.Markdown(['meta']) - >>> print md.convert(text) -
Some Code - not extra lines of meta data.
-
- >>> md.Meta
- {}
-
-Copyright 2007-2008 [Waylan Limberg](http://achinghead.com).
-
-Project website: line 1
- line 2
Text with double__underscore__words.
- >>> print markdown.markdown('__Strong__ still works.', - ... extensions=['smart_strong']) -Strong still works.
- >>> print markdown.markdown('__this__works__too__.', - ... extensions=['smart_strong']) -this__works__too.
+Original code Copyright 2011 [Waylan Limberg](http://achinghead.com) -Copyright 2011 -[Waylan Limberg](http://achinghead.com) +All changes Copyright 2011-2014 The Python Markdown Project + +License: [BSD](http://www.opensource.org/licenses/bsd-license.php) ''' @@ -38,5 +31,5 @@ class SmartEmphasisExtension(Extension): md.inlinePatterns['strong'] = SimpleTagPattern(STRONG_RE, 'strong') md.inlinePatterns.add('strong2', SimpleTagPattern(SMART_STRONG_RE, 'strong'), '>emphasis2') -def makeExtension(configs={}): - return SmartEmphasisExtension(configs=dict(configs)) +def makeExtension(*args, **kwargs): + return SmartEmphasisExtension(*args, **kwargs) diff --git a/awx/lib/site-packages/markdown/extensions/smarty.py b/awx/lib/site-packages/markdown/extensions/smarty.py index 2f946f8294..00c330f1f0 100644 --- a/awx/lib/site-packages/markdown/extensions/smarty.py +++ b/awx/lib/site-packages/markdown/extensions/smarty.py @@ -1,73 +1,91 @@ # -*- coding: utf-8 -*- -# Smarty extension for Python-Markdown -# Author: 2013, Dmitry ShachnevHe said, "'Quoted' words in a larger quote."
@@ -113,8 +144,6 @@ closingSingleQuotesRegex2 = r"(?<=%s)'(\s|s\b)" % closeClass remainingSingleQuotesRegex = "'" remainingDoubleQuotesRegex = '"' -lsquo, rsquo, ldquo, rdquo = '‘', '’', '“', '”' - class SubstituteTextPattern(HtmlPattern): def __init__(self, pattern, replace, markdown_instance): """ Replaces matches with some text. """ @@ -132,35 +161,56 @@ class SubstituteTextPattern(HtmlPattern): return result class SmartyExtension(Extension): - def __init__(self, configs): + def __init__(self, *args, **kwargs): self.config = { 'smart_quotes': [True, 'Educate quotes'], + 'smart_angled_quotes': [False, 'Educate angled quotes'], 'smart_dashes': [True, 'Educate dashes'], - 'smart_ellipses': [True, 'Educate ellipses'] + 'smart_ellipses': [True, 'Educate ellipses'], + 'substitutions' : [{}, 'Overwrite default substitutions'], } - for key, value in configs: - self.setConfig(key, parseBoolValue(value)) + super(SmartyExtension, self).__init__(*args, **kwargs) + self.substitutions = dict(substitutions) + self.substitutions.update(self.getConfig('substitutions', default={})) def _addPatterns(self, md, patterns, serie): for ind, pattern in enumerate(patterns): pattern += (md,) pattern = SubstituteTextPattern(*pattern) - after = ('>smarty-%s-%d' % (serie, ind - 1) if ind else '>entity') + after = ('>smarty-%s-%d' % (serie, ind - 1) if ind else '_begin') name = 'smarty-%s-%d' % (serie, ind) - md.inlinePatterns.add(name, pattern, after) + self.inlinePatterns.add(name, pattern, after) def educateDashes(self, md): - emDashesPattern = SubstituteTextPattern(r'(?entity') - md.inlinePatterns.add('smarty-en-dashes', enDashesPattern, + emDashesPattern = SubstituteTextPattern(r'(?smarty-em-dashes') def educateEllipses(self, md): - ellipsesPattern = SubstituteTextPattern(r'(?entity') + ellipsesPattern = SubstituteTextPattern(r'(?\>', + (self.substitutions['right-angle-quote'],), md) + self.inlinePatterns.add('smarty-left-angle-quotes', + leftAngledQuotePattern, '_begin') + self.inlinePatterns.add('smarty-right-angle-quotes', + rightAngledQuotePattern, '>smarty-left-angle-quotes') def educateQuotes(self, md): + configs = self.getConfigs() + lsquo = self.substitutions['left-single-quote'] + rsquo = self.substitutions['right-single-quote'] + ldquo = self.substitutions['left-double-quote'] + rdquo = self.substitutions['right-double-quote'] patterns = ( (singleQuoteStartRe, (rsquo,)), (doubleQuoteStartRe, (rdquo,)), @@ -179,13 +229,19 @@ class SmartyExtension(Extension): def extendMarkdown(self, md, md_globals): configs = self.getConfigs() - if configs['smart_quotes']: - self.educateQuotes(md) - if configs['smart_dashes']: - self.educateDashes(md) + self.inlinePatterns = OrderedDict() if configs['smart_ellipses']: self.educateEllipses(md) + if configs['smart_quotes']: + self.educateQuotes(md) + if configs['smart_angled_quotes']: + self.educateAngledQuotes(md) + if configs['smart_dashes']: + self.educateDashes(md) + inlineProcessor = InlineProcessor(md) + inlineProcessor.inlinePatterns = self.inlinePatterns + md.treeprocessors.add('smarty', inlineProcessor, '_end') md.ESCAPED_CHARS.extend(['"', "'"]) -def makeExtension(configs=None): - return SmartyExtension(configs) +def makeExtension(*args, **kwargs): + return SmartyExtension(*args, **kwargs) diff --git a/awx/lib/site-packages/markdown/extensions/tables.py b/awx/lib/site-packages/markdown/extensions/tables.py index ad52ec11c7..57507e96d8 100644 --- a/awx/lib/site-packages/markdown/extensions/tables.py +++ b/awx/lib/site-packages/markdown/extensions/tables.py @@ -4,14 +4,15 @@ Tables Extension for Python-Markdown Added parsing of tables to Python-Markdown. -A simple example: +SeeSome text with a WikiLink.
+Original code Copyright [Waylan Limberg](http://achinghead.com/). -Whitespace behavior: - - >>> print markdown.markdown('[[ foo bar_baz ]]', ['wikilinks']) - - >>> print markdown.markdown('foo [[ ]] bar', ['wikilinks']) -foo bar
- -To define custom settings the simple way: - - >>> print markdown.markdown(text, - ... ['wikilinks(base_url=/wiki/,end_url=.html,html_class=foo)'] - ... ) -Some text with a WikiLink.
- -Custom settings the complex way: - - >>> md = markdown.Markdown( - ... extensions = ['wikilinks'], - ... extension_configs = {'wikilinks': [ - ... ('base_url', 'http://example.com/'), - ... ('end_url', '.html'), - ... ('html_class', '') ]}, - ... safe_mode = True) - >>> print md.convert(text) -Some text with a WikiLink.
- -Use MetaData with mdx_meta.py (Note the blank html_class in MetaData): - - >>> text = """wiki_base_url: http://example.com/ - ... wiki_end_url: .html - ... wiki_html_class: - ... - ... Some text with a [[WikiLink]].""" - >>> md = markdown.Markdown(extensions=['meta', 'wikilinks']) - >>> print md.convert(text) -Some text with a WikiLink.
- -MetaData should not carry over to next document: - - >>> print md.convert("No [[MetaData]] here.") -No MetaData here.
- -Define a custom URL builder: - - >>> def my_url_builder(label, base, end): - ... return '/bar/' - >>> md = markdown.Markdown(extensions=['wikilinks'], - ... extension_configs={'wikilinks' : [('build_url', my_url_builder)]}) - >>> print md.convert('[[foo]]') - - -From the command line: - - python markdown.py -x wikilinks(base_url=http://example.com/,end_url=.html,html_class=foo) src.txt - -By [Waylan Limberg](http://achinghead.com/). +All changes Copyright The Python Markdown Project License: [BSD](http://www.opensource.org/licenses/bsd-license.php) -Dependencies: -* [Python 2.3+](http://python.org) -* [Markdown 2.0+](http://packages.python.org/Markdown/) ''' from __future__ import absolute_import @@ -90,19 +29,17 @@ def build_url(label, base, end): class WikiLinkExtension(Extension): - def __init__(self, configs): - # set extension defaults + + def __init__ (self, *args, **kwargs): self.config = { - 'base_url' : ['/', 'String to append to beginning or URL.'], - 'end_url' : ['/', 'String to append to end of URL.'], - 'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'], - 'build_url' : [build_url, 'Callable formats URL from label.'], + 'base_url' : ['/', 'String to append to beginning or URL.'], + 'end_url' : ['/', 'String to append to end of URL.'], + 'html_class' : ['wikilink', 'CSS hook. Leave blank for none.'], + 'build_url' : [build_url, 'Callable formats URL from label.'], } - configs = dict(configs) or {} - # Override defaults with user settings - for key, value in configs.items(): - self.setConfig(key, value) + super(WikiLinkExtension, self).__init__(*args, **kwargs) + def extendMarkdown(self, md, md_globals): self.md = md @@ -147,5 +84,5 @@ class WikiLinks(Pattern): return base_url, end_url, html_class -def makeExtension(configs=None) : - return WikiLinkExtension(configs=configs) +def makeExtension(*args, **kwargs) : + return WikiLinkExtension(*args, **kwargs) diff --git a/awx/lib/site-packages/markdown/inlinepatterns.py b/awx/lib/site-packages/markdown/inlinepatterns.py index 9335748730..c9d82fdc75 100644 --- a/awx/lib/site-packages/markdown/inlinepatterns.py +++ b/awx/lib/site-packages/markdown/inlinepatterns.py @@ -46,13 +46,13 @@ from __future__ import unicode_literals from . import util from . import odict import re -try: +try: #pragma: no cover from urllib.parse import urlparse, urlunparse -except ImportError: +except ImportError: #pragma: no cover from urlparse import urlparse, urlunparse -try: +try: #pragma: no cover from html import entities -except ImportError: +except ImportError: #pragma: no cover import htmlentitydefs as entities @@ -75,7 +75,8 @@ def build_inlinepatterns(md_instance, **kwargs): inlinePatterns["html"] = HtmlPattern(HTML_RE, md_instance) inlinePatterns["entity"] = HtmlPattern(ENTITY_RE, md_instance) inlinePatterns["not_strong"] = SimpleTextPattern(NOT_STRONG_RE) - inlinePatterns["strong_em"] = DoubleTagPattern(STRONG_EM_RE, 'strong,em') + inlinePatterns["em_strong"] = DoubleTagPattern(EM_STRONG_RE, 'strong,em') + inlinePatterns["strong_em"] = DoubleTagPattern(STRONG_EM_RE, 'em,strong') inlinePatterns["strong"] = SimpleTagPattern(STRONG_RE, 'strong') inlinePatterns["emphasis"] = SimpleTagPattern(EMPHASIS_RE, 'em') if md_instance.smart_emphasis: @@ -100,7 +101,8 @@ BACKTICK_RE = r'(?" in text: text = text.replace(">", ">") return text - except (TypeError, AttributeError): + except (TypeError, AttributeError): #pragma: no cover _raise_serialization_error(text) @@ -115,7 +115,7 @@ def _escape_attrib(text): if "\n" in text: text = text.replace("\n", " ") return text - except (TypeError, AttributeError): + except (TypeError, AttributeError): #pragma: no cover _raise_serialization_error(text) def _escape_attrib_html(text): @@ -130,7 +130,7 @@ def _escape_attrib_html(text): if "\"" in text: text = text.replace("\"", """) return text - except (TypeError, AttributeError): + except (TypeError, AttributeError): #pragma: no cover _raise_serialization_error(text) @@ -240,7 +240,7 @@ def _namespaces(elem, default_namespace=None): "default_namespace option" ) qnames[qname] = qname - except TypeError: + except TypeError: #pragma: no cover _raise_serialization_error(qname) # populate qname and namespaces table diff --git a/awx/lib/site-packages/markdown/treeprocessors.py b/awx/lib/site-packages/markdown/treeprocessors.py index ef0a2aa00c..303e4600cd 100644 --- a/awx/lib/site-packages/markdown/treeprocessors.py +++ b/awx/lib/site-packages/markdown/treeprocessors.py @@ -34,11 +34,11 @@ class Treeprocessor(util.Processor): def run(self, root): """ Subclasses of Treeprocessor should implement a `run` method, which - takes a root ElementTree. This method can return another ElementTree - object, and the existing root ElementTree will be replaced, or it can + takes a root ElementTree. This method can return another ElementTree + object, and the existing root ElementTree will be replaced, or it can modify the current tree and return None. """ - pass + pass #pragma: no cover class InlineProcessor(Treeprocessor): @@ -53,6 +53,7 @@ class InlineProcessor(Treeprocessor): + len(self.__placeholder_suffix) self.__placeholder_re = util.INLINE_PLACEHOLDER_RE self.markdown = md + self.inlinePatterns = md.inlinePatterns def __makePlaceholder(self, type): """ Generate a placeholder """ @@ -70,7 +71,7 @@ class InlineProcessor(Treeprocessor): * index: index, from which we start search Returns: placeholder id and string index, after the found placeholder. - + """ m = self.__placeholder_re.search(data, index) if m: @@ -99,9 +100,9 @@ class InlineProcessor(Treeprocessor): """ if not isinstance(data, util.AtomicString): startIndex = 0 - while patternIndex < len(self.markdown.inlinePatterns): + while patternIndex < len(self.inlinePatterns): data, matched, startIndex = self.__applyPattern( - self.markdown.inlinePatterns.value_for_index(patternIndex), + self.inlinePatterns.value_for_index(patternIndex), data, patternIndex, startIndex) if not matched: patternIndex += 1 @@ -128,11 +129,10 @@ class InlineProcessor(Treeprocessor): text = subnode.tail subnode.tail = None - childResult = self.__processPlaceholders(text, subnode) + childResult = self.__processPlaceholders(text, subnode, isText) if not isText and node is not subnode: - pos = list(node).index(subnode) - node.remove(subnode) + pos = list(node).index(subnode) + 1 else: pos = 0 @@ -140,7 +140,7 @@ class InlineProcessor(Treeprocessor): for newChild in childResult: node.insert(pos, newChild) - def __processPlaceholders(self, data, parent): + def __processPlaceholders(self, data, parent, isText=True): """ Process string with placeholders and generate ElementTree tree. @@ -150,7 +150,7 @@ class InlineProcessor(Treeprocessor): * parent: Element, which contains processing inline data Returns: list with ElementTree elements with applied inline patterns. - + """ def linkText(text): if text: @@ -159,6 +159,11 @@ class InlineProcessor(Treeprocessor): result[-1].tail += text else: result[-1].tail = text + elif not isText: + if parent.tail: + parent.tail += text + else: + parent.tail = text else: if parent.text: parent.text += text @@ -182,7 +187,7 @@ class InlineProcessor(Treeprocessor): for child in [node] + list(node): if child.tail: if child.tail.strip(): - self.__processElementText(node, child,False) + self.__processElementText(node, child, False) if child.text: if child.text.strip(): self.__processElementText(child, child) @@ -239,7 +244,7 @@ class InlineProcessor(Treeprocessor): # We need to process current node too for child in [node] + list(node): if not isString(node): - if child.text: + if child.text: child.text = self.__handleInline(child.text, patternIndex + 1) if child.tail: @@ -287,11 +292,10 @@ class InlineProcessor(Treeprocessor): if child.tail: tail = self.__handleInline(child.tail) dumby = util.etree.Element('d') - tailResult = self.__processPlaceholders(tail, dumby) - if dumby.text: - child.tail = dumby.text - else: - child.tail = None + child.tail = None + tailResult = self.__processPlaceholders(tail, dumby, False) + if dumby.tail: + child.tail = dumby.tail pos = list(currElement).index(child) + 1 tailResult.reverse() for newChild in tailResult: @@ -303,7 +307,7 @@ class InlineProcessor(Treeprocessor): if self.markdown.enable_attributes: if element.text and isString(element.text): element.text = \ - inlinepatterns.handleAttributes(element.text, + inlinepatterns.handleAttributes(element.text, element) i = 0 for newChild in lst: @@ -357,4 +361,4 @@ class PrettifyTreeprocessor(Treeprocessor): pres = root.getiterator('pre') for pre in pres: if len(pre) and pre[0].tag == 'code': - pre[0].text = pre[0].text.rstrip() + '\n' + pre[0].text = util.AtomicString(pre[0].text.rstrip() + '\n') diff --git a/awx/lib/site-packages/markdown/util.py b/awx/lib/site-packages/markdown/util.py index edb25886ad..0541e7b409 100644 --- a/awx/lib/site-packages/markdown/util.py +++ b/awx/lib/site-packages/markdown/util.py @@ -10,11 +10,11 @@ Python 3 Stuff """ PY3 = sys.version_info[0] == 3 -if PY3: +if PY3: #pragma: no cover string_type = str text_type = str int2str = chr -else: +else: #pragma: no cover string_type = basestring text_type = unicode int2str = unichr @@ -58,14 +58,15 @@ RTL_BIDI_RANGES = ( ('\u0590', '\u07FF'), # Extensions should use "markdown.util.etree" instead of "etree" (or do `from # markdown.util import etree`). Do not import it by yourself. -try: # Is the C implementation of ElementTree available? +try: #pragma: no cover + # Is the C implementation of ElementTree available? import xml.etree.cElementTree as etree from xml.etree.ElementTree import Comment # Serializers (including ours) test with non-c Comment etree.test_comment = Comment if etree.VERSION < "1.0.5": raise RuntimeError("cElementTree version 1.0.5 or higher is required.") -except (ImportError, RuntimeError): +except (ImportError, RuntimeError): #pragma: no cover # Use the Python implementation of ElementTree? import xml.etree.ElementTree as etree if etree.VERSION < "1.1": @@ -85,15 +86,20 @@ def isBlockLevel(tag): # Some ElementTree tags are not strings, so return False. return False -def parseBoolValue(value, fail_on_errors=True): +def parseBoolValue(value, fail_on_errors=True, preserve_none=False): """Parses a string representing bool value. If parsing was successful, - returns True or False. If parsing was not successful, raises - ValueError, or, if fail_on_errors=False, returns None.""" + returns True or False. If preserve_none=True, returns True, False, + or None. If parsing was not successful, raises ValueError, or, if + fail_on_errors=False, returns None.""" if not isinstance(value, string_type): + if preserve_none and value is None: + return value return bool(value) + elif preserve_none and value.lower() == 'none': + return None elif value.lower() in ('true', 'yes', 'y', 'on', '1'): return True - elif value.lower() in ('false', 'no', 'n', 'off', '0'): + elif value.lower() in ('false', 'no', 'n', 'off', '0', 'none'): return False elif fail_on_errors: raise ValueError('Cannot parse bool value: %r' % value)