+
    f0i                    :   R t ^ RIHt ^RIHt ^ RIHtHtHtH	t	 ^ RI
t
^ RIHu Ht ^ RIHt ]'       d   ^ RIHt R R ltR	t R
t Rt Rt Rt Rt Rt Rt Rt Rt Rt Rt Rt ]R,           t  Rt! ] t" ]!t# Rt$ Rt% Rt& Rt' Rt( Rt) R R lt* ! R  R!]	4      t+ ! R" R#4      t, ! R$ R%],4      t- ! R& R'],4      t. ! R( R)]-4      t/ ! R* R+]-4      t0 ! R, R-],4      t1 ! R. R/]-4      t2 ! R0 R1]14      t3 ! R2 R3]24      t4 ! R4 R5]-4      t5 ! R6 R7]14      t6 ! R8 R9]24      t7 ! R: R;]-4      t8 ! R< R=]-4      t9 ! R> R?]94      t: ! R@ RA]-4      t; ! RB RC];4      t< ! RD RE];4      t= ! RF RG]=4      t> ! RH RI]=4      t? ! RJ RK]?4      t@ ! RL RM]-4      tA ! RN RO]-4      tBR# )PaB  
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)Markdownc               $    V ^8  d   QhRRRRRR/# )   mdr	   kwargsr   returnzutil.Registry[InlineProcessor] )formats   "]/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/markdown/inlinepatterns.py__annotate__r   5   s"     * *X * *9W *    c                8   \         P                  ! 4       pVP                  \        \        4      R^4       VP                  \        \        V 4      R^4       VP                  \        \        V 4      R^4       VP                  \        \        V 4      R^4       VP                  \        \        V 4      R^4       VP                  \        \        V 4      R^4       VP                  \        \        V 4      R^4       VP                  \!        \        V 4      R^}4       VP                  \#        \$        V 4      R	^x4       VP                  \'        \(        V 4      R
^n4       VP                  \+        \,        R4      R^d4       VP                  \/        \0        V 4      R^Z4       VP                  \/        \2        V 4      R^P4       VP                  \5        \6        4      R^F4       VP                  \9        R4      R^<4       VP                  \;        R4      R^24       V# )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autolinkautomailbr	linebreakhtmlentity
not_strongz\*	em_strong_
em_strong2)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   &, r   build_inlinepatternsrE   5   s   & ]]_N3K@*cR1)R@(CP4\2FUXY/<fcJ0C\SVW%&8"=?PRU %lB79JC *+=rBDUWZ 3KDjRUV3KDjRUV8M{\_`/<fbI/	2>"M5mDlTVW-e4k2F/5|RHr   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  \nc                    V ^8  d   QhRRRR/# )r   stringstrr   r   )r   s   "r   r   r      s      C C r   c                    V P                  R4      '       d   V P                  R4      '       g/   V P                  R4      '       d   V P                  R4      '       d   V ^R # V # )z#Remove quotes from around a string."')
startswithendswith)rG   s   &r   dequoterO      sQ    			3		FOOC$8$8#6??3#7#7a|r   c                  :    ] tR t^t$ RtR]R&   R]R&   R]R&   RtR# )	EmStrongItemzEmphasis/strong pattern item.re.Pattern[str]patternrH   buildertagsr   N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__r   r   r   rQ   rQ      s    'L
Ir   rQ   c                      ] tR t^t$ Rt]! 4       tR]R&    R]R&   R]R&   RR	 R
 lltR R lt	R R lt
R R ltR R ltRtR# )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_EXCLUDESrR   compiled_reMarkdown | Noner   Nc                    V ^8  d   QhRRRR/# r   rS   rH   r   ra   r   )r   s   "r   r   Pattern.__annotate__           r   c                    Wn         \        P                  ! RV,          \        P                  \        P                  ,          4      V n        W n        R# )z
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)rS   recompileDOTALLUNICODEr`   r   selfrS   r   s   &&&r   __init__Pattern.__init__   s9     ::&6&@&(ii"**&<> r   c                   V ^8  d   QhRR/# )r   r   z
re.Patternr   )r   s   "r   r   rd      s        :  r   c                    V P                   # )z&Return a compiled regular expression. )r`   rl   s   &r   getCompiledRegExpPattern.getCompiledRegExp   s    r   c                    V ^8  d   QhRRRR/# )r   mre.Match[str]r   zetree.Element | strr   )r   s   "r   r   rd      s      ] /B r   c                    R# )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.

