§
    r°Û_©.  ã                   óŒ   — d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ  G d
„ dej        ¦  «        ZdS )z/Implement some common transforms on parsed AST.é    N)ÚnodesÚ
transforms)Ú
StringList)ÚParser)Únew_document)Úaddnodesé   )ÚDummyStateMachinec                   ó~   — e Zd ZdZd„ ZdZ eddg¦  «        Zdddddddd	gd
„ ddœ
Zd„ Z	d„ Z
d„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚAutoStructifyz‰Automatically try to transform blocks to sphinx directives.

    This class is designed to handle AST generated by CommonMarkParser.
    c                 ó”  — t          j        j        | g|¢R i |¤Ž | j        j        | _        | j                             ¦   «         | _        	 | j        j        j	        j        j
        }| j                             |¦  «         n# t          $ r Y nw xY w| j                             dd¦  «        r| j                             d¦  «         d S d S )NÚenable_auto_doc_refFz8AutoStructify option "enable_auto_doc_ref" is deprecated)r   Ú	TransformÚ__init__ÚdocumentÚreporterÚdefault_configÚcopyÚconfigÚsettingsÚenvÚrecommonmark_configÚupdateÚAttributeErrorÚgetÚwarning)ÚselfÚargsÚkwargsÚnew_cfgs       ú8/usr/lib/python3/dist-packages/recommonmark/transform.pyr   zAutoStructify.__init__   sí   € ÝÔÔ% dÐ<¨TÐ<Ð<Ð<°VÐ<Ð<Ð<ØœÔ.ˆŒØÔ)×.Ò.Ñ0Ô0ˆŒð	Ø”mÔ,Ô0Ô7ÔKˆGØŒK×Ò˜wÑ'Ô'Ð'Ð'øÝð 	ð 	ð 	ØˆDð	øøøð
 Œ;�?Š?Ð0°%Ñ8Ô8ð 	LØŒM×!Ò!ØJñLô Lð Lð Lð Lð	Lð 	Ls   Á5B Â
BÂBr	   ÚmdÚrstFNTz.mdc                 ó   — | S )N© )Úxs    r!   ú<lambda>zAutoStructify.<lambda>3   s   €  !€ ó    )
r   Úauto_toc_maxdepthÚauto_toc_tree_sectionÚenable_auto_toc_treeÚenable_eval_rstÚenable_mathÚenable_inline_mathÚcommonmark_suffixesÚurl_resolverÚknown_url_schemesc                 óî  — d}t          |j        ¦  «        dk    rd|v r|d         nd}nDt          |j        d         t          j        ¦  «        r|j        d                              ¦   «         }|d         }|                     d¦  «        dk    r||dfS d}|                     d¦  «        }t          |¦  «        dk    r|d	         }t          |¦  «        dk    st          |d         ¦  «        dk    r||dfS |d         }t          j	         
                    t          j	                             | j        |¦  «        ¦  «        }t          j	                             || j        ¦  «        }|                     d
d	¦  «        }t          |¦  «        dk    r½|d	         t           j        v r©t          j	                             |¦  «        rŠ|                     | j        ¦  «        rpt          j	        j        dk    r%|                     t          j	        j        d¦  «        }d|                     d
d	¦  «        d         z   }	|	dz   }|€|||	fS ||dz   |z   dfS | j        r|                      |¦  «        }|r|d|z   z  }||dfS )a  Analyze the ref block, and return the information needed.

        Parameters
        ----------
        ref : nodes.reference

        Returns
        -------
        result : tuple of (str, str, str)
            The returned result is tuple of (title, uri, docpath).
            title is the display title of the ref.
            uri is the html uri of to the ref after resolve.
            docpath is the absolute document path to the document, if
            the target corresponds to an internal document, this can bex None
        Nr   ÚnameÚrefuriz://éÿÿÿÿú#é   r	   ú.ú/z.html)ÚlenÚchildrenÚ
