
    !Sh:                       d 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
ddlmc mZ ddlmZ erddlmZ dXdZdZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 dZ	 edz   Z 	 dZ!	 e Z"	 e!Z#	 dZ$	 d Z%	 d!Z&	 d"Z'	 d#Z(	 d$Z)	 dYd'Z* G d( d)e	          Z+ G d* d+          Z, G d, d-e,          Z- G d. d/e,          Z. G d0 d1e-          Z/ G d2 d3e-          Z0 G d4 d5e,          Z1 G d6 d7e-          Z2 G d8 d9e1          Z3 G d: d;e2          Z4 G d< d=e-          Z5 G d> d?e1          Z6 G d@ dAe2          Z7 G dB dCe-          Z8 G dD dEe-          Z9 G dF dGe9          Z: G dH dIe-          Z; G dJ dKe;          Z< G dL dMe;          Z= G dN dOe=          Z> G dP dQe=          Z? G dR dSe?          Z@ G dT dUe-          ZA G dV dWe-          ZBdS )ZaB  
In version 3.0, a new, more flexible inline processor was added, [`markdown.inlinepatterns.InlineProcessor`][].   The
original inline patterns, which inherit from [`markdown.inlinepatterns.Pattern`][] or one of its children are still
supported, though users are encouraged to migrate.

The new `InlineProcessor` provides two major enhancements to `Patterns`:

1. Inline Processors no longer need to match the entire block, so regular expressions no longer need to start with
  `r'^(.*?)'` and end with `r'(.*?)%'`. This runs faster. The returned [`Match`][re.Match] object will only contain
   what is explicitly matched in the pattern, and extension pattern groups now start with `m.group(1)`.

2.  The `handleMatch` method now takes an additional input called `data`, which is the entire block under analysis,
    not just what is matched with the specified pattern. The method now returns the element *and* the indexes relative
    to `data` that the return element is replacing (usually `m.start(0)` and `m.end(0)`).  If the boundaries are
    returned as `None`, it is assumed that the match did not take place, and nothing will be altered in `data`.

    This allows handling of more complex constructs than regular expressions can handle, e.g., matching nested
    brackets, and explicit control of the span "consumed" by the processor.

    )annotations   )util)TYPE_CHECKINGAny
Collection
NamedTupleN)entities)Markdownmdr   kwargsr   returnutil.Registry[InlineProcessor]c                P   t          j                    }|                    t          t                    dd           |                    t          t          |           dd           |                    t          t          |           dd           |                    t          t          |           dd           |                    t          t          |           d	d
           |                    t          t          |           dd           |                    t          t          |           dd           |                    t!          t          |           dd           |                    t#          t$          |           dd           |                    t'          t(          |           dd           |                    t+          t,          d          dd           |                    t/          t0          |           dd           |                    t/          t2          |           dd           |                    t5          t6                    dd           |                    t9          d          dd            |                    t;          d!          d"d#           |S )$a  
    Build the default set of inline patterns for Markdown.

    The order in which processors and/or patterns are applied is very important - e.g. if we first replace
    `http://.../` links with `<a>` tags and _then_ try to replace inline HTML, we would end up with a mess. So, we
    apply the expressions in the following order:

    * backticks and escaped characters have to be handled before everything else so that we can preempt any markdown
      patterns by escaping them;

    * then we handle the various types of links (auto-links must be handled before inline HTML);

    * then we handle inline HTML.  At this point we will simply replace all inline HTML strings with a placeholder
      and add the actual HTML to a stash;

    * finally we apply strong, emphasis, etc.

    backtick   escape   	reference   link   