Nr   rl   ru   s   &&r   handleMatchPattern.handleMatch   s     	r   c                   V ^8  d   QhRR/# )r   r   rH   r   )r   s   "r   r   rd     s     ' 'c 'r   c                .    V P                   P                  # )z*Return class name, to define pattern type )	__class__rV   rq   s   &r   typePattern.type  s    ~~&&&r   c                    V ^8  d   QhRRRR/# r   textrH   r   r   )r   s   "r   r   rd     s     ? ?S ?S ?r   c                   a  V P                   P                  R,          P                  oT3R lp\        P
                  P                  Y!4      #   \         d    Tu # i ; i)=Return unescaped text given text with an inline placeholder. inlinec                   < V P                  ^4      pVS9   dI   SP                  V4      p\        V\        4      '       d   V# RP	                  VP                  4       4      # R# )    N)groupget
isinstancerH   joinitertext)ru   idvaluestashs   &  r   	get_stash#Pattern.unescape.<locals>.get_stash  sS    BU{		"eS)) L 775>>#344 r   r   treeprocessorsstashed_nodesKeyErrorr   INLINE_PLACEHOLDER_REsubrl   r   r   r   s   && @r   unescapePattern.unescape  sV    	GG**84BBE	5 ))--i>>  	K	s   'A AA)r`   r   rS   N)rV   rW   rX   rY   rZ   tupler_   r[   rm   rr   ry   r~   r   r\   r   r   r   r^   r^      sG    & */0
 ! " '? ?r   r^   c                  6    ] tR tRtRtR	R R lltR R ltRtR# )
InlineProcessori  z
Base class that inline processors subclass.

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

Nc                    V ^8  d   QhRRRR/# rc   r   )r   s   "r   r   InlineProcessor.__annotate__$  re   r   c                    Wn         \        P                  ! V\        P                  \        P                  ,          4      V n        RV n        W n        R# )z
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)rS   rg   rh   ri   rj   r`   	safe_moder   rk   s   &&&r   rm   InlineProcessor.__init__$  s7     ::gryy2::/EF r   c               $    V ^8  d   QhRRRRRR/# )r   ru   rv   datarH   r   z9tuple[etree.Element | str | None, int | None, int | None]r   )r   s   "r   r   r   5  s"      ] # :s r   c                    R# )a9  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.

Nr   rl   ru   r   s   &&&r   ry   InlineProcessor.handleMatch5  s    & 	r   )r`   r   rS   r   r   rV   rW   rX   rY   rZ   rm   ry   r\   r   r   r   r   r     s    " r   r   c                  &    ] tR tRtRtR R ltRtR# )SimpleTextPatterniK  z1Return a simple text of `group(2)` of a Pattern. c                    V ^8  d   QhRRRR/# r   ru   rv   r   rH   r   )r   s   "r   r   SimpleTextPattern.__annotate__M  s      ] s r   c                $    VP                  ^4      # )z;Return string content of `group(2)` of a matching pattern. )r   rx   s   &&r   ry   SimpleTextPattern.handleMatchM  s    wwqzr   r   NrV   rW   rX   rY   rZ   ry   r\   r   r   r   r   r   K  s    < r   r   c                  &    ] tR tRtRtR R ltRtR# )r@   iR  z1Return a simple text of `group(1)` of a Pattern. c               $    V ^8  d   QhRRRRRR/# r   ru   rv   r   rH   r   ztuple[str, int, int]r   )r   s   "r   r   &SimpleTextInlineProcessor.__annotate__T  s"     0 0] 0# 0:N 0r   c                f    VP                  ^4      VP                  ^ 4      VP                  ^ 4      3# )z;Return string content of `group(1)` of a matching pattern. )r   startendr   s   &&&r   ry   %SimpleTextInlineProcessor.handleMatchT  s'    wwqz1771:quuQx//r   r   Nr   r   r   r   r@   r@   R  s    <0 0r   r@   c                  &    ] tR tRtRtR R ltRtR# )r+   iY  zReturn an escaped character. c               $    V ^8  d   QhRRRRRR/# )r   ru   rv   r   rH   r   ztuple[str | None, int, int]r   )r   s   "r   r   "EscapeInlineProcessor.__annotate__\  s"     . .] .# .:U .r   c                P   VP                  ^4      pW0P                  P                  9   dZ   RP                  \        P
                  \        V4      \        P                  4      VP                  ^ 4      VP                  ^ 4      3# RVP                  ^ 4      VP                  ^ 4      3# )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`.
{}{}{}N)
r   r   ESCAPED_CHARSr   r   STXordETXr   r   )rl   ru   r   chars   &&& r   ry   !EscapeInlineProcessor.handleMatch\  su     wwqz77(((??488SYA1771:quuUVxWWQUU1X--r   r   Nr   r   r   r   r+   r+   Y  s    (. .r   r+   c                  2    ] tR tRtRtR R ltR R ltRtR# )	SimpleTagPatternil  zQ
Return element of type `tag` with a text attribute of `group(3)`
of a Pattern.

c                    V ^8  d   QhRRRR/# r   rS   rH   tagr   )r   s   "r   r   SimpleTagPattern.__annotate__r       1 1 1# 1r   c                <    \         P                  W4       W n        R# )z
Create an instant of an simple tag pattern.

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

N)r^   rm   r   rl   rS   r   s   &&&r   rm   SimpleTagPattern.__init__r  s     	'0r   c                    V ^8  d   QhRRRR/# r   ru   rv   r   etree.Elementr   )r   s   "r   r   r     s      ] } r   c                r    \         P                  ! V P                  4      pVP                  ^4      Vn        V# )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   )rl   ru   els   && r   ry   SimpleTagPattern.handleMatch  s*    
 ]]488$''!*	r   r   Nr   r   r   r   r   r   l  s    