isinstancer   ÚTextÚastextÚfindÚsplitÚosÚpathÚabspathÚjoinÚfile_dirÚrelpathÚroot_dirÚrsplitr   Ú
suffix_setÚexistsÚ
startswithÚsepÚreplacer0   )
r   ÚrefÚtitleÚuriÚanchorÚarrrC   rF   ÚsuffixÚdocpaths
             r!   Ú	parse_refzAutoStructify.parse_ref7   sQ  € ð  ˆÝˆsŒ|ÑÔ Ò!Ð!Ø#)¨S = =�C˜”K�K°dˆEˆEÝ˜œ Qœ­¬Ñ4Ô4ð 	-Ø”L ”O×*Ò*Ñ,Ô,ˆEØ�(ŒmˆØ�8Š8�E‰?Œ?˜bÒ Ð Ø˜3 Ð%Ð%ØˆØ�iŠi˜‰nŒnˆÝˆs‰8Œ8�qŠ=ˆ=Ø˜”VˆFÝˆs‰8Œ8�aŠ<ˆ<�3˜s 1œv™;œ;¨!Ò+Ð+Ø˜3 Ð%Ð%Ø�!Œfˆå”'—/’/¥"¤'§,¢,¨t¬}¸cÑ"BÔ"BÑCÔCˆÝ”'—/’/ '¨4¬=Ñ9Ô9ˆØ—’  QÑ'Ô'ˆÝˆv‰;Œ;˜!ÒÐ  q¤	­]Ô-EÐ EÐ EÝ”—’˜wÑ'Ô'ð !FØ,3×,>Ò,>¸t¼}Ñ,MÔ,Mð !Fõ ŒwŒ{˜cÒ!Ð!Ø!Ÿ/š/­"¬'¬+°sÑ;Ô;�Ø˜GŸNšN¨3°Ñ2Ô2°1Ô5Ñ5ˆGà˜GÑ#ˆCØˆ~Ø˜s GÐ,Ð,à˜s S™y¨6Ñ1°4Ð8Ð8ð Ô ð 1Ø×'Ò'¨Ñ0Ô0�Øð $Ø�s˜V‘|Ñ#�Ø˜3 Ð%Ð%r(   c                 óô  — | j         d         sdS | j         d         }|�ô|j        €dS d}t          |j        t          j        ¦  «        r9|j                             t          j        ¦  «        }|�|j        j        |         }nat          |j        t          j        ¦  «        rB|j        j                             t          j        ¦  «        }|�|j        j        j        |         }|sdS | 	                    ¦   «          
                    ¦   «         |k    rdS d}t          |t          j        ¦  «        rd}nt          |t          j        ¦  «        rd}|€dS g }|j        dd…         D �]5}t          |t          j        ¦  «        sJ ‚t          |j        ¦  «        dk    r dS |j        d         }t          |t          j        ¦  «        s dS t          |j        ¦  «        dk    r dS |j        d         }	t          |	t          j        ¦  «        r|	j        d         }	t          |	t          j        ¦  «        s dS |                      |	¦  «        \  }}
}|�|
                     d¦  «        r dS |r|                     ||f¦  «         �Œ|                     ||
f¦  «         �Œ7| j                             | j        |j        | j        ¦  «         | j                             d| j         d         |d	œd
„ |D ¦   «         ¬¦  «        S )aú  Try to convert a list block to toctree in rst.

        This function detects if the matches the condition and return
        a converted toc tree node. The matching condition:
        The list only contains one level, and only contains references

        Parameters
        ----------
        node: nodes.Sequential
            A list node in the doctree

        Returns
        -------
        tocnode: docutils node
            The converted toc tree node, None if conversion is not possible.
        r+   Nr*   r   r	   r6   Útoctreer)   )ÚmaxdepthÚnumberedc                 ó$   — g | ]\  }}|›d |›d�‘ŒS )z <ú>r%   )Ú.0ÚkÚvs      r!   ú
