404

[ Avaa Bypassed ]




Upload:

Command:

botdev@18.219.103.116: ~ $
"""
Python-Markdown Extra Extension
===============================

A compilation of various Python-Markdown extensions that imitates
[PHP Markdown Extra](http://michelf.com/projects/php-markdown/extra/).

Note that each of the individual extensions still need to be available
on your PYTHONPATH. This extension simply wraps them all up as a
convenience so that only one extension needs to be listed when
initiating Markdown. See the documentation for each individual
extension for specifics about that extension.

There may be additional extensions that are distributed with
Python-Markdown that are not included here in Extra. Those extensions
are not part of PHP Markdown Extra, and therefore, not part of
Python-Markdown Extra. If you really would like Extra to include
additional extensions, we suggest creating your own clone of Extra
under a differant name. You could also edit the `extensions` global
variable defined below, but be aware that such changes may be lost
when you upgrade to any future version of Python-Markdown.

See <https://pythonhosted.org/Markdown/extensions/extra.html>
for documentation.

Copyright The Python Markdown Project

License: [BSD](http://www.opensource.org/licenses/bsd-license.php)

"""

from __future__ import absolute_import
from __future__ import unicode_literals
from . import Extension
from ..blockprocessors import BlockProcessor
from .. import util
import re

extensions = [
    'markdown.extensions.smart_strong',
    'markdown.extensions.fenced_code',
    'markdown.extensions.footnotes',
    'markdown.extensions.attr_list',
    'markdown.extensions.def_list',
    'markdown.extensions.tables',
    'markdown.extensions.abbr'
]


class ExtraExtension(Extension):
    """ Add various extensions to Markdown class."""

    def __init__(self, *args, **kwargs):
        """ config is a dumb holder which gets passed to actual ext later. """
        self.config = kwargs.pop('configs', {})
        self.config.update(kwargs)

    def extendMarkdown(self, md, md_globals):
        """ Register extension instances. """
        md.registerExtensions(extensions, self.config)
        if not md.safeMode:
            # Turn on processing of markdown text within raw html
            md.preprocessors['html_block'].markdown_in_raw = True
            md.parser.blockprocessors.add('markdown_block',
                                          MarkdownInHtmlProcessor(md.parser),
                                          '_begin')
            md.parser.blockprocessors.tag_counter = -1
            md.parser.blockprocessors.contain_span_tags = re.compile(
                r'^(p|h[1-6]|li|dd|dt|td|th|legend|address)$', re.IGNORECASE)


def makeExtension(*args, **kwargs):
    return ExtraExtension(*args, **kwargs)


class MarkdownInHtmlProcessor(BlockProcessor):
    """Process Markdown Inside HTML Blocks."""
    def test(self, parent, block):
        return block == util.TAG_PLACEHOLDER % \
            str(self.parser.blockprocessors.tag_counter + 1)

    def _process_nests(self, element, block):
        """Process the element's child elements in self.run."""
        # Build list of indexes of each nest within the parent element.
        nest_index = []  # a list of tuples: (left index, right index)
        i = self.parser.blockprocessors.tag_counter + 1
        while len(self._tag_data) > i and self._tag_data[i]['left_index']:
            left_child_index = self._tag_data[i]['left_index']
            right_child_index = self._tag_data[i]['right_index']
            nest_index.append((left_child_index - 1, right_child_index))
            i += 1

        # Create each nest subelement.
        for i, (left_index, right_index) in enumerate(nest_index[:-1]):
            self.run(element, block[left_index:right_index],
                     block[right_index:nest_index[i + 1][0]], True)
        self.run(element, block[nest_index[-1][0]:nest_index[-1][1]],  # last
                 block[nest_index[-1][1]:], True)                      # nest

    def run(self, parent, blocks, tail=None, nest=False):
        self._tag_data = self.parser.markdown.htmlStash.tag_data

        self.parser.blockprocessors.tag_counter += 1
        tag = self._tag_data[self.parser.blockprocessors.tag_counter]

        # Create Element
        markdown_value = tag['attrs'].pop('markdown')
        element = util.etree.SubElement(parent, tag['tag'], tag['attrs'])

        # Slice Off Block
        if nest:
            self.parser.parseBlocks(parent, tail)  # Process Tail
            block = blocks[1:]
        else:  # includes nests since a third level of nesting isn't supported
            block = blocks[tag['left_index'] + 1: tag['right_index']]
            del blocks[:tag['right_index']]

        # Process Text
        if (self.parser.blockprocessors.contain_span_tags.match(  # Span Mode
                tag['tag']) and markdown_value != 'block') or \
                markdown_value == 'span':
            element.text = '\n'.join(block)
        else:                                                     # Block Mode
            i = self.parser.blockprocessors.tag_counter + 1
            if len(self._tag_data) > i and self._tag_data[i]['left_index']:
                first_subelement_index = self._tag_data[i]['left_index'] - 1
                self.parser.parseBlocks(
                    element, block[:first_subelement_index])
                if not nest:
                    block = self._process_nests(element, block)
            else:
                self.parser.parseBlocks(element, block)

Filemanager

Name Type Size Permission Actions
__init__.py File 3.76 KB 0644
__init__.pyc File 4 KB 0644
abbr.py File 2.67 KB 0644
abbr.pyc File 4.14 KB 0644
admonition.py File 3.09 KB 0644
admonition.pyc File 3.66 KB 0644
attr_list.py File 6.12 KB 0644
attr_list.pyc File 6.21 KB 0644
codehilite.py File 9.54 KB 0644
codehilite.pyc File 9.3 KB 0644
def_list.py File 3.66 KB 0644
def_list.pyc File 4.31 KB 0644
extra.py File 5.42 KB 0644
extra.pyc File 5.57 KB 0644
fenced_code.py File 4.01 KB 0644
fenced_code.pyc File 4.45 KB 0644
footnotes.py File 14.57 KB 0644
footnotes.pyc File 14.79 KB 0644
headerid.py File 3.24 KB 0644
headerid.pyc File 4.23 KB 0644
meta.py File 2.34 KB 0644
meta.pyc File 2.95 KB 0644
nl2br.py File 859 B 0644
nl2br.pyc File 1.54 KB 0644
sane_lists.py File 1.56 KB 0644
sane_lists.pyc File 2.73 KB 0644
smart_strong.py File 1.17 KB 0644
smart_strong.pyc File 1.81 KB 0644
smarty.py File 10.12 KB 0644
smarty.pyc File 10.23 KB 0644
tables.py File 7.67 KB 0644
tables.pyc File 6.79 KB 0644
toc.py File 10.79 KB 0644
toc.pyc File 10.53 KB 0644
wikilinks.py File 2.8 KB 0644
wikilinks.pyc File 4.02 KB 0644