
    'Wd1                       U d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZmZ ddlmZm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mZ ddlmZ ddlm Z  ddlm!Z!m"Z"m#Z#m$Z$ 	 d dl%Z%ejN                  jQ                         ejR                  jQ                         ejT                  jQ                         ejV                  jQ                         ejX                  jQ                         dZ-de.d<    G d d      Z/y# e&$ r dZ%Y w xY w)    )annotations)Callable	GeneratorIterableMappingMutableMapping)contextmanager)AnyLiteraloverload   )helperspresets)normalize_urlutils)ParserBlock)
ParserCore)ParserInline)RendererHTMLRendererProtocol)	StateCore)Token)EnvTypeOptionsDictOptionsType
PresetTypeN)defaultz
js-defaultzero
commonmarkzgfm-likezdict[str, PresetType]_PRESETSc                  r   e Zd Z	 	 ded	 	 	 	 	 ddZddZedd       Zedd       Zed d       Zed!d       Zed"d	       Zd"d
Zd#dZ	 d$	 	 	 	 	 d%dZ	d&dZ
d&dZ	 d'	 	 	 	 	 d(dZ	 d'	 	 	 	 	 d(dZed)d       Z	 d*	 	 	 	 	 	 	 d+dZ	 	 	 	 	 	 	 	 d,dZd$d-dZd$d.dZd$d-dZd$d.dZd/dZd0dZd1dZy)2
MarkdownItN)renderer_clsc               N   t         | _         t        | _        t               | _        t	               | _        t               | _         ||       | _        t        rt        j                         nd| _        |rt        |t              st        d| d      | j                  ||       y)a6  Main parser class

        :param config: name of configuration to load or a pre-defined dictionary
        :param options_update: dictionary that will be merged into ``config["options"]``
        :param renderer_cls: the class to load as the renderer:
            ``self.renderer = renderer_cls(self)
        Nz$options_update should be a mapping: z4
(Perhaps you intended this to be the renderer_cls?))options_update)r   r   r   inliner   blockr   corerenderer
linkify_it	LinkifyItlinkify
isinstancer   	TypeError	configure)selfconfigr%   r#   s       2/usr/lib/python3/dist-packages/markdown_it/main.py__init__zMarkdownIt.__init__!   s     
 #n ]
L	$T*1;z++- *^W"E6~6FGH  	vn=    c                b    | j                   j                   d| j                   j                   dS )N.z())	__class__
__module____name__)r0   s    r2   __repr__zMarkdownIt.__repr__C   s+    ..++,Adnn.E.E-FbIIr4   c                     y N r0   names     r2   __getitem__zMarkdownIt.__getitem__F       r4   c                     y r<   r=   r>   s     r2   r@   zMarkdownIt.__getitem__J   rA   r4   c                     y r<   r=   r>   s     r2   r@   zMarkdownIt.__getitem__N   rA   r4   c                     y r<   r=   r>   s     r2   r@   zMarkdownIt.__getitem__R   rA   r4   c                     y r<   r=   r>   s     r2   r@   zMarkdownIt.__getitem__V   rA   r4   c                f    | j                   | j                  | j                  | j                  d|   S )Nr&   r'   r(   r)   rG   r>   s     r2   r@   zMarkdownIt.__getitem__Z   s2    kkZZII	

  	r4   c                $    t        |      | _        y)a  Set parser options (in the same format as in constructor).
        Probably, you will never need it, but you can change options after constructor call.

        __Note:__ To achieve the best possible performance, don't modify a
        `markdown-it` instance options on the fly. If you need multiple configurations
        it's best to create multiple instances and initialize each with separate config.
        N)r   options)r0   rI   s     r2   setzMarkdownIt.setb   s     #7+r4   c                   t        |t              r!|t        vrt        d| d      t        |   }n|}|st	        d      |j                  di       xs i }|ri ||}| j                  |       d|v r|d   j                         D ]j  \  }}|j                  dd      }|r| |   j                  j                  |       |j                  dd      }|sM| |   j                  j                  |       l | S )	a  Batch load of all options and component settings.
        This is an internal method, and you probably will not need it.
        But if you will - see available presets and data structure
        [here](https://github.com/markdown-it/markdown-it/tree/master/lib/presets)

        We strongly recommend to use presets instead of direct config loads.
        That will give better compatibility with next versions.
        zWrong `markdown-it` preset 'z', check namez*Wrong `markdown-it` config, can't be emptyrI   
componentsrulesNrules2)r-   strr    KeyError
ValueErrorgetrJ   itemsruler
enableOnlyruler2)	r0   r   r%   r1   rI   r?   	componentrM   rN   s	            r2   r/   zMarkdownIt.configurel   s    gs#h&!=gYmTUUg&FFIJJ**Y+1r33N3G6!#),#7#=#=#? 9i!gt4J$$//6"x6J%%0089 r4   c                    dD ci c]   }|| |   j                   j                         " }}| j                  j                  j                         |d<   |S c c}w z%Return the names of all active rules.r(   r'   r&   inline2)rT   get_all_rulesr&   rV   r0   chainrM   s      r2   r\   zMarkdownIt.get_all_rules   sb     5
 4;$$2244
 
  ;;--;;=i
   %Ac                    dD ci c]   }|| |   j                   j                         " }}| j                  j                  j                         |d<   |S c c}w rY   )rT   get_active_rulesr&   rV   r]   s      r2   ra   zMarkdownIt.get_active_rules   sb     5
 4;$$5577
 
  ;;-->>@i