image_link   image_reference   short_reference   short_image_ref}   autolinkx   automailn   br	linebreakd   htmlZ   entityP   
not_strongF   z\*	em_strong<   _
em_strong22   )r   RegistryregisterBacktickInlineProcessorBACKTICK_REEscapeInlineProcessor	ESCAPE_REReferenceInlineProcessorREFERENCE_RELinkInlineProcessorLINK_REImageInlineProcessorIMAGE_LINK_REImageReferenceInlineProcessorIMAGE_REFERENCE_REShortReferenceInlineProcessor"ShortImageReferenceInlineProcessorAutolinkInlineProcessorAUTOLINK_REAutomailInlineProcessorAUTOMAIL_RESubstituteTagInlineProcessorLINE_BREAK_REHtmlInlineProcessorHTML_RE	ENTITY_RESimpleTextInlineProcessorNOT_STRONG_REAsteriskProcessorUnderscoreProcessor)r   r   inlinePatternss      ]/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/markdown/inlinepatterns.pybuild_inlinepatternsrR   5   sb   & ]__N3K@@*cRRR1)R@@(CPPP4\2FFUXYYY/<<fcJJJ0CC\SVWWW%&8"==?PRU   %lB779JC   *+=rBBDUWZ   3KDDjRUVVV3KDDjRUVVV8MM{\_```/<<fbIII/	2>>"MMM5mDDlTVWWW-e44k2FFF/55|RHHH    z(?<!\!)z;(?:(?<!\\)((?:\\{2})+)(?=`+)|(?<!\\)(`+)(.+?)(?<!`)\2(?!`))z\\(.)z(\*)([^\*]+)\1z(\*{2})(.+?)\1z%(?<!\w)(_{2})(?!_)(.+?)(?<!_)\1(?!\w)z"(?<!\w)(_)(?!_)(.+?)(?<!_)\1(?!\w)z7(?<!\w)(\_)\1(?!\1)(.+?)(?<!\w)\1(?!\1)(.+?)\1{3}(?!\w)z(\*)\1{2}(.+?)\1(.*?)\1{2}z(_)\1{2}(.+?)\1(.*?)\1{2}z(\*)\1{2}(.+?)\1{2}(.*?)\1z(_)\1{2}(.+?)\1{2}(.*?)\1z&(\*)\1(?!\1)([^*]+?)\1(?!\1)(.+?)\1{3}z\[z\!\[z%((^|(?<=\s))(\*{1,3}|_{1,3})(?=\s|$))z+<((?:[Ff]|[Hh][Tt])[Tt][Pp][Ss]?://[^<>]*)>z<([^<> !]+@[^@<> ]+)>z(<(\/?[a-zA-Z][^<>@ ]*( [^<>]*)?|!--(?:(?!<!--|-->).)*--|[?](?:(?!<[?]|[?]>).)*[?]|!\[CDATA\[(?:(?!<!\[CDATA\[|\]\]>).)*\]\])>)z-(&(?:\#[0-9]+|\#x[0-9a-fA-F]+|[a-zA-Z0-9]+);)z  \nstringstrc                    |                      d          r|                     d          s*|                      d          r|                     d          r
| dd         S | S )z#Remove quotes from around a string."'r   )
startswithendswith)rT   s    rQ   dequoter\      sh    			3		 FOOC$8$8 ##)??3#7#7ad|rS   c                  2    e Zd ZU dZded<   ded<   ded<   dS )EmStrongItemzEmphasis/strong pattern item.re.Pattern[str]patternrU   buildertagsN)__name__
__module____qualname____doc____annotations__ rS   rQ   r^   r^      s4         ''LLLIIIIIrS   r^   c                  r    e Zd ZU dZ e            Zded<   	 ded<   ded<   dddZddZddZ	ddZ
ddZdS )Patterna  
    Base class that inline patterns subclass.

    Inline patterns are handled by means of `Pattern` subclasses, one per regular expression.
    Each pattern object uses a single regular expression and must support the following methods:
    [`getCompiledRegExp`][markdown.inlinepatterns.Pattern.getCompiledRegExp] and
    [`handleMatch`][markdown.inlinepatterns.Pattern.handleMatch].

    All the regular expressions used by `Pattern` subclasses must capture the whole block.  For this
    reason, they all start with `^(.*)` and end with `(.*)!`.  When passing a regular expression on
    class initialization, the `^(.*)` and `(.*)!` are added automatically and the regular expression
    is pre-compiled.

    It is strongly suggested that the newer style [`markdown.inlinepatterns.InlineProcessor`][] that
    use a more efficient and flexible search approach be used instead. However, the older style
    `Pattern` remains for backward compatibility with many existing third-party extensions.

    zCollection[str]ANCESTOR_EXCLUDESr_   compiled_reMarkdown | Noner   Nr`   rU   c                    || _         t          j        d|z  t          j        t          j        z            | _        || _        dS )a!  
        Create an instant of an inline pattern.

        Arguments:
            pattern: A regular expression that matches a pattern.
            md: An optional pointer to the instance of `markdown.Markdown` and is available as
                `self.md` on the class instance.


        z^(.*?)%s(.*)$N)r`   recompileDOTALLUNICODErl   r   selfr`   r   s      rQ   __init__zPattern.__init__   s@     :&6&@&(i"*&<> > rS   r   
re.Patternc                    | j         S )z' Return a compiled regular expression. )rl   rt   s    rQ   getCompiledRegExpzPattern.getCompiledRegExp   s    rS   mre.Match[str]etree.Element | strc                    dS )zReturn a ElementTree element from the given match.

        Subclasses should override this method.

        Arguments:
            m: A match object containing a match of the pattern.

        Returns: An ElementTree Element object.

        Nrh   rt   rz   s     rQ   handleMatchzPattern.handleMatch   s	     	rS   c                    | j         j        S )z+ Return class name, to define pattern type )	__class__rc   rx   s    rQ   typezPattern.type  s    ~&&rS   textc                    	 | j         j        d         j        n# t          $ r |cY S w xY wfd}t          j                            ||          S )> Return unescaped text given text with an inline placeholder. inlinec                    |                      d          }|v rS                    |          }t          |t                    r|S d                    |                                          S d S )Nr    )groupget