1 r   r   c                  2    ] tR tRtRtR R ltR R ltRtR# )	SimpleTagInlineProcessori  zQ
Return element of type `tag` with a text attribute of `group(2)`
of a Pattern.

c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   %SimpleTagInlineProcessor.__annotate__  r   r   c                <    \         P                  W4       W n        R# )z
Create an instant of an simple tag processor.

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

N)r   rm   r   r   s   &&&r   rm   !SimpleTagInlineProcessor.__init__  s     	  /0r   c               $    V ^8  d   QhRRRRRR/# r   ru   rv   r   rH   r   ztuple[etree.Element, int, int]r   )r   s   "r   r   r     s"     ( (] (# (:X (r   c                    \         P                  ! V P                  4      pVP                  ^4      Vn        W1P                  ^ 4      VP                  ^ 4      3# )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   rl   ru   r   r   s   &&& r   ry   $SimpleTagInlineProcessor.handleMatch  s@    
 ]]488$''!*771:quuQx''r   r   Nr   r   r   r   r   r     s    
1( (r   r   c                  &    ] tR tRtRtR R ltRtR# )SubstituteTagPatterni  2Return an element of type `tag` with no children. c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   !SubstituteTagPattern.__annotate__  s     ' '] '} 'r   c                B    \         P                  ! V P                  4      # zGReturn empty [`Element`][xml.etree.ElementTree.Element] of type `tag`. )r   r   r   rx   s   &&r   ry    SubstituteTagPattern.handleMatch  s    }}TXX&&r   r   Nr   r   r   r   r   r     s    =' 'r   r   c                  &    ] tR tRtRtR R ltRtR# )r;   i  r   c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r   )SubstituteTagInlineProcessor.__annotate__  s"     = =] =# =:X =r   c                    \         P                  ! V P                  4      VP                  ^ 4      VP	                  ^ 4      3# r   )r   r   r   r   r   r   s   &&&r   ry   (SubstituteTagInlineProcessor.handleMatch  s,    }}TXX&
AEE!H<<r   r   Nr   r   r   r   r;   r;     s    == =r   r;   c                  2    ] tR tRtRtR R ltR R ltRtR# )	r)   i  z@Return a `<code>` element containing the escaped matching text. c                   V ^8  d   QhRR/# )r   rS   rH   r   )r   s   "r   r   $BacktickInlineProcessor.__annotate__  s     1 1 1r   c                	    \         P                  W4       R P                  \        P                  \        R4      \        P                  4      V n        RV n        R# )r   \codeN)	r   rm   r   r   r   r   r   ESCAPED_BSLASHr   )rl   rS   s   &&r   rm    BacktickInlineProcessor.__init__  s;      /&oodhhD	488L0r   c               $    V ^8  d   QhRRRRRR/# )r   ru   rv   r   rH   r   z$tuple[etree.Element | str, int, int]r   )r   s   "r   r   r     s'     Y Y] Y# Y:^ Yr   c                   VP                  ^4      '       d   \        P                  ! V P                  4      p\        P
                  ! \        P                  ! VP                  ^4      P                  4       4      4      Vn        W1P                  ^ 4      VP                  ^ 4      3# VP                  ^4      P                  RV P                  4      VP                  ^ 4      VP                  ^ 4      3# )aX  
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.

z\\)r   r   r   r   r   AtomicStringcode_escapestripr   r   r   replacer   r   s   &&& r   ry   #BacktickInlineProcessor.handleMatch  s     771::txx(B''(8(89I9I9K(LMBGwwqz1558++771:%%fd.A.ABAGGAJPQPUPUVWPXXXr   )r   r   Nr   r   r   r   r)   r)     s    K1Y Yr   r)   c                  &    ] tR tRtRtR R ltRtR# )DoubleTagPatterni  ^Return a ElementTree element nested in tag2 nested in tag1.

Useful for strong emphasis etc.

c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   DoubleTagPattern.__annotate__  s      ] } r   c                ,   V P                   P                  R4      w  r#\        P                  ! V4      p\        P                  ! WC4      pVP                  ^4      Vn        \        VP                  4       4      ^8X  d   VP                  ^4      Vn	        V# )z
Return [`Element`][xml.etree.ElementTree.Element] in following format:
`<tag1><tag2>group(3)</tag2>group(4)</tag2>` where `group(4)` is optional.