r_   c                Z   g }t        |t              r|g}dD ]0  }|j                  | |   j                  j	                  |d             2 |j                  | j
                  j                  j	                  |d             |D cg c]	  }||vs| }}|r|st        d|       | S c c}w )a  Enable list or rules. (chainable)

        :param names: rule name or list of rule names to enable.
        :param ignoreInvalid: set `true` to ignore errors when rule not found.

        It will automatically find appropriate components,
        containing rules with given names. If rule not found, and `ignoreInvalid`
        not set - throws exception.

        Example::

            md = MarkdownIt().enable(['sub', 'sup']).disable('smartquotes')

        rZ   Tz.MarkdownIt. Failed to enable unknown rule(s): )r-   rO   extendrT   enabler&   rV   rQ   r0   namesignoreInvalidresultr^   r?   misseds          r2   rd   zMarkdownIt.enable   s    " eS!GE0 	AEMM$u+++225$?@	Adkk((//t<=#(?4D,>$??-MfXVWW	 @   	B(B(c                Z   g }t        |t              r|g}dD ]0  }|j                  | |   j                  j	                  |d             2 |j                  | j
                  j                  j	                  |d             |D cg c]	  }||vs| }}|r|st        d|       | S c c}w )zThe same as [[MarkdownIt.enable]], but turn specified rules off. (chainable)

        :param names: rule name or list of rule names to disable.
        :param ignoreInvalid: set `true` to ignore errors when rule not found.

        rZ   Tz/MarkdownIt. Failed to disable unknown rule(s): )r-   rO   rc   rT   disabler&   rV   rQ   re   s          r2   rl   zMarkdownIt.disable   s     eS!GE0 	BEMM$u+++33E4@A	Bdkk((00=>#(?4D,>$??-NvhWXX @rj   c              #     K   | j                         }d |j                         D ])  \  }}|dk7  s| |   j                  j                  |       + | j                  j
                  j                  |d          yw)zEA context manager, that will reset the current enabled rules on exit.Nr[   )ra   rS   rT   rU   r&   rV   )r0   chain_rulesr^   rM   s       r2   reset_ruleszMarkdownIt.reset_rules   st      ++-'--/ 	4LE5	!U!!,,U3	4 	%%k)&<=s   0A<A	A<c                    | j                   j                  |k(  r3|j                  | j                         | j                   j                  |<   yy)ztAdd a rule for rendering a particular Token type.

        Only applied when ``renderer.__output__ == fmt``
        N)r)   
__output____get__rM   )r0   r?   functionfmts       r2   add_render_rulezMarkdownIt.add_render_rule   s>     ==##s*(0(8(8(GDMM% +r4   c                     || g|i | | S )ao  Load specified plugin with given params into current parser instance. (chainable)

        It's just a sugar to call `plugin(md, params)` with curring.

        Example::

            def func(tokens, idx):
                tokens[idx].content = tokens[idx].content.replace('foo', 'bar')
            md = MarkdownIt().use(plugin, 'foo_replace', 'text', func)

        r=   )r0   pluginparamsrI   s       r2   usezMarkdownIt.use   s     	t(f((r4   c                   |i n|}t        |t              st        dt        |             t        |t              st        dt        |             t        || |      }| j                  j                  |       |j                  S )a.  Parse the source string to a token stream

        :param src: source string
        :param env: environment sandbox

        Parse input string and return list of block tokens (special token type
        "inline" will contain list of inline tokens).

        `env` is used to pass data between "distributed" rules and return additional
        metadata like reference info, needed for the renderer. It also can be used to
        inject data in specific cases. Usually, you will be ok to pass `{}`,
        and then pass updated object to renderer.
        z+Input data should be a MutableMapping, not #Input data should be a string, not )	r-   r   r.   typerO   r   r(   processtokensr0   srcenvstates       r2   parsezMarkdownIt.parse   s{     KbS#~.I$s)UVV#s#A$s)MNN#tS)		% ||r4   c                |    |i n|}| j                   j                  | j                  ||      | j                  |      S )a}  Render markdown string into html. It does all magic for you :).

        :param src: source string
        :param env: environment sandbox
        :returns: The output of the loaded renderer

        `env` can be used to inject additional metadata (`{}` by default).
        But you will not need it with high probability. See also comment
        in [[MarkdownIt.parse]].
        )r)   renderr   rI   r0   r   r   s      r2   r   zMarkdownIt.render  s7     KbS}}##DJJsC$8$,,LLr4   c                    |i n|}t        |t              st        dt        |             t        |t              st        dt        |             t        || |      }d|_        | j                  j                  |       |j                  S )a=  The same as [[MarkdownIt.parse]] but skip all block rules.

        :param src: source string
        :param env: environment sandbox

        It returns the
        block tokens list with the single `inline` element, containing parsed inline
        tokens in `children` property. Also updates `env` object.
        z,Input data should be an MutableMapping, not r{   T)