<listcomp>z/AutoStructify.auto_toc_tree.<locals>.<listcomp>¼   s)   € Ð9Ð9Ð9©D¨A¨q ! ! ! Q Q QÐ'Ð9Ð9Ð9r(   )ÚoptionsÚcontent)r   Úparentr<   r   ÚsectionÚfirst_child_matching_classrO   r;   Ú	paragraphr>   ÚstripÚbullet_listÚenumerated_listÚ	list_itemr:   r   Úpending_xrefÚ	referencerU   rK   ÚappendÚstate_machineÚresetr   Úcurrent_levelÚrun_directive)r   ÚnodeÚsecrO   ÚchildrY   ÚrefsÚndÚparrN   rP   rT   s               r!   Úauto_toc_treezAutoStructify.auto_toc_treen   s  € ð" Œ{Ð1Ô2ð 	Ø�4ð ŒkÐ1Ô2ˆØˆ?ØŒ{Ð"Ø�tØˆEÝ˜$œ+¥u¤}Ñ5Ô5ð ?Øœ×>Ò>½u¼{ÑKÔK�ØÐ$Ø œKÔ0°Ô7�EøÝ˜DœK­¬Ñ9Ô9ð ?ØœÔ*×EÒEÅeÄkÑRÔR�ØÐ$Ø œKÔ.Ô7¸Ô>�EØð Ø�tØ�|Š|‰~Œ~×#Ò#Ñ%Ô%¨Ò,Ð,Ø�tàˆÝ�d�EÔ-Ñ.Ô.ð 	ØˆHˆHÝ˜�eÔ3Ñ4Ô4ð 	ØˆHàÐØ�4ØˆØ”-   Ô"ð 	*ñ 	*ˆBÝ˜b¥%¤/Ñ2Ô2Ð2Ð2Ð2Ý�2”;ÑÔ 1Ò$Ð$Ø�t�tØ”+˜a”.ˆCÝ˜c¥5¤?Ñ3Ô3ð Ø�t�tÝ�3”<Ñ Ô  AÒ%Ð%Ø�t�tØ”,˜q”/ˆCÝ˜#�xÔ4Ñ5Ô5ð &Ø”l 1”o�Ý˜c¥5¤?Ñ3Ô3ð Ø�t�tØ"&§.¢.°Ñ"5Ô"5ÑˆE�3˜Øˆ} §¢¨sÑ 3Ô 3ˆ}Ø�t�tØð *Ø—’˜U GÐ,Ñ-Ô-Ð-Ñ-à—’˜U C˜LÑ)Ô)Ð)Ñ)ØÔ× Ò  ¤Ø!%¤Ø!%Ô!3ñ	5ô 	5ð 	5ð Ô!×/Ò/Øà œKÐ(;Ô<Ø$ðð ð :Ð9°DÐ9Ñ9Ô9ð 0ñ ;ô ;ð 	;r(   c                 ó$  — t          |t          j        ¦  «        sJ ‚t          |j        ¦  «        dk    rdS |j        d         }t          |t          j        ¦  «        sdS |                     ¦   «                              ¦   «         }|                     d¦  «        ru| 	                    d¦  «        r`| j
        d         sdS |dd…         }| j                             | j        |j        | j        ¦  «         | j                             d|¬¦  «        S dS )	a5  Try to automatically generate nodes for inline literals.

        Parameters
        ----------
        node : nodes.literal
            Original codeblock node
        Returns
        -------
        tocnode: docutils node
            The converted toc tree node, None if conversion is not possible.
        r	   Nr   ú$r.   r5   Úmath©ra   )r<   r   Úliteralr:   r;   r=   r>   rf   rK   Úendswithr   rm   rn   r   rb   ro   Úrun_role)r   rq   ra   s      r!   Úauto_inline_codezAutoStructify.auto_inline_code¾   s  € õ ˜$¥¤Ñ.Ô.Ð.Ð.Ð.ÝˆtŒ}ÑÔ Ò"Ð"Ø�4Ø”- Ô"ˆÝ˜'¥5¤:Ñ.Ô.ð 	Ø�4Ø—.’.Ñ"Ô"×(Ò(Ñ*Ô*ˆØ×Ò˜cÑ"Ô"ð 		 w×'7Ò'7¸Ñ'<Ô'<ð 		Ø”;Ð3Ô4ð Ø�tØ˜a ˜d”mˆGØÔ×$Ò$ T¤]Ø%)¤[Ø%)Ô%7ñ9ô 9ð 9ð Ô%×.Ò.¨v¸wÐ.ÑGÔGÐGà�4r(   c                 ón  — t          |t          j        ¦  «        sJ ‚|}d|vrdS | j                             | j        |j        | j        ¦  «         |j         	                    d¦  «        }|d         }|dk    r+| j
        d         r| j                             d|¬¦  «        S �n|dk    rg| j
        d         rYt          j        ¦   «         }| j        j                             t          ||j        ¬	¦  «        d