isinstancerU   joinitertext)rz   idvaluestashs      rQ   	get_stashz#Pattern.unescape.<locals>.get_stash  sf    BU{{		"eS)) 5 L 775>>#3#3444 {rS   r   treeprocessorsstashed_nodesKeyErrorr   INLINE_PLACEHOLDER_REsubrt   r   r   r   s      @rQ   unescapezPattern.unescape  st    	G*84BEE 	 	 	KKK		5 	5 	5 	5 	5 )--i>>>s    **Nr`   rU   r   rm   )r   rv   )rz   r{   r   r|   )r   rU   r   rU   r   rU   )rc   rd   re   rf   tuplerk   rg   ru   ry   r   r   r   rh   rS   rQ   rj   rj      s          & */0000
 !       "          ' ' ' '? ? ? ? ? ?rS   rj   c                  $    e Zd ZdZdddZddZdS )InlineProcessorz
    Base class that inline processors subclass.

    This is the newer style inline processor that uses a more
    efficient and flexible search approach.

    Nr`   rU   r   rm   c                    || _         t          j        |t          j        t          j        z            | _        d| _        || _        dS )a"  
        Create an instant of an inline processor.

        Arguments:
            pattern: A regular expression that matches a pattern.
            md: An optional pointer to the instance of `markdown.Markdown` and is available as
                `self.md` on the class instance.

        FN)r`   ro   rp   rq   rr   rl   	safe_moder   rs   s      rQ   ru   zInlineProcessor.__init__$  s<     :gry2:/EFF rS   rz   r{   datar   9tuple[etree.Element | str | None, int | None, int | None]c                    dS )a  Return a ElementTree element from the given match and the
        start and end index of the matched text.

        If `start` and/or `end` are returned as `None`, it will be
        assumed that the processor did not find a valid region of text.

        Subclasses should override this method.

        Arguments:
            m: A re match object containing a match of the pattern.
            data: The buffer currently under analysis.

        Returns:
            el: The ElementTree element, text or None.
            start: The start of the region that has been matched or None.
            end: The end of the region that has been matched or None.

        Nrh   rt   rz   r   s      rQ   r   zInlineProcessor.handleMatch5  s	    & 	rS   r   r   )rz   r{   r   rU   r   r   rc   rd   re   rf   ru   r   rh   rS   rQ   r   r     sK             "     rS   r   c                      e Zd ZdZddZdS )	SimpleTextPatternz2 Return a simple text of `group(2)` of a Pattern. rz   r{   r   rU   c                ,    |                     d          S )z< Return string content of `group(2)` of a matching pattern.    )r   r~   s     rQ   r   zSimpleTextPattern.handleMatchM  s    wwqzzrS   Nrz   r{   r   rU   rc   rd   re   rf   r   rh   rS   rQ   r   r   K  s.        <<     rS   r   c                      e Zd ZdZd
dZd	S )rL   z2 Return a simple text of `group(1)` of a Pattern. rz   r{   r   rU   r   tuple[str, int, int]c                ~    |                     d          |                    d          |                    d          fS )z< Return string content of `group(1)` of a matching pattern. r   r   )r   startendr   s      rQ   r   z%SimpleTextInlineProcessor.handleMatchT  s-    wwqzz1771::quuQxx//rS   Nrz   r{   r   rU   r   r   r   rh   rS   rQ   rL   rL   R  s.        <<0 0 0 0 0 0rS   rL   c                      e Zd ZdZd
dZd	S )r7   z Return an escaped character. rz   r{   r   rU   r   tuple[str | None, int, int]c                `   |                     d          }|| j        j        v rad                    t          j        t          |          t          j                  |                    d          |	                    d          fS d|                    d          |	                    d          fS )a  
        If the character matched by `group(1)` of a pattern is in [`ESCAPED_CHARS`][markdown.Markdown.ESCAPED_CHARS]
        then return the integer representing the character's Unicode code point (as returned by [`ord`][]) wrapped
        in [`util.STX`][markdown.util.STX] and [`util.ETX`][markdown.util.ETX].

        If the matched character is not in [`ESCAPED_CHARS`][markdown.Markdown.ESCAPED_CHARS], then return `None`.
        r   {}{}{}r   N)
r   r   ESCAPED_CHARSformatr   STXordETXr   r   )rt   rz   r   chars       rQ   r   z!EscapeInlineProcessor.handleMatch\  s     wwqzz47(((??48SYYAA1771::quuUVxxWWQUU1XX--rS   N)rz   r{   r   rU   r   r   r   rh   rS   rQ   r7   r7   Y  s.        ((. . . . . .rS   r7   c                  "    e Zd ZdZddZdd
ZdS )SimpleTagPatternz]
    Return element of type `tag` with a text attribute of `group(3)`
    of a Pattern.

    r`   rU   tagc                J    t                               | |           || _        dS )z
        Create an instant of an simple tag pattern.

        Arguments:
            pattern: A regular expression that matches a pattern.
            tag: Tag of element.

        N)rj   ru   r   rt   r`   r   s      rQ   ru   zSimpleTagPattern.__init__r  s'     	w'''00rS   rz   r{   r   etree.Elementc                l    t          j        | j                  }|                    d          |_        |S )z
        Return [`Element`][xml.etree.ElementTree.Element] of type `tag` with the string in `group(3)` of a
        matching pattern as the Element's text.
           )etreeElementr   r   r   )rt   rz   els      rQ   r   zSimpleTagPattern.handleMatch  s+    
 ]48$$''!**	rS   Nr`   rU   r   rU   rz   r{   r   r   r   rh   rS   rQ   r   r   l  sF         
1 1 1 1     rS   r   c                  "    e Zd ZdZddZddZdS )SimpleTagInlineProcessorz]
    Return element of type `tag` with a text attribute of `group(2)`
    of a Pattern.

    r`   rU   r   c                J    t                               | |           || _        dS )z
        Create an instant of an simple tag processor.

        Arguments:
            pattern: A regular expression that matches a pattern.
            tag: Tag of element.

        N)r   ru   r   r   s      rQ   ru   z!SimpleTagInlineProcessor.__init__  s'     	  w///00rS   rz   r{   r   r   tuple[etree.Element, int, int]c                    t          j        | j                  }|                    d          |_        ||                    d          |                    d          fS )z
        Return [`Element`][xml.etree.ElementTree.Element] of type `tag` with the string in `group(2)` of a
        matching pattern as the Element's text.
        r   r   )r   r   r   r   r   r   r   rt   rz   r   r   s       rQ   r   z$SimpleTagInlineProcessor.handleMatch  sG    
 ]48$$''!**1771::quuQxx''rS   Nr   rz   r{   r   rU   r   r   r   rh   rS   rQ   r   r     sF         
1 1 1 1( ( ( ( ( (rS   r   c                      e Zd ZdZddZdS )	SubstituteTagPattern3 Return an element of type `tag` with no children. rz   r{   r   r   c                4    t          j        | j                  S )H Return empty [`Element`][xml.etree.ElementTree.Element] of type `tag`. )r   r   r   r~   s     rQ   r   z SubstituteTagPattern.handleMatch  s    }TX&&&rS   Nr   r   rh   rS   rQ   r   r     s.        ==' ' ' ' ' 'rS   r   c                      e Zd ZdZd
dZd	S )rG   r   rz   r{   r   rU   r   r   c                    t          j        | j                  |                    d          |                    d          fS )r   r   )r   r   r   r   r   r   s      rQ   r   z(SubstituteTagInlineProcessor.handleMatch  s/    }TX&&

AEE!HH<<rS   Nr   r   rh   rS   rQ   rG   rG     s.        === = = = = =rS   rG   c                  "    e Zd ZdZddZdd
ZdS )r5   zA Return a `<code>` element containing the escaped matching text. r`   rU   c                    t                               | |           d                    t          j        t          d          t          j                  | _        d| _        d S )Nr   \code)	r   ru   r   r   r   r   r   ESCAPED_BSLASHr   )rt   r`   s     rQ   ru   z BacktickInlineProcessor.__init__  sG      w///&oodhD		48LL00rS   rz   r{   r   r   $tuple[etree.Element | str, int, int]c                   |                     d          rt          j        | j                  }t	          j        t	          j        |                     d                                                              |_        ||	                    d          |
                    d          fS |                     d                              d| j                  |	                    d          |
                    d          fS )a  
        If the match contains `group(3)` of a pattern, then return a `code`
        [`Element`][xml.etree.ElementTree.Element] which contains HTML escaped text (with
        [`code_escape`][markdown.util.code_escape]) as an [`AtomicString`][markdown.util.AtomicString].

        If the match does not contain `group(3)` then return the text of `group(1)` backslash escaped.

        r   r   r   z\\)r   r   r   r   r   AtomicStringcode_escapestripr   r   r   replacer   r   s       rQ   r   z#BacktickInlineProcessor.handleMatch  s     771:: 	Ytx((B'(89I9I9K9K(L(LMMBGqwwqzz15588++771::%%fd.ABBAGGAJJPQPUPUVWPXPXXXrS   N)r`   rU   )rz   r{   r   rU   r   r   r   rh   rS   rQ   r5   r5     sH        KK1 1 1 1Y Y Y Y Y YrS   r5   c                      e Zd ZdZddZdS )	DoubleTagPatternfReturn a ElementTree element nested in tag2 nested in tag1.

    Useful for strong emphasis etc.

    rz   r{   r   r   c                D   | j                             d          \  }}t          j        |          }t          j        ||          }|                    d          |_        t          |                                          dk    r|                    d          |_	        |S )z
        Return [`Element`][xml.etree.ElementTree.Element] in following format:
        `<tag1><tag2>group(3)</tag2>group(4)</tag2>` where `group(4)` is optional.

        ,r         )