r-   r   r.   r|   rO   r   
inlineModer(   r}   r~   r   s       r2   parseInlinezMarkdownIt.parseInline%  s     KbS#~.J4PS9+VWW#s#A$s)MNN#tS)		% ||r4   c                |    |i n|}| j                   j                  | j                  ||      | j                  |      S )a  Similar to [[MarkdownIt.render]] but for single paragraph content.

        :param src: source string
        :param env: environment sandbox

        Similar to [[MarkdownIt.render]] but for single paragraph content. Result
        will NOT be wrapped into `<p>` tags.
        )r)   r   r   rI   r   s      r2   renderInlinezMarkdownIt.renderInline9  s9     KbS}}##D$4$4S#$>cRRr4   c                ,    t        j                  |      S )a'  Validate if the URL link is allowed in output.

        This validator can prohibit more than really needed to prevent XSS.
        It's a tradeoff to keep code simple and to be secure by default.

        Note: the url should be normalized at this point, and existing entities decoded.
        )r   validateLinkr0   urls     r2   r   zMarkdownIt.validateLinkG  s     ))#..r4   c                ,    t        j                  |      S )zNormalize destination URLs in links

        ::

            [label]:   destination   'title'
                    ^^^^^^^^^^^
        )r   normalizeLinkr   s     r2   r   zMarkdownIt.normalizeLinkQ  s     **3//r4   c                ,    t        j                  |      S )zbNormalize autolink content

        ::

            <destination>
            ~~~~~~~~~~~
        )r   normalizeLinkText)r0   links     r2   r   zMarkdownIt.normalizeLinkText[  s     ..t44r4   )r   N)r1   str | PresetTyper%   Mapping[str, Any] | Noner#   z(Callable[[MarkdownIt], RendererProtocol])returnrO   )r?   zLiteral['inline']r   r   )r?   zLiteral['block']r   r   )r?   zLiteral['core']r   r   )r?   zLiteral['renderer']r   r   )r?   rO   r   r
   )rI   r   r   Noner<   )r   r   r%   r   r   r"   )r   zdict[str, list[str]])F)rf   zstr | Iterable[str]rg   boolr   r"   )r   zGenerator[None, None, None])html)r?   rO   rs   zCallable[..., Any]rt   rO   r   r   )rw   zCallable[..., None]rx   r
   rI   r
   r   r"   )r   rO   r   EnvType | Noner   zlist[Token])r   rO   r   r   r   r
   )r   rO   r   r   )r   rO   r   rO   )r   rO   r   rO   )r9   r8   __qualname__r   r3   r:   r   r@   rJ   r/   r\   ra   rd   rl   r	   ro   ru   ry   r   r   r   r   r   r   r   r=   r4   r2   r"   r"       s    $037 >
 BN >  > 1 >
 ? >DJ          , UY$'$9Q$	$L AF(9=	B AF(9=	. > > CIHH#5H<?H	H)47DG	".M(
S/05r4   r"   )0
__future__r   collections.abcr   r   r   r   r   
contextlibr	   typingr
   r   r    r   r   commonr   r   parser_blockr   parser_corer   parser_inliner   r)   r   r   rules_core.state_corer   tokenr   r   r   r   r   r*   ModuleNotFoundErrorr   make
js_defaultr   r   gfm_liker    __annotations__r"   r=   r4   r2   <module>r      s    " R R % ) )  ( % # ' 4 ,  @ @ ##%$$))+LL$$))+  %%'#
 C5 C5  Js   )C= =DD