,)
r   splitr   r   
SubElementr   r   lengroupstail)rl   ru   tag1tag2el1el2s   &&    r   ry   DoubleTagPattern.handleMatch  sk     XX^^C(
mmD!s)771:qxxz?awwqzCH
r   r   Nr   r   r   r   r  r    s    
 r   r  c                  &    ] tR tRtRtR R ltRtR# )DoubleTagInlineProcessori  r  c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r   %DoubleTagInlineProcessor.__annotate__  s"     ) )] )# ):X )r   c                l   V P                   P                  R4      w  r4\        P                  ! V4      p\        P                  ! WT4      pVP                  ^4      Vn        \        VP                  4       4      ^8X  d   VP                  ^4      Vn	        WQP                  ^ 4      VP                  ^ 4      3# )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   )rl   ru   r   r  r  r  r  s   &&&    r   ry   $DoubleTagInlineProcessor.handleMatch  s     XX^^C(
mmD!s)771:qxxz?awwqzCHGGAJa((r   r   Nr   r   r   r   r  r    s    
) )r   r  c                  >    ] tR tRtRtR R ltR R ltR R ltR	tR
# )r=   i  z0Store raw inline html and return a placeholder. c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r    HtmlInlineProcessor.__annotate__  s"     2 2] 2# 2:N 2r   c                    V P                  V P                  VP                  ^4      4      4      pV P                  P                  P                  V4      pWAP                  ^ 4      VP                  ^ 4      3# )zKStore the text of `group(1)` of a pattern and return a placeholder string. )backslash_unescaper   r   r   	htmlStashstorer   r   )rl   ru   r   rawhtmlplace_holders   &&&  r   ry   HtmlInlineProcessor.handleMatch  sX    ))$--
*CDww((..w7WWQZq11r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r    s     ? ?S ?S ?r   c                   a a  S P                   P                  R,          P                  oR T T3R llp\        P
                  P                  Y!4      #   \         d    Tu # i ; i)r   r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   2HtmlInlineProcessor.unescape.<locals>.__annotate__  s     	* 	* 	*3 	*r   c                   < V P                  ^4      pSP                  V4      pVe,    SP                  SP                  P	                  V4      4      # R#   \
         d    RT,          u # i ; i)r   Nz\%s)r   r   r   r   
serializer	Exception)ru   r   r   rl   r   s   &  r   r   /HtmlInlineProcessor.unescape.<locals>.get_stash  sf    BIIbME *==););E)BCC ! ! *!E>)*s   )A A,+A,r   r   s   f& @r   r   HtmlInlineProcessor.unescape  s[    	GG**84BBE	* 	* ))--i>>  	K	s   'A A$#A$c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   r    s     
' 
's 
's 
'r   c                     V P                   P                  R,          P                  pR R lpTP	                  Y14      #   \         d    Tu # i ; i)zFReturn text with backslash escapes undone (backslashes are restored). r   c                    V ^8  d   QhRRRR/# r   r   )r   s   "r   r   <HtmlInlineProcessor.backslash_unescape.<locals>.__annotate__  s     	( 	( 	(3 	(r   c                H    \        \        V P                  ^4      4      4      # )r   )chrintr   )ru   s   &r   	_unescape9HtmlInlineProcessor.backslash_unescape.<locals>._unescape  s    s1771:''r   )r   r   REr   r   )rl   r   r3  r1  s   &&  r   r  &HtmlInlineProcessor.backslash_unescape  sM    	''
366B	( vvi&&  	K	s   'A   AAr   N)	rV   rW   rX   rY   rZ   ry   r   r  r\   r   r   r   r=   r=     s    ;2?&
' 
'r   r=   c                  z   ] tR tRtRt]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR	4      .t R
 R ltR R ltR R ltR R ltR R ltR R ltRtR# )rB   i  zGEmphasis processor for handling strong and em matches inside asterisks.double	strong,em	em,strongdouble2singlestrongemc               (    V ^8  d   QhRRRRRRRR/# )	r   ru   rv   r   rH   idxr0  r   r   r   )r   s   "r   r   AsteriskProcessor.__annotate__+  s(      m # C M r   c                z    \         P                  ! V4      pVP                  ^4      pV P                  WTRV4       V# )zReturn single tag.N)r   r   r   parse_sub_patterns)rl   ru   r   r>  r  r   s   &&&&  r   build_singleAsteriskProcessor.build_single+  s4    mmC wwqz45
r   c               (    V ^8  d   QhRRRRRRRR/# 	r   ru   rv   rU   rH   r>  r0  r   r   r   )r   s   "r   r   r?  2  s(      m 3 S ] r   c                p   VP                  R4      w  rE\        P                  ! V4      p\        P                  ! V4      pVP                  ^4      pV P	                  WRV4       VP                  V4       \        VP                  4       4      ^8X  d$   VP                  ^4      pV P	                  WWs4       V# )zReturn double tag.r  N)r  r   r   r   rA  appendr	  r
  	rl   ru   rU   r>  r  r  r  r  r   s	   &&&&     r   build_doubleAsteriskProcessor.build_double2  s     ZZ_
mmD!mmD!wwqz45

3qxxz?a771:D##Ds8
r   c               (    V ^8  d   QhRRRRRRRR/# rE  r   )r   s   "r   r   r?  @  s(      } C c m r   c                6   VP                  R4      w  rE\        P                  ! V4      p\        P                  ! V4      pVP                  ^4      pV P	                  WRV4       VP                  ^4      pVP                  V4       V P	                  WRV4       V# )zFReturn double tags (variant 2): `<strong>text <em>text</em></strong>`.r  N)r  r   r   r   rA  rG  rH  s	   &&&&     r   build_double2AsteriskProcessor.build_double2@  s}     ZZ_
mmD!mmD!wwqz45wwqz

345
r   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   r   rH   parentr   lastzetree.Element | Noner>  r0  r   Noner   )r   s   "r   r   r?  M  s4     ;# ;#;#!.;#6J;#QT;#	;#r   c                   ^ p^ p\        V4      pWg8  Ed   V P                  P                  W4      '       d   Rp\        V P                  4       F  w  rW8:  d   K  V
P
                  P                  W4      pV'       g   K2  WVP                  ^ 4       pV'       d   Ve   Wn        MWn        V P                  WP                  V
P                  V	4      pVP                  V4       TpVP                  ^ 4      ;rVRpK  	  V'       g   V^,          pEK  EK  V^,          pEK  WR pV'       d   Ve	   Wn        R# Wn        R# R# )z
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.
FNT)r	  r`   match	enumeratePATTERNSrS   r   r  r   build_elementrT   rU   rG  r   )rl   r   rP  rQ  r>  offsetposlengthmatchedindexitemru   r   r   s   &&&&&         r   rA  $AsteriskProcessor.parse_sub_patternsM  s    Tl%%d00#,T]]#;KE| **45Aq
  $1771:6#/,0	.2!//<<ERb)!'(uuQx/"&+ $<, 1HC 
 q G} 	"	 r   c          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r   ru   rv   rT   rH   rU   r\  r0  r   r   r   )r   s   "r   r   r?    s0     5 5} 5s 5# 5c 5Vc 5r   c                    VR8X  d   V P                  WV4      # VR8X  d   V P                  WV4      # V P                  WV4      # )zElement builder.r9  r6  )rM  rI  rB  )rl   ru   rT   rU   r\  s   &&&&&r   rW  AsteriskProcessor.build_element  sM     i%%au55 $$Qe44$$Qe44r   c               $    V ^8  d   QhRRRRRR/# r   ru   rv   r   rH   r   z3tuple[etree.Element | None, int | None, int | None]r   )r   s   "r   r   r?    s"      ] # :m r   c                L   RpRpRp\        V P                  4       F  w  rgVP                  P                  W!P	                  ^ 4      4      pV'       g   K9  VP	                  ^ 4      pVP                  ^ 4      pV P                  WP                  VP                  V4      p M	  W4V3# )zParse patterns.N)	rU  rV  rS   rT  r   r   rW  rT   rU   )	rl   ru   r   r   r   r   r\  r]  m1s	   &&&      r   ry   AsteriskProcessor.handleMatch  s     $T]]3KE##D''!*5BrffQi''LL$))UK 4 #~r   r   N)rV   rW   rX   rY   rZ   rQ   rg   rh   EM_STRONG_REri   rj   STRONG_EM_RESTRONG_EM3_RE	STRONG_REEMPHASIS_RErV  rB  rI  rM  rA  rW  ry   r\   r   r   r   rB   rB     s    Q 	RZZbii"**.DExQ\]RZZbii"**.DExQ\]RZZryy2::/EF	S^_RZZ	299rzz+ABHhWRZZRYY-CDhPTUH P;#z5 r   rB   c                  0   ] tR tRtRt]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR4      ]! ]P                  ! ]]P                  ]P                  ,          4      RR	4      .tR
tR# )rC   i  zIEmphasis processor for handling strong and em matches inside underscores.r6  r7  r8  r9  r:  r;  r<  r   N)rV   rW   rX   rY   rZ   rQ   rg   rh   EM_STRONG2_REri   rj   STRONG_EM2_RESMART_STRONG_EM_RESMART_STRONG_RESMART_EMPHASIS_RErV  r\   r   r   r   rC   rC     s    S 	RZZryy2::/EFR]^RZZryy2::/EFR]^RZZ 2BII

4JKYXcdRZZRZZ1GH(T\]RZZ 1299rzz3IJHVZ[H Pr   rC   c                      ] tR tRtRt]P                  ! R]P                  ]P                  ,          4      t	]P                  ! R4      t
R R ltR R ltR	 R
 ltRtR# )r/   i  z,Return a link element from the given match. z2\(\s*(?:(<[^<>]*>)\s*(?:('[^']*'|"[^"]*")\s*)?\))?z\sc               $    V ^8  d   QhRRRRRR/# rc  r   )r   s   "r   r    LinkInlineProcessor.__annotate__  s"     % %] %# %:m %r   c                F   V P                  W!P                  ^ 4      4      w  r4pV'       g   R# V P                  W$4      w  rgrEV'       g   R# \        P                  ! R4      pW8n        VP                  RV4       Ve   VP                  RV4       WP                  ^ 4      V3# )zRReturn an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. ahreftitleNNN)getTextr   getLinkr   r   r   setr   )	rl   ru   r   r   r\  handledrw  rx  r   s	   &&&      r   ry   LinkInlineProcessor.handleMatch  s    #||D%%(;W##&*ll4&?#U##]]3
vtFF7E"771:u$$r   c               $    V ^8  d   QhRRRRRR/# )r   r   rH   r\  r0  r   z!tuple[str, str | None, int, bool]r   )r   s   "r   r   rt    s'     r+ r+C r+ r+0Q r+r   c           	        RpRpRpV P                   P                  WR7      pV'       dz   VP                  ^4      '       dc   VP                  ^4      ^R	 P                  4       pVP                  ^4      '       d   VP                  ^4      ^R	 pVP	                  ^ 4      pRpEMV'       Ed   ^p^pVP	                  4       p	T	pR	p
RpR	pR	pRpRpR	pR	pRp\        V\        V4      4       EF  pVV,          pVR8X  d$   V'       g   V^,          pMV^ 8  d
   V^,          pMVR8X  dS   VR	8w  d   VV8X  g   VR	8w  d   VV8X  d   ^ pMV'       g   V^,          pMV^ 8  d   V^,          pV^ 8X  d
   V^,           p
MeVR
9   d_   V'       g   RpTp^pV^,           pTpMDVV8w  d   V'       g   V^,           pTpM)VV8X  d   V^,           pMV'       d   VV8X  d
   V^,           pV^,          pV^ 8X  dw   V^ 8  d.   VV8X  d'   WV^,
           pRP                  WV^,
           4      pM@V^ 8  d/   VV8X  d(   WV^,
           pRP                  VVV^,
           4      pMWV^,
           p MVR8w  g   EK  TpEK  	  V^ 8w  d   V^ 8X  d   WV
^,
           pT
p^ pV^ 8H  pVeC   V P                  P                  R\        V P                  VP                  4       4      4      4      pV P                  V4      P                  4       pW4W%3# )z?Parse data between `()` of `[Text]()` allowing recursive `()`. r   NFrY  T() rL   )rK   rJ   )RE_LINKrT  r   r   r   ranger	  r   RE_TITLE_CLEANr   rO   r   )rl   r   r\  rw  rx  r}  ru   bracket_countbacktrack_countstart_indexlast_bracketquotestart_quote
exit_quoteignore_matches	alt_quotestart_alt_quoteexit_alt_quoterQ  rY  cs   &&&                  r   r{  LinkInlineProcessor.getLink  s     LLt/771:a#))+Dwwqzz
1R(EE!HEGQMO%%'KEL !%EKJ"N I ON DUCI.I8 *%*(1,'1,#X $r)etmSUAUZcgkZk()+%*(1,'1,*a/+019L*_  *.*7()&+ai !eI*/!)$%	e%*QY
"qI~).
 !A%!Q5D=#a@ "a(H I'1,d1B#!0CD "_^a=O(P Q#	:8Dw /B !o&:q(89$ !#q(G''++Cu{{}9U1VWE}}T"((*E**r   c               $    V ^8  d   QhRRRRRR/# )r   r   rH   r\  r0  r   tuple[str, int, bool]r   )r   s   "r   r   rt  @  s"     8 8C 8 80E 8r   c                   ^p. p\        V\        V4      4       FO  pW,          pVR8X  d   V^,          pMVR8X  d
   V^,          pV^,          pV^ 8X  d    MVP                  V4       KQ  	  RP                  V4      W#^ 8H  3# )zcParse the content between `[]` of the start of an image or link
resolving nested square brackets.

][r   )r  r	  rG  r   )rl   r   r\  r  r   rY  r  s   &&&    r   rz  LinkInlineProcessor.getText@  s    
 D	*C	ACx"c"QJE!KKN + wwt}ea%777r   r   N)rV   rW   rX   rY   rZ   rg   rh   ri   rj   r  r  ry   r{  rz  r\   r   r   r   r/   r/     sM    7jjRTVT]T]`b`j`jTjkGZZ&N%*r+h8 8r   r/   c                  &    ] tR tRtRtR R ltRtR# )r1   iT  z-Return a `img` element from the given match. c               $    V ^8  d   QhRRRRRR/# rc  r   )r   s   "r   r   !ImageInlineProcessor.__annotate__W  s"     % %] %# %:m %r   c                |   V P                  W!P                  ^ 4      4      w  r4pV'       g   R# V P                  W$4      w  rgrEV'       g   R# \        P                  ! R4      pVP                  RV4       Ve   VP                  RV4       VP                  RV P                  V4      4       WP                  ^ 4      V3# )zTReturn an `img` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. imgsrcrx  altry  )rz  r   r{  r   r   r|  r   r   )	rl   ru   r   r   r\  r}  r  rx  r   s	   &&&      r   ry    ImageInlineProcessor.handleMatchW  s    #||D%%(;W##%)\\$%>"E##]]5!