r   splitr   r   
SubElementr   r   lengroupstail)rt   rz   tag1tag2el1el2s         rQ   r   zDoubleTagPattern.handleMatch  s|     X^^C((
dmD!!sD))771::qxxzz??awwqzzCH
rS   Nr   r   rh   rS   rQ   r   r     s2         
     rS   r   c                      e Zd ZdZd
dZd	S )DoubleTagInlineProcessorr   rz   r{   r   rU   r   r   c                   | j                             d          \  }}t          j        |          }t          j        ||          }|                    d          |_        t          |                                          dk    r|                    d          |_	        ||
                    d          |                    d          fS )z
        Return [`Element`][xml.etree.ElementTree.Element] in following format:
        `<tag1><tag2>group(2)</tag2>group(3)</tag2>` where `group(3)` is optional.

        r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   )rt   rz   r   r   r   r   r   s          rQ   r   z$DoubleTagInlineProcessor.handleMatch  s     X^^C((
dmD!!sD))771::qxxzz??awwqzzCHAGGAJJa((rS   Nr   r   rh   rS   rQ   r   r     s2         
) ) ) ) ) )rS   r   c                  *    e Zd ZdZddZdd
ZddZdS )rI   z1 Store raw inline html and return a placeholder. rz   r{   r   rU   r   r   c                   |                      |                     |                    d                              }| j        j                            |          }||                    d          |                    d          fS )zL Store the text of `group(1)` of a pattern and return a placeholder string. r   r   )backslash_unescaper   r   r   	htmlStashstorer   r   )rt   rz   r   rawhtmlplace_holders        rQ   r   zHtmlInlineProcessor.handleMatch  sd    ))$--