|d¬¦  «         |j        dd…         S n¥t%          j        d|¦  «        }|rpt)          ¦   «         }t+          d| j        j        ¦  «        }d|                     d
¦  «        z   dz   |j        z   }|                     ||¦  «         |j        dd…         S | j                             d|g|¬¦  «        S dS )a<  Try to automatically generate nodes for codeblock syntax.

        Parameters
        ----------
        node : nodes.literal_block
            Original codeblock node
        Returns
        -------
        tocnode: docutils node
            The converted toc tree node, None if conversion is not possible.
        ÚlanguageNú
rz   r-   r{   Úeval_rstr,   )Úsourcer   T)rq   Úmatch_titlesz[ ]?[\w_-]+::.*z.. z
code-block)Ú	argumentsra   )r<   r   Úliteral_blockrm   rn   r   rb   ro   Ú	rawsourcer@   r   rp   rc   ÚstateÚnested_parser   r„   r;   ÚreÚsearchr   r   r   ÚgroupÚparse)	r   rq   Úoriginal_nodera   r�   ÚmatchÚparserÚnew_docÚ	newsources	            r!   Úauto_code_blockzAutoStructify.auto_code_blockÜ   sî  € õ ˜$¥Ô 3Ñ4Ô4Ð4Ð4Ð4ØˆØ˜TÐ!Ð!Ø�4ØÔ× Ò  ¤Ø!%¤Ø!%Ô!3ñ	5ô 	5ð 	5ð ”.×&Ò& tÑ,Ô,ˆØ˜
Ô#ˆØ�vÒÐØŒ{˜=Ô)ð -ØÔ)×7Ò7Ø Gð 8ñ -ô -ð -ñ-ð ˜Ò#Ð#ØŒ{Ð,Ô-ð (å”}‘”�ØÔ"Ô(×5Ò5Ý˜w¨}Ô/CÐDÑDÔDØ˜D¨tð 6ñ 5ô 5ð 5ð ”} Q Q QÔ'Ð'ð(õ ”IÐ/°Ñ:Ô:ˆEØð 	%Ý™œ�Ý& t¨T¬]Ô-CÑDÔD�Ø" U§[¢[°¡^¤^Ñ3°dÑ:¸T¼^ÑK�	Ø—’˜Y¨Ñ0Ô0Ð0ØÔ'¨¨¨Ô*Ð*àÔ)×7Ò7Ø ¨X¨JØ#ð 8ñ %ô %ð %ð ˆtr(   c                 ó(  — d}t          |t          j        ¦  «        r|                      |¦  «        }n_t          |t          j        ¦  «        r|                      |¦  «        }n/t          |t          j        ¦  «        r|                      |¦  «        }|S )aR  Try to find replace node for current node.

        Parameters
        ----------
        node : docutil node
            Node to find replacement for.

        Returns
        -------
        nodes : node or list of node
            The replacement nodes of current node.
            Returns None if no replacement can be found.
        N)r<   r   Ú
