0
    £ˆïî¾448êÆù À   £‹      •“_oÓ0Åß÷).~à­¹I[Û£‘T¢R×V]Bˆ7q³ÔŽl—0>=NSXAí`Oþ÷óñ9×6}‘.’ìÓrï³Û,?¼›M Ä�£1ÍÒ~a„âdN€TÎ5WˆmÛí(Ð¦Äl…•ÛÖc´ÎÈÜ…+» Ý» Z	^ø¨“®lª
ñôPïœ•…ãÎ´7Ë¯v!Ö–+Šý/�ºÖÅC'=GÆÓûãùz¯Öu£®‚o¼–¥Š‰ÓaTnK°&�	Ê\+‹ëš«û ”¼v1ù<M_<‡®êv3Ê¡2b“·I<¿^Ä)as¾ùiæÖ37„Í¸u°Õ…ÜHQœ…ïzøNþ8/˜öL*lndã¤V�(úˆÇQs]Û†û¬¯|‚ÊS=Rü«<ÿ£Ë›Õdž¥ÓU_’¢“xt÷Ô¥¶ôCå •FäN›‡ƒí^ã¥ZÛæú×¦Œ,+GÀ N’ÏH²S÷J·ê8Œ/ÔÉÝû	ì®ñ2¿»Çfÿr7‡£A8#ß\E¯Î€£ËË'büçµááASÜÿ
Šý‡û	N¿þŽÓ    H  ¥ˆl–ß=¿JÕ/”Š�~àš¸ËJbÑ¿�þDèÂ³q¸9%]xùÀ„Ó¿_ŠI|¥�+Wé3ž¯Èv…†±’rÿ '¡   ¥"""Docutils CommonMark parser"""

import sys
from os.path import splitext

from docutils import parsers, nodes
from sphinx import addnodes

from commonmark import Parser

from warnings import warn

if sys.version_info < (3, 0):
    from urlparse import urlparse, unquote
else:
    from urllib.parse import urlparse, unquote

__all__ = ['CommonMarkParser']


class CommonMarkParser(parsers.Parser):

    """Docutils parser for CommonMark"""

    supported = ('md', 'markdown')
    translate_section_name = None

    default_config = {
        'known_url_schemes': None,
    }

    def __init__(self):
        self._level_to_elem = {}

    def parse(self, inputstring, document):
        self.document = document
        self.current_node = document
        self.config = self.default_config.copy()
        try:
            new_cfg = self.document.settings.env.config.recommonmark_config
            self.config.update(new_cfg)
        except AttributeError:
            pass
        self.setup_parse(inputstring, document)
        self.setup_sections()
        parser = Parser()
        ast = parser.parse(inputstring + '\n')
        self.convert_ast(ast)
        self.finish_parse()

    def convert_ast(self, ast):
        for (node, entering) in ast.walker():
            fn_prefix = "visit" if entering else "depart"
            fn_name = "{0}_{1}".format(fn_prefix, node.t.lower())
            fn_default = "default_{0}".format(fn_prefix)
            fn = getattr(self, fn_name, None)
            if fn is None:
                fn = getattr(self, fn_default)
            fn(node)

    # Node type enter/exit handlers
    def default_visit(self, mdnode):
        pass

    def default_depart(self, mdnode):
        """Default node depart handler

        If there is a matching ``visit_<type>`` method for a container node,
        then we should make sure to back up to it's parent element when the node
        is exited.
        """
        if mdnode.is_container():
            fn_name = 'visit_{0}'.format(mdnode.t)
            if not hasattr(self, fn_name):
                warn("Container node skipped: type={0}".format(mdnode.t))
            else:
                self.current_node = self.current_node.parent

    def visit_heading(self, mdnode):
        # Test if we're replacing a section level first
        if isinstance(self.current_node, nodes.section):
            if self.is_section_level(mdnode.level, self.current_node):
                self.current_node = self.current_node.parent

        title_node = nodes.title()
        title_node.line = mdnode.sourcepos[0][0]

        new_section = nodes.section()
        new_section.line = mdnode.sourcepos[0][0]
        new_section.append(title_node)

        self.add_section(new_section, mdnode.level)

        # Set the current node to the title node to accumulate text children/etc
        # for heading.
        self.current_node = title_node

    def depart_heading(self, _):
        """Finish establishing section

        Wrap up title node, but stick in the section node. Add the section names
        based on all the text nodes added to the title.
        """
        assert isinstance(self.current_node, nodes.title)
        # The title node has a tree of text nodes, use the whole thing to
        # determine the section id and names
        text = self.current_node.astext()
        if self.translate_section_name:
            text = self.translate_section_name(text)
        name = nodes.fully_normalize_name(text)
        section = self.curren