*C*CDDw(..w77QWWQZZq11rS   r   c                     	  j         j        d         j        n# t          $ r |cY S w xY wd fd}t          j                            ||          S )r   r   rz   r{   r   rU   c                    |                      d          }                    |          }|0	 j                            |          S # t          $ r d|z  cY S w xY wd S )Nr   z\%s)r   r   r   
serializer	Exception)rz   r   r   rt   r   s      rQ   r   z/HtmlInlineProcessor.unescape.<locals>.get_stash  su    BIIbMME *7--e444  * * *!E>)))* ! s   A	 	AAr   r   r   s   `  @rQ   r   zHtmlInlineProcessor.unescape  s    	G*84BEE 	 	 	KKK		* 	* 	* 	* 	* 	* 	* )--i>>>s    ++c                    	 | j         j        d         j        }n# t          $ r |cY S w xY wdd}|                    ||          S )zG Return text with backslash escapes undone (backslashes are restored). r   rz   r{   r   rU   c                `    t          t          |                     d                              S )Nr   )chrintr   )rz   s    rQ   	_unescapez9HtmlInlineProcessor.backslash_unescape.<locals>._unescape  s     s1771::'''rS   r   )r   r   REr   r   )rt   r   r  r  s       rQ   r   z&HtmlInlineProcessor.backslash_unescape  si    	'
36BB 	 	 	KKK		( 	( 	( 	( vvi&&&s    ))Nr   r   )rc   rd   re   rf   r   r   r   rh   rS   rQ   rI   rI     sV        ;;2 2 2 2? ? ? ?$
' 
' 
' 
' 
' 
'rS   rI   c                     e Zd ZdZ e ej        eej        ej	        z            dd           e ej        e
ej        ej	        z            dd           e ej        eej        ej	        z            dd           e ej        eej        ej	        z            dd           e ej        eej        ej	        z            dd          gZ	 d!dZd"dZd"dZd#dZd$dZd%dZd S )&rN   zGEmphasis processor for handling strong and em matches inside asterisks.double	strong,em	em,strongdouble2singlestrongemrz   r{   r   rU   idxr  r   r   c                    t          j        |          }|                    d          }|                     ||d|           |S )zReturn single tag.r   N)r   r   r   parse_sub_patterns)rt   rz   r   r  r   r   s         rQ   build_singlezAsteriskProcessor.build_single*  s?    mC  wwqzzc4555
rS   rb   c                   |                     d          \  }}t          j        |          }t          j        |          }|                    d          }|                     ||d|           |                    |           t          |                                          dk    r-|                    d          }|                     ||||           |S )zReturn double tag.r   r   Nr   )r   r   r   r   r  appendr   r   	rt   rz   rb   r  r   r   r   r   r   s	            rQ   build_doublezAsteriskProcessor.build_double1  s     ZZ__
dmD!!mD!!wwqzzc4555

3qxxzz??a771::D##D#sC888
rS   c                d   |                     d          \  }}t          j        |          }t          j        |          }|                    d          }|                     ||d|           |                    d          }|                    |           |                     ||d|           |S )zFReturn double tags (variant 2): `<strong>text <em>text</em></strong>`.r   r   Nr   )r   r   r   r   r  r  r  s	            rQ   build_double2zAsteriskProcessor.build_double2?  s     ZZ__
dmD!!mD!!wwqzzc4555wwqzz

3c4555
rS   r   parentlastetree.Element | NoneNonec                X   d}d}t          |          }||k     r| j                            ||          rd}t          | j                  D ]\  }	}
|	|k    r|
j                            ||          }|r|||                    d                   }|r|||_        n||_        | 	                    ||
j
        |
j        |	          }|                    |           |}|                    d          x}}d}|s|dz  }n|dz  }||k     ||d         }|r|	||_        dS ||_        dS dS )a/  
        Parses sub patterns.

        `data`: text to evaluate.

        `parent`: Parent to attach text and sub elements to.

        `last`: Last appended child to parent. Can also be None if parent has no children.

        `idx`: Current pattern index that was used to evaluate the parent.
        r   FNTr   )r   rl   match	enumeratePATTERNSr`   r   r   r   build_elementra   rb   r  r   )rt   r   r  r  r  offsetposlengthmatchedindexitemrz   r   r   s                 rQ   r  z$AsteriskProcessor.parse_sub_patternsL  sx    TFll%%dC00 #,T]#;#; ' 'KE4|| **455A '
  $F1771::$56 3#/,0		.2!//4<ERRb)))!'(uuQxx/"& 1HC qA FllF FGG} 	# 			"		# 	#rS   ra   r&  c                    |dk    r|                      |||          S |dk    r|                     |||          S |                     |||          S )zElement builder.r  r  )r  r  r  )rt   rz   ra   rb   r&  s        rQ   r!  zAsteriskProcessor.build_element  sb     i%%au555  $$Qe444$$Qe444rS   3tuple[etree.Element | None, int | None, int | None]c                H   d}d}d}t          | j                  D ]\  }}|j                            ||                    d                    }|rN|                    d          }|                    d          }|                     ||j        |j        |          } n|||fS )zParse patterns.Nr   )	r  r   r`   r  r   r   r!  ra   rb   )	rt   rz   r   r   r   r   r&  r'  m1s	            rQ   r   zAsteriskProcessor.handleMatch  s     $T]33 	 	KE4##D!''!**55B ffQii''DL$)UKK	
 5#~rS   N)rz   r{   r   rU   r  r  r   r   )rz   r{   rb   rU   r  r  r   r   )
r   rU   r  r   r  r  r  r  r   r  )
rz   r{   ra   rU   rb   rU   r&  r  r   r   rz   r{   r   rU   r   r)  )rc   rd   re   rf   r^   ro   rp   EM_STRONG_RErq   rr   STRONG_EM_RESTRONG_EM3_RE	STRONG_REEMPHASIS_REr   r  r  r  r  r!  r   rh   rS   rQ   rN   rN     sn       QQ 	ZRZbi"*.DEExQ\]]ZRZbi"*.DEExQ\]]ZRZry2:/EFF	S^__ZRZ	29rz+ABBHhWWZRZRY-CDDhPTUUH P         ;# ;# ;# ;#z5 5 5 5     rS   rN   c                     e Zd ZdZ e ej        eej        ej	        z            dd           e ej        e
ej        ej	        z            dd           e ej        eej        ej	        z            dd           e ej        eej        ej	        z            dd           e ej        eej        ej	        z            dd          gZd	S )
rO   zIEmphasis processor for handling strong and em matches inside underscores.r  r	  r
  r  r  r  r  N)rc   rd   re   rf   r^   ro   rp   EM_STRONG2_RErq   rr   STRONG_EM2_RESMART_STRONG_EM_RESMART_STRONG_RESMART_EMPHASIS_REr   rh   rS   rQ   rO   rO     s        SS 	ZRZry2:/EFFR]^^ZRZry2:/EFFR]^^ZRZ 2BI
4JKKYXcddZRZRZ1GHH(T\]]ZRZ 129rz3IJJHVZ[[H POrS   rO   c                      e Zd ZdZ ej        dej        ej        z            Z ej        d          Z	dd
Z
ddZddZdS )r;   z- Return a link element from the given match. z2\(\s*(?:(<[^<>]*>)\s*(?:('[^']*'|"[^"]*")\s*)?\))?z\srz   r{   r   rU   r   r)  c                d   |                      ||                    d                    \  }}}|sdS |                     ||          \  }}}}|sdS t          j        d          }||_        |                    d|           ||                    d|           ||                    d          |fS )zS Return an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. r   NNNahrefNtitle)getTextr   getLinkr   r   r   setr   )	rt   rz   r   r   r&  handledr<  r=  r   s	            rQ   r   zLinkInlineProcessor.handleMatch  s    #||D!%%((;;eW 	$##&*ll4&?&?#eUG 	$##]3
vtFF7E"""1771::u$$rS   r&  r  !tuple[str, str | None, int, bool]c           	        d}d}d}| j                             ||          }|r|                    d          rz|                    d          dd                                         }|                    d          r|                    d          dd         }|                    d          }d	}n|rd}d}|                                }	|	}d}
d}d}d}d}d}d}d}d}t          |t          |                    D ]8}||         }|d
k    r|s|dz  }n|dk    r|dz  }n}|dk    r:|dk    r||k    s|dk    r	||k    rd}n\|s|dz  }nT|dk    r|dz  }|dk    r|dz   }
n=|dv r9|sd	}|}d}|dz   }|}n)||k    r
|s|dz   }|}n||k    r|dz   }n|r||k    r|dz   }|dz  }|dk    r|dk    r4||k    r.||	|dz
           }d                    |||dz
                     }nG|dk    r4||k    r.||	|dz
           }d                    |||dz
                     }n||	|dz
           } n
|dk    r|}:|dk    r|dk    r||	|
dz
           }|
}d}|dk    }|M| j        	                    dt          |                     |                                                              }|                     |                                          }||||fS )z?Parse data between `()` of `[Text]()` allowing recursive `()`. r   NFr#  r   rY   r   r   T())rX   rW    )RE_LINKr  r   r   r   ranger   r   RE_TITLE_CLEANr   r\   r   )rt   r   r&  r<  r=  rA  rz   bracket_countbacktrack_countstart_indexlast_bracketquotestart_quote
exit_quoteignore_matches	alt_quotestart_alt_quoteexit_alt_quoter  r#  cs                        rQ   r?  zLinkInlineProcessor.getLink  s     Lt// c	) c	)771::ad#))++Dwwqzz )

1R4(EE!HHEGG \	)MO%%''KEL !%EKJ"N I ON DUCII.. ; ;I88 * -%*(1,,'1,#XX $r))etmmSUAUAUZcgkZkZk()+ 5%*(1,,'1,*a//+019L*__  3 *.*7()&+ai !eI*/!)$%		e%*QY

" 3qI~~).
 !A%%!Q5D==#Ka$?@ "[a-G(H I I'1,,d1B1B#K!0C$CD "_^a=O-O(P Q Q#K	$9:E88D !!o&:&:Kq(889$ !#q(G'++Cu{{}}9U9U1V1VWWE}}T""((**UE7**rS   tuple[str, int, bool]c                   d}g }t          |t          |                    D ]C}||         }|dk    r|dz  }n|dk    r|dz  }|dz  }|dk    r n|                    |           Dd                    |          ||dk    fS )zsParse the content between `[]` of the start of an image or link
        resolving nested square brackets.

        r   ][r   r   )rI  r   r  r   )rt   r   r&  rK  r   r#  rV  s          rQ   r>  zLinkInlineProcessor.getText?  s    
 D		** 		 		CS	ACxx"c"QJE!!KKNNNNwwt}}e]a%777rS   Nr,  )r   rU   r&  r  r   rB  )r   rU   r&  r  r   rW  )rc   rd   re   rf   ro   rp   rq   rr   rH  rJ  r   r?  r>  rh   rS   rQ   r;   r;     s        77bjRTVT]`b`jTjkkGRZ&&N% % % %*r+ r+ r+ r+h8 8 8 8 8 8rS   r;   c                      e Zd ZdZd
dZd	S )r=   z. Return a `img` element from the given match. rz   r{   r   rU   r   r)  c                   |                      ||                    d                    \  }}}|sdS |                     ||          \  }}}}|sdS t          j        d          }|                    d|           ||                    d|           |                    d|                     |                     ||                    d          |fS )zU Return an `img` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. r   r:  imgsrcNr=  alt)r>  r   r?  r   r   r@  r   r   )	rt   rz   r   r   r&  rA  r^  r=  r   s	            rQ   r   z ImageInlineProcessor.handleMatchV  s    #||D!%%((;;eW 	$##%)\\$%>%>"UE7 	$##]5!!
ucFF7E"""
udmmD))***1771::u$$rS   Nr,  r   rh   rS   rQ   r=   r=   S  s.        88% % % % % %rS   r=   c                      e Zd ZdZ ej        dej                  Z ej        dej        ej	        z            Z
dd
ZddZddZdS )r9   z6 Match to a stored reference and return link element. z\s+z\s?\[([^\]]*)\]rz   r{   r   rU   r   r)  c                   |                      ||                    d                    \  }}}|sdS |                     |||          \  }}}|sdS | j                            d|          }|| j        j        vrd|                    d          |fS | j        j        |         \  }}	|                     ||	|          |                    d          |fS )zz
        Return [`Element`][xml.etree.ElementTree.Element] returned by `makeTag` method or `(None, None, None)`.

        r   r:  rG  N)	r>  r   evalIdNEWLINE_CLEANUP_REr   r   
referencesr   makeTag)
rt   rz   r   r   r&  rA  r   r   r<  r=  s
             rQ   r   z$ReferenceInlineProcessor.handleMatchq  s    
  $||D!%%((;;eW 	$##;;tUD99C 	$## $((b11TW'''S((g(,e||D%..

C??rS   r&  r  r   tuple[str | None, int, bool]c                    | j                             ||          }|sd|dfS |                    d                                          }|                    d          }|s|                                }||dfS )z\
        Evaluate the id portion of `[ref][id]`.

        If `[ref][]` use `[ref]`.
        rD  NFr   r   T)rH  r  r   lowerr   )rt   r   r&  r   rz   r   r   s          rQ   rb  zReferenceInlineProcessor.evalId  s~     Lt// 	"%%!!##B%%((C "ZZ\\3}rS   r<  r=  r   c                    t          j        d          }|                    d|           |r|                    d|           ||_        |S )z; Return an `a` [`Element`][xml.etree.ElementTree.Element]. r;  r<  r=  )r   r   r@  r   rt   r<  r=  r   r   s        rQ   re  z ReferenceInlineProcessor.makeTag  sM    ]3