Sequentialrw   r‡   r”   r|   r   )r   rq   Únewnodes      r!   Úfind_replacezAutoStructify.find_replace  s‰   € ð ˆÝ�d�EÔ,Ñ-Ô-ð 	2Ø×(Ò(¨Ñ.Ô.ˆGˆGÝ˜�eÔ1Ñ2Ô2ð 	2Ø×*Ò*¨4Ñ0Ô0ˆGˆGÝ˜�eœmÑ,Ô,ð 	2Ø×+Ò+¨DÑ1Ô1ˆGØˆr(   c                 óœ  — | j         }t          |t          j        ¦  «        rd|v r|d         | _         g }g }|j        dd…         D ]F}|                      |¦  «        }|�|                     ||f¦  «         Œ1|                     |¦  «         ŒG|D ]\  }}|                     ||¦  «         Œ|D ]}	|                      |	¦  «         Œ|| _         dS )zzTraverse the document tree rooted at node.

        node : docutil node
            current root node to traverse
        ÚlevelN)	ro   r<   r   rc   r;   r˜   rl   rM   Útraverse)
r   rq   Ú	old_levelÚto_visitÚ
to_replaceÚcr—   ÚoldnodeÚnewnodesrs   s
             r!   r›   zAutoStructify.traverse"  sÿ   € ð Ô&ˆ	Ý�d�EœMÑ*Ô*ð 	3Ø˜$ˆˆØ%)¨'¤]�Ô"ØˆØˆ
Ø”˜q˜q˜qÔ!ð 	#ð 	#ˆAØ×'Ò'¨Ñ*Ô*ˆGØÐ"Ø×!Ò! 1 g ,Ñ/Ô/Ð/Ð/à—’ Ñ"Ô"Ð"Ð"à!+ð 	,ð 	,ÑˆG�XØ�LŠL˜ (Ñ+Ô+Ð+Ð+àð 	!ð 	!ˆEØ�MŠM˜%Ñ Ô Ð Ð Ø&ˆÔÐÐr(   c                 óx  — | j         d         }| j                             d|z  ¦  «         |                     t	          | j        d         ¦  «        ¦  «        sdS | j        d         | _        t          | j        ¦  «        sJ ‚t          ¦   «         | _	        d| _
        t          j                             t          j                             | j         d         ¦  «        ¦  «        | _        t          j                             | j         j        j        j        ¦  «        | _        |                      | j         ¦  «         dS )z*Apply the transformation by configuration.r„   zAutoStructify: %sr/   Nr0   r   )r   r   Úinfor}   Útupler   r0   Úcallabler
   rm   ro   rA   rB   rC   ÚdirnamerE   r   r   ÚsrcdirrG   r›   )r   r„   s     r!   ÚapplyzAutoStructify.apply<  sõ   € à”˜xÔ(ˆàŒ×ÒÐ.°Ñ7Ñ8Ô8Ð8ð �Š�u T¤[Ð1FÔ%GÑHÔHÑIÔIð 	ØˆFà œK¨Ô7ˆÔÝ˜Ô)Ñ*Ô*Ð*Ð*Ð*å.Ñ0Ô0ˆÔØˆÔÝœŸš­¬¯ª¸¼ÀhÔ8OÑ(PÔ(PÑQÔQˆŒÝœŸš¨¬Ô(>Ô(BÔ(IÑJÔJˆŒØ�Š�d”mÑ$Ô$Ð$Ð$Ð$r(   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Údefault_priorityÚsetrI   r   rU   rw   r   r”   r˜   r›   r¨   r%   r(   r!   r   r      sê   € € € € € ðð ð
Lð Lð Lð" ÐØ��d˜E�]Ñ#Ô#€Jð  %ØØ!%Ø $ØØØ"Ø %˜wØ#˜Ø!ðð €Nð5&ð 5&ð 5&ðnN;ð N;ð N;ð`ð ð ð<-ð -ð -ð^ð ð ð.'ð 'ð 'ð4%ð %ð %ð %ð %r(   r   )r¬   rA   r‹   Údocutilsr   r   Údocutils.statemachiner   Údocutils.parsers.rstr   Údocutils.utilsr   Úsphinxr   Ústatesr
   r   r   r%   r(   r!   ú<module>rµ      sÐ   ðØ 5Ð 5à 	€	€	€	Ø 	€	€	€	à &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø Ð Ð Ð Ð Ð à %Ð %Ð %Ð %Ð %Ð %ð~%ð ~%ð ~%ð ~%ð ~%�JÔ(ñ ~%ô ~%ð ~%ð ~%ð ~%r(   