ucFF7E"
udmmD)*771:u$$r   r   Nr   r   r   r   r1   r1   T  s    8% %r   r1   c                      ] tR tRtRt]P                  ! R]P                  4      t]P                  ! R]P                  ]P                  ,          4      tR R ltR R ltR	 R
 ltRtR# )r-   il  z5Match to a stored reference and return link element. z\s+z\s?\[([^\]]*)\]c               $    V ^8  d   QhRRRRRR/# rc  r   )r   s   "r   r   %ReferenceInlineProcessor.__annotate__r  s'     @ @] @# @:m @r   c                   V P                  W!P                  ^ 4      4      w  r4pV'       g   R# V P                  W$V4      w  rgpV'       g   R# V P                  P	                  RV4      pW`P
                  P                  9  d   RVP                  ^ 4      V3# V P
                  P                  V,          w  rV P                  WV4      VP                  ^ 4      V3# )zj
Return [`Element`][xml.etree.ElementTree.Element] returned by `makeTag` method or `(None, None, None)`.

Nr  ry  )	rz  r   evalIdNEWLINE_CLEANUP_REr   r   
referencesr   makeTag)
rl   ru   r   r   r\  r}  r   r   rw  rx  s
   &&&       r   ry   $ReferenceInlineProcessor.handleMatchr  s    
  $||D%%(;W##;;tD9## $$((b1WW'''S((gg((,||D.
C??r   c               (    V ^8  d   QhRRRRRRRR/# )r   r   rH   r\  r0  r   r   ztuple[str | None, int, bool]r   )r   s   "r   r   r    s)      3 s # :V r   c                    V P                   P                  WR7      pV'       g   RVR3# VP                  ^4      P                  4       pVP	                  ^ 4      pV'       g   VP                  4       pWVR3# )zD
Evaluate the id portion of `[ref][id]`.

If `[ref][]` use `[ref]`.
r  NFT)r  rT  r   lowerr   )rl   r   r\  r   ru   r   r   s   &&&&   r   r  ReferenceInlineProcessor.evalId  sf     LLt/%%!!#B%%(CZZ\}r   c               (    V ^8  d   QhRRRRRRRR/# r   rw  rH   rx  r   r   r   r   )r   s   "r   r   r    s(     	 	C 	 	3 	= 	r   c                    \         P                  ! R4      pVP                  RV4       V'       d   VP                  RV4       W4n        V# )z:Return an `a` [`Element`][xml.etree.ElementTree.Element]. rv  rw  rx  )r   r   r|  r   rl   rw  rx  r   r   s   &&&& r   r   ReferenceInlineProcessor.makeTag  s9    ]]3
vtFF7E"	r   r   N)rV   rW   rX   rY   rZ   rg   rh   	MULTILINEr  ri   rj   r  ry   r  r  r\   r   r   r   r-   r-   l  sM    @FBLL9jj+RYY-CDG@, 	 	r   r-   c                  &    ] tR tRtRtR R ltRtR# )r5   i  z%Short form of reference: `[google]`. c               (    V ^8  d   QhRRRRRRRR/# r   r   rH   r\  r0  r   r   r  r   )r   s   "r   r   *ShortReferenceInlineProcessor.__annotate__  )     ) )3 )s )# ):O )r   c                (    VP                  4       VR3# zEvaluate the id of `[ref]`.  Tr  rl   r   r\  r   s   &&&&r   r  $ShortReferenceInlineProcessor.evalId       zz|UD((r   r   NrV   rW   rX   rY   rZ   r  r\   r   r   r   r5   r5     s    /) )r   r5   c                  &    ] tR tRtRtR R ltRtR# )r3   i  z6Match to a stored reference and return `img` element. c               (    V ^8  d   QhRRRRRRRR/# r  r   )r   s   "r   r   *ImageReferenceInlineProcessor.__annotate__  s(      C  3 = r   c                    \         P                  ! R4      pVP                  RV4       V'       d   VP                  RV4       VP                  RV P                  V4      4       V# )z<Return an `img` [`Element`][xml.etree.ElementTree.Element]. r  r  rx  r  )r   r   r|  r   r  s   &&&& r   r  %ImageReferenceInlineProcessor.makeTag  sK    ]]5!
udFF7E"
udmmD)*	r   r   N)rV   rW   rX   rY   rZ   r  r\   r   r   r   r3   r3     s    A r   r3   c                  &    ] tR tRtRtR R ltRtR# )r6   i  z)Short form of image reference: `![ref]`. c               (    V ^8  d   QhRRRRRRRR/# r  r   )r   s   "r   r   /ShortImageReferenceInlineProcessor.__annotate__  r  r   c                (    VP                  4       VR3# r  r  r  s   &&&&r   r  )ShortImageReferenceInlineProcessor.evalId  r  r   r   Nr  r   r   r   r6   r6     s    4) )r   r6   c                  &    ] tR tRtRtR R ltRtR# )r7   i  zCReturn a link Element given an auto-link (`<http://example/com>`). c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r   $AutolinkInlineProcessor.__annotate__  s"     ( (] (# (:X (r   c                &   \         P                  ! R4      pVP                  RV P                  VP	                  ^4      4      4       \
        P                  ! VP	                  ^4      4      Vn        W1P                  ^ 4      VP                  ^ 4      3# )zHReturn an `a` [`Element`][xml.etree.ElementTree.Element] of `group(1)`. rv  rw  )