vt 	#FF7E"""	rS   Nr,  )r   rU   r&  r  r   rU   r   rf  r<  rU   r=  rU   r   rU   r   r   )rc   rd   re   rf   ro   rp   	MULTILINErc  rq   rr   rH  r   rb  re  rh   rS   rQ   r9   r9   k  s        @@#FBL99bj+RY-CDDG@ @ @ @,    	 	 	 	 	 	rS   r9   c                      e Zd ZdZdd	Zd
S )rA   z%Short form of reference: `[google]`. r   rU   r&  r  r   r   rW  c                0    |                                 |dfS zEvaluate the id of `[ref]`.  Trh  rt   r   r&  r   s       rQ   rb  z$ShortReferenceInlineProcessor.evalId       zz||UD((rS   Nr   rU   r&  r  r   rU   r   rW  rc   rd   re   rf   rb  rh   rS   rQ   rA   rA     s.        //) ) ) ) ) )rS   rA   c                      e Zd ZdZd
dZd	S )r?   z7 Match to a stored reference and return `img` element. r<  rU   r=  r   r   r   c                    t          j        d          }|                    d|           |r|                    d|           |                    d|                     |                     |S )z= Return an `img` [`Element`][xml.etree.ElementTree.Element]. r]  r^  r=  r_  )r   r   r@  r   rj  s        rQ   re  z%ImageReferenceInlineProcessor.makeTag  sf    ]5!!
ud 	#FF7E"""
udmmD))***	rS   Nrk  )rc   rd   re   rf   re  rh   rS   rQ   r?   r?     s.        AA     rS   r?   c                      e Zd ZdZdd	Zd
S )rB   z* Short form of image reference: `![ref]`. r   rU   r&  r  r   r   rW  c                0    |                                 |dfS ro  rp  rq  s       rQ   rb  z)ShortImageReferenceInlineProcessor.evalId  rr  rS   Nrs  rt  rh   rS   rQ   rB   rB     s.        44) ) ) ) ) )rS   rB   c                      e Zd ZdZd
dZd	S )rC   zD Return a link Element given an auto-link (`<http://example/com>`). rz   r{   r   rU   r   r   c                P   t          j        d          }|                    d|                     |                    d                               t          j        |                    d                    |_        ||                    d          |	                    d          fS )zI Return an `a` [`Element`][xml.etree.ElementTree.Element] of `group(1)`. r;  r<  r   r   )
r   r   r@  r   r   r   r   r   r   r   r   s       rQ   r   z#AutolinkInlineProcessor.handleMatch  sx    ]3
vt}}QWWQZZ00111#AGGAJJ//1771::quuQxx''rS   Nr   r   rh   rS   rQ   rC   rC     s.        NN( ( ( ( ( (rS   rC   c                      e Zd ZdZd
dZd	S )rE   zW
    Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`).
    rz   r{   r   rU   r   r   c                   t          j        d          }|                     |                    d                    }|                    d          r|t          d          d         }dd	fd
|D             }t          j        d                    |                    |_	        d|z   }d                    d |D                       }|
                    d|           ||                    d          |                    d          fS )za Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link  of `group(1)`. r;  r   zmailto:Nr   r  r   rU   c                    t           j                            |           }|r d                    t          j        |          S dt          j        | fz  S )z=Return entity definition by code, or the code if not defined.z{}{};z%s#%d;)r
   codepoint2namer   r   r   AMP_SUBSTITUTE)r   r*   s     rQ   r~  z;AutomailInlineProcessor.handleMatch.<locals>.codepoint2name  sJ    ,0066F >~~d&96BBB4#6"===rS   c                @    g | ]} t          |                    S rh   )r   ).0letterr~  s     rQ   
<listcomp>z7AutomailInlineProcessor.handleMatch.<locals>.<listcomp>  s)    CCC6>>#f++..CCCrS   r   c                L    g | ]!}t           j        d t          |          z  z   "S )z#%d;)r   r  r   )r  r  s     rQ   r  z7AutomailInlineProcessor.handleMatch.<locals>.<listcomp>  s@     < < <*0 -f++1& & < < <rS   r<  r   )r   r  r   rU   )r   r   r   r   rZ   r   r   r   r   r   r@  r   r   )rt   rz   r   r   emaillettersmailtor~  s          @rQ   r   z#AutomailInlineProcessor.handleMatch  s   ]3aggajj))I&& 	+#i..//*E	> 	> 	> 	> DCCCUCCC#BGGG$4$455U" < <4:< < < = =
vv1771::quuQxx''rS   Nr   r   rh   rS   rQ   rE   rE     s2         ( ( ( ( ( (rS   rE   )r   r   r   r   r   r   )rT   rU   r   rU   )Crf   
__future__r   r   r   typingr   r   r   r	   ro   xml.etree.ElementTreer   ElementTreer(   r
   markdownr   rR   NOIMGr6   r8   r1  r0  r6  r7  r5  r-  r3  r.  r4  r/  r<   r>   r:   r@   rM   rD   rF   rJ   rK   rH   r\   r^   rj   r   r   rL   r7   r   r   r   rG   r5   r   r   rI   rN   rO   r;   r=   r9   rA   r?   rB   rC   rE   rh   rS   rQ   <module>r     s  ( * # " " " " "       = = = = = = = = = = = = 				 % % % % % % % % %       "!!!!!!* * * *` 	 \L M	 = 7	 5: b9  cO  B, S, V, ?, B9 ?
%- ` S 5"  :8 '< =& ;
  %<	 V (       :   S? S? S? S? S? S? S? S?l- - - - -g - - -`       0 0 0 0 0 0 0 0. . . . .O . . .&    w   :( ( ( ( ( ( ( (:' ' ' ' '+ ' ' '= = = = =#; = = =Y Y Y Y Yo Y Y Y2    '   *) ) ) ) )7 ) ) )*$' $' $' $' $'/ $' $' $'NC C C C C C C CL
P 
P 
P 
P 
P+ 
P 
P 
P_8 _8 _8 _8 _8/ _8 _8 _8D% % % % %. % % %05 5 5 5 52 5 5 5p) ) ) ) )$< ) ) )	 	 	 	 	$< 	 	 	) ) ) ) ))F ) ) )( ( ( ( (o ( ( (( ( ( ( (o ( ( ( ( (rS   