r   r   r|  r   r   r   r   r   r   r   r   s   &&& r   ry   #AutolinkInlineProcessor.handleMatch  sd    ]]3
vt}}QWWQZ01##AGGAJ/771:quuQx''r   r   Nr   r   r   r   r7   r7     s    N( (r   r7   c                  &    ] tR tRtRtR R ltRtR# )r9   i  zO
Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`).
c               $    V ^8  d   QhRRRRRR/# r   r   )r   s   "r   r   $AutomailInlineProcessor.__annotate__  s"     ( (] (# (:X (r   c           
     p   \         P                  ! R4      pV P                  VP                  ^4      4      pVP	                  R4      '       d   V\        R4      R pR R lpV Uu. uF  qe! \        V4      4      NK  	  pp\        P                  ! RP                  V4      4      Vn
        RV,           pRP                  V Uu. uF*  p\        P                  R\        V4      ,          ,           NK,  	  up4      pVP                  RV4       W1P                  ^ 4      VP                  ^ 4      3# u upi u upi )	z`Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link  of `group(1)`. rv  zmailto:Nc                    V ^8  d   QhRRRR/# )r   r   r0  r   rH   r   )r   s   "r   r   9AutomailInlineProcessor.handleMatch.<locals>.__annotate__  s     	> 	> 	> 	>r   c                    \         P                  P                  V 4      pV'       d!   RP                  \        P
                  V4      # R\        P
                  V 3,          # )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   & r   r  ;AutomailInlineProcessor.handleMatch.<locals>.codepoint2name  sH    ,,006F~~d&9&96BB4#6#6"===r   r   z#%d;rw  )r   r   r   r   rM   r	  r   r   r   r   r   r  r|  r   r   )	rl   ru   r   r   emailr  letterlettersmailtos	   &&&      r   ry   #AutomailInlineProcessor.handleMatch  s   ]]3aggaj)I&&#i./*E	> >CCU6>#f+.UC##BGGG$45U"4:<4:& --f+1& & &4:< =
vv771:quuQx'' D<s   &D.0D3r   Nr   r   r   r   r9   r9     s    ( (r   r9   )CrZ   
__future__r   r   r   typingr   r   r   r   rg   xml.etree.ElementTreer   ElementTreer!   r   markdownr	   rE   NOIMGr*   r,   rk  rj  rp  rq  ro  rg  rm  rh  rn  ri  r0   r2   r.   r4   rA   r8   r:   r>   r?   r<   rO   rQ   r^   r   r   r@   r+   r   r   r   r;   r)   r  r  r=   rB   rC   r/   r1   r-   r5   r3   r6   r7   r9   r   r   r   <module>r     s5  (* #  = = 	 % % !*` 	 \L M	 = 7	 5: b9  cO  B, S, V, ?, B9 ?
%- ` S 5"  :8 '< =& ;
  %<	 V (: S? S?l-g -` 0 0.O .&w :( (:'+ '=#; =Yo Y2' *)7 )*%'/ %'PC CL
P+ 
P_8/ _8D%. %052 5p)$< )	$< 	))F )(o ((o (r   