
    ̆h:                    *   S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
r
SSKJs  Jr  SSKJr  \(       a  SSKJr  SPS	 jrS
r Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr Sr \S-   r  Sr! \ r" \!r# Sr$ Sr% Sr& Sr' Sr( Sr) SQS jr* " S  S!\	5      r+ " S" S#5      r, " S$ S%\,5      r- " S& S'\,5      r. " S( S)\-5      r/ " S* S+\-5      r0 " S, S-\,5      r1 " S. S/\-5      r2 " S0 S1\15      r3 " S2 S3\25      r4 " S4 S5\-5      r5 " S6 S7\15      r6 " S8 S9\25      r7 " S: S;\-5      r8 " S< S=\-5      r9 " S> S?\95      r: " S@ SA\-5      r; " SB SC\;5      r< " SD SE\;5      r= " SF SG\=5      r> " SH SI\=5      r? " SJ SK\?5      r@ " SL SM\-5      rA " SN SO\-5      rBg)RaB  
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                8   [         R                  " 5       nUR                  [        [        5      SS5        UR                  [        [        U 5      SS5        UR                  [        [        U 5      SS5        UR                  [        [        U 5      SS5        UR                  [        [        U 5      S	S
5        UR                  [        [        U 5      SS5        UR                  [        [        U 5      SS5        UR                  [!        [        U 5      SS5        UR                  [#        [$        U 5      SS5        UR                  ['        [(        U 5      SS5        UR                  [+        [,        S5      SS5        UR                  [/        [0        U 5      SS5        UR                  [/        [2        U 5      SS5        UR                  [5        [6        5      SS5        UR                  [9        S5      SS 5        UR                  [;        S!5      S"S#5        U$ )$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)mdkwargsinlinePatternss      O/opt/services/DDDS/venv/lib/python3.13/site-packages/markdown/inlinepatterns.pybuild_inlinepatternsrP   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    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                    U R                  S5      (       a  U R                  S5      (       d,  U R                  S5      (       a  U R                  S5      (       a  U SS $ U $ )z#Remove quotes from around a string."'r   )
startswithendswith)strings    rO   dequoterY      sQ    			3		FOOC$8$8#6??3#7#7a|rQ   c                  8    \ rS rSr% SrS\S'   S\S'   S\S'   Srg	)
EmStrongItem   zEmphasis/strong pattern item.re.Pattern[str]patternstrbuildertags N)__name__
__module____qualname____firstlineno____doc____annotations____static_attributes__rb   rQ   rO   r[   r[      s    'L
IrQ   r[   c                  ~    \ rS rSr% Sr\" 5       rS\S'    S\S'   S\S'   SSS
 jjrSS jr	SS jr
SS jrSS jrSrg	)Pattern   a  
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 | NonerL   Nc                    Xl         [        R                  " SU-  [        R                  [        R                  -  5      U l        X l        g)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)r^   recompileDOTALLUNICODErn   rL   selfr^   rL   s      rO   __init__Pattern.__init__   s9     ::&6&@&(ii"**&<> rQ   c                    U R                   $ )z&Return a compiled regular expression. )rn   rv   s    rO   getCompiledRegExpPattern.getCompiledRegExp   s    rQ   c                    g)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.

Nrb   rv   ms     rO   handleMatchPattern.handleMatch   s     	rQ   c                .    U R                   R                  $ )z*Return class name, to define pattern type )	__class__rc   rz   s    rO   typePattern.type  s    ~~&&&rQ   c                   ^  U R                   R                  S   R                  mU4S jn[        R
                  R                  X!5      $ ! [         a    Us $ f = f)=Return unescaped text given text with an inline placeholder. inlinec                   > U R                  S5      nUT;   aG  TR                  U5      n[        U[        5      (       a  U$ SR	                  UR                  5       5      $ g )Nr    )groupget
isinstancer_   joinitertext)r   idvaluestashs      rO   	get_stash#Pattern.unescape.<locals>.get_stash  sS    BU{		"eS)) L 775>>#344 rQ   rL   treeprocessorsstashed_nodesKeyErrorr   INLINE_PLACEHOLDER_REsubrv   textr   r   s      @rO   unescapePattern.unescape  sV    	GG**84BBE	5 ))--i>>  	K	s   #A AA)rn   rL   r^   Nr^   r_   rL   ro   )returnz
re.Pattern)r   re.Match[str]r   zetree.Element | str)r   r_   r   r_   r   r_   )rc   rd   re   rf   rg   tuplerm   rh   rw   r{   r   r   r   ri   rb   rQ   rO   rk   rk      sB    & */0
 ! " '?rQ   rk   c                  0    \ rS rSrSrSSS jjrS	S jrSrg)
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                    Xl         [        R                  " U[        R                  [        R                  -  5      U l        SU l        X l        g)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)r^   rq   rr   rs   rt   rn   	safe_moderL   ru   s      rO   rw   InlineProcessor.__init__$  s7     ::gryy2::/EF rQ   c                    g)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.

Nrb   rv   r   datas      rO   r   InlineProcessor.handleMatch5  s    & 	rQ   )rn   rL   r^   r   r   r   )r   r   r   r_   r   z9tuple[etree.Element | str | None, int | None, int | None]rc   rd   re   rf   rg   rw   r   ri   rb   rQ   rO   r   r     s    "rQ   r   c                  "    \ rS rSrSrSS jrSrg)SimpleTextPatterniK  z1Return a simple text of `group(2)` of a Pattern. c                $    UR                  S5      $ )z;Return string content of `group(2)` of a matching pattern.    )r   r~   s     rO   r   SimpleTextPattern.handleMatchM  s    wwqzrQ   rb   Nr   r   r   r_   rc   rd   re   rf   rg   r   ri   rb   rQ   rO   r   r   K  s
    <rQ   r   c                  "    \ rS rSrSrSS jrSrg)rH   iR  z1Return a simple text of `group(1)` of a Pattern. c                f    UR                  S5      UR                  S5      UR                  S5      4$ )z;Return string content of `group(1)` of a matching pattern. r   r   )r   startendr   s      rO   r   %SimpleTextInlineProcessor.handleMatchT  s'    wwqz1771:quuQx//rQ   rb   Nr   r   r   r_   r   ztuple[str, int, int]r   rb   rQ   rO   rH   rH   R  s
    <0rQ   rH   c                  "    \ rS rSrSrSS jrSrg)r3   iY  zReturn an escaped character. c                N   UR                  S5      nX0R                  R                  ;   aY  SR                  [        R
                  [        U5      [        R                  5      UR                  S5      UR                  S5      4$ SUR                  S5      UR                  S5      4$ )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   rL   ESCAPED_CHARSformatr   STXordETXr   r   )rv   r   r   chars       rO   r   !EscapeInlineProcessor.handleMatch\  su     wwqz77(((??488SYA1771:quuUVxWWQUU1X--rQ   rb   N)r   r   r   r_   r   ztuple[str | None, int, int]r   rb   rQ   rO   r3   r3   Y  s
    (.rQ   r3   c                  ,    \ rS rSrSrSS jrSS jrSrg)	SimpleTagPatternil  zQ
Return element of type `tag` with a text attribute of `group(3)`
of a Pattern.

c                :    [         R                  X5        X l        g)z
Create an instant of an simple tag pattern.

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

N)rk   rw   tagrv   r^   r   s      rO   rw   SimpleTagPattern.__init__r  s     	'0rQ   c                r    [         R                  " U R                  5      nUR                  S5      Ul        U$ )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   )rv   r   els      rO   r   SimpleTagPattern.handleMatch  s*    
 ]]488$''!*	rQ   r   Nr^   r_   r   r_   r   r   r   etree.Elementr   rb   rQ   rO   r   r   l  s    
1rQ   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)	SimpleTagInlineProcessori  zQ
Return element of type `tag` with a text attribute of `group(2)`
of a Pattern.

c                :    [         R                  X5        X l        g)z
Create an instant of an simple tag processor.

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

N)r   rw   r   r   s      rO   rw   !SimpleTagInlineProcessor.__init__  s     	  /0rQ   c                    [         R                  " U R                  5      nUR                  S5      Ul        X1R                  S5      UR                  S5      4$ )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   rv   r   r   r   s       rO   r   $SimpleTagInlineProcessor.handleMatch  s@    
 ]]488$''!*771:quuQx''rQ   r   Nr   r   r   r   r_   r   ztuple[etree.Element, int, int]r   rb   rQ   rO   r   r     s    
1(rQ   r   c                  "    \ rS rSrSrSS jrSrg)SubstituteTagPatterni  2Return an element of type `tag` with no children. c                B    [         R                  " U R                  5      $ )GReturn empty [`Element`][xml.etree.ElementTree.Element] of type `tag`. )r   r   r   r~   s     rO   r    SubstituteTagPattern.handleMatch  s    }}TXX&&rQ   rb   Nr   r   rb   rQ   rO   r   r     s
    ='rQ   r   c                  "    \ rS rSrSrSS jrSrg)rC   i  r   c                    [         R                  " U R                  5      UR                  S5      UR	                  S5      4$ )r   r   )r   r   r   r   r   r   s      rO   r   (SubstituteTagInlineProcessor.handleMatch  s,    }}TXX&
AEE!H<<rQ   rb   Nr   r   rb   rQ   rO   rC   rC     s
    ==rQ   rC   c                  ,    \ rS rSrSrSS jrSS jrSrg)	r1   i  z@Return a `<code>` element containing the escaped matching text. c                    [         R                  X5        SR                  [        R                  [        S5      [        R                  5      U l        SU l        g )Nr   \code)	r   rw   r   r   r   r   r   ESCAPED_BSLASHr   )rv   r^   s     rO   rw    BacktickInlineProcessor.__init__  s;      /&oodhhD	488L0rQ   c                   UR                  S5      (       a  [        R                  " U R                  5      n[        R
                  " [        R                  " UR                  S5      R                  5       5      5      Ul        X1R                  S5      UR                  S5      4$ UR                  S5      R                  SU R                  5      UR                  S5      UR                  S5      4$ )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.

r   r   r   z\\)r   r   r   r   r   AtomicStringcode_escapestripr   r   r   replacer   r   s       rO   r   #BacktickInlineProcessor.handleMatch  s     771::txx(B''(8(89I9I9K(LMBGwwqz1558++771:%%fd.A.ABAGGAJPQPUPUVWPXXXrQ   )r   r   N)r^   r_   )r   r   r   r_   r   z$tuple[etree.Element | str, int, int]r   rb   rQ   rO   r1   r1     s    K1YrQ   r1   c                  "    \ rS rSrSrSS jrSrg)DoubleTagPatterni  ^Return a ElementTree element nested in tag2 nested in tag1.

Useful for strong emphasis etc.

c                *   U R                   R                  S5      u  p#[        R                  " U5      n[        R                  " XC5      nUR                  S5      Ul        [        UR                  5       5      S:X  a  UR                  S5      Ul	        U$ )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)rv   r   tag1tag2el1el2s         rO   r   DoubleTagPattern.handleMatch  sk     XX^^C(
mmD!s)771:qxxz?awwqzCH
rQ   rb   Nr   r   rb   rQ   rO   r   r     s    
rQ   r   c                  "    \ rS rSrSrSS jrSrg)DoubleTagInlineProcessori  r   c                j   U R                   R                  S5      u  p4[        R                  " U5      n[        R                  " XT5      nUR                  S5      Ul        [        UR                  5       5      S:X  a  UR                  S5      Ul	        XQR                  S5      UR                  S5      4$ )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   )rv   r   r   r   r   r  r  s          rO   r   $DoubleTagInlineProcessor.handleMatch  s     XX^^C(
mmD!s)771:qxxz?awwqzCHGGAJa((rQ   rb   Nr   r   rb   rQ   rO   r  r    s    
)rQ   r  c                  6    \ rS rSrSrSS jrS	S jrS	S jrSrg)
rE   i  z0Store raw inline html and return a placeholder. c                    U R                  U R                  UR                  S5      5      5      nU R                  R                  R                  U5      nXAR                  S5      UR                  S5      4$ )zKStore the text of `group(1)` of a pattern and return a placeholder string. r   r   )backslash_unescaper   r   rL   	htmlStashstorer   r   )rv   r   r   rawhtmlplace_holders        rO   r   HtmlInlineProcessor.handleMatch  sX    ))$--
*CDww((..w7WWQZq11rQ   c                   ^ ^  T R                   R                  S   R                  mSU U4S jjn[        R
                  R                  X!5      $ ! [         a    Us $ f = f)r   r   c                   > U R                  S5      nTR                  U5      nUb   TR                  R                  U5      $ g ! [         a    SU-  s $ f = f)Nr   z\%s)r   r   rL   
serializer	Exception)r   r   r   rv   r   s      rO   r   /HtmlInlineProcessor.unescape.<locals>.get_stash  s]    BIIbME *77--e44 ! ! *!E>)*s   A AAr   r   r   s   `  @rO   r   HtmlInlineProcessor.unescape  s[    	GG**84BBE	* 	* ))--i>>  	K	s   #A AAc                     U R                   R                  S   R                  nSS jnUR	                  X15      $ ! [         a    Us $ f = f)zFReturn text with backslash escapes undone (backslashes are restored). r   c                H    [        [        U R                  S5      5      5      $ )Nr   )chrintr   )r   s    rO   	_unescape9HtmlInlineProcessor.backslash_unescape.<locals>._unescape  s    s1771:''rQ   r   )rL   r   REr   r   )rv   r   r  r  s       rO   r
  &HtmlInlineProcessor.backslash_unescape  sM    	''
366B	( vvi&&  	K	s   #; A
	A
rb   Nr   r   )	rc   rd   re   rf   rg   r   r   r
  ri   rb   rQ   rO   rE   rE     s    ;2?$
'rQ   rE   c                  X   \ rS rSrSr\" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS	5      /r SS
 jrSS jrSS jr          SS jrSS jrSS jrSrg)rJ   i  zGEmphasis processor for handling strong and em matches inside asterisks.double	strong,em	em,strongdouble2singlestrongemc                z    [         R                  " U5      nUR                  S5      nU R                  XTSU5        U$ )zReturn single tag.r   N)r   r   r   parse_sub_patterns)rv   r   r   idxr  r   s         rO   build_singleAsteriskProcessor.build_single*  s4    mmC wwqz45
rQ   c                n   UR                  S5      u  pE[        R                  " U5      n[        R                  " U5      nUR                  S5      nU R	                  XSU5        UR                  U5        [        UR                  5       5      S:X  a#  UR                  S5      nU R	                  XXs5        U$ )zReturn double tag.r   r   Nr   )r   r   r   r   r'  appendr   r   	rv   r   ra   r(  r   r   r  r  r   s	            rO   build_doubleAsteriskProcessor.build_double1  s     ZZ_
mmD!mmD!wwqz45

3qxxz?a771:D##Ds8
rQ   c                6   UR                  S5      u  pE[        R                  " U5      n[        R                  " U5      nUR                  S5      nU R	                  XSU5        UR                  S5      nUR                  U5        U R	                  XSU5        U$ )zFReturn double tags (variant 2): `<strong>text <em>text</em></strong>`.r   r   Nr   )r   r   r   r   r'  r,  r-  s	            rO   build_double2AsteriskProcessor.build_double2?  s}     ZZ_
mmD!mmD!wwqz45wwqz

345
rQ   c                \   SnSn[        U5      nXg:  a  U R                  R                  X5      (       a  Sn[        U R                  5       H  u  pX::  a  M  U
R
                  R                  X5      nU(       d  M0  XUR                  S5       nU(       a  Ub  Xl        OXl        U R                  XR                  U
R                  U	5      nUR                  U5        UnUR                  S5      =pVSnM     U(       d  US-  nOUS-  nXg:  a  M  XS nU(       a  Ub  Xl        gXl        gg)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.
r   FNTr   )r   rn   match	enumeratePATTERNSr^   r   r   r   build_elementr`   ra   r,  r   )rv   r   parentlastr(  offsetposlengthmatchedindexitemr   r   r   s                 rO   r'  $AsteriskProcessor.parse_sub_patternsL  s    Tl%%d00#,T]]#;KE| **45Aq
  $1771:6#/,0	.2!//<<ERb)!'(uuQx/"&+ $<, 1HC qA lF G} 	"	 rQ   c                    US:X  a  U R                  XU5      $ US:X  a  U R                  XU5      $ U R                  XU5      $ )zElement builder.r"  r  )r1  r.  r)  )rv   r   r`   ra   r>  s        rO   r7  AsteriskProcessor.build_element  sM     i%%au55 $$Qe44$$Qe44rQ   c                J   SnSnSn[        U R                  5       H  u  pgUR                  R                  X!R	                  S5      5      nU(       d  M8  UR	                  S5      nUR                  S5      nU R                  XR                  UR                  U5      n  O   X4U4$ )zParse patterns.Nr   )	r5  r6  r^   r4  r   r   r7  r`   ra   )	rv   r   r   r   r   r   r>  r?  m1s	            rO   r   AsteriskProcessor.handleMatch  s     $T]]3KE##D''!*5BrffQi''LL$))UK 4 #~rQ   rb   N)r   r   r   r_   r(  r  r   r   )r   r   ra   r_   r(  r  r   r   )
r   r_   r8  r   r9  zetree.Element | Noner(  r  r   None)
r   r   r`   r_   ra   r_   r>  r  r   r   r   r   r   r_   r   z3tuple[etree.Element | None, int | None, int | None])rc   rd   re   rf   rg   r[   rq   rr   EM_STRONG_RErs   rt   STRONG_EM_RESTRONG_EM3_RE	STRONG_REEMPHASIS_REr6  r)  r.  r1  r'  r7  r   ri   rb   rQ   rO   rJ   rJ     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;#;#!.;#6J;#QT;#	;#z5rQ   rJ   c                     \ rS rSrSr\" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS5      \" \R                  " \\R                  \R                  -  5      SS	5      /rS
rg)rK   i  zIEmphasis processor for handling strong and em matches inside underscores.r  r   r!  r"  r#  r$  r%  rb   N)rc   rd   re   rf   rg   r[   rq   rr   EM_STRONG2_RErs   rt   STRONG_EM2_RESMART_STRONG_EM_RESMART_STRONG_RESMART_EMPHASIS_REr6  ri   rb   rQ   rO   rK   rK     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rQ   rK   c                      \ rS rSrSr\R                  " S\R                  \R                  -  5      r	\R                  " S5      r
S
S jrSS jrSS jrSrg	)r7   i  z,Return a link element from the given match. z2\(\s*(?:(<[^<>]*>)\s*(?:('[^']*'|"[^"]*")\s*)?\))?z\sc                <   U R                  X!R                  S5      5      u  p4nU(       d  gU R                  X$5      u  pgpEU(       d  g[        R                  " S5      nX8l        UR                  SU5        Ub  UR                  SU5        XR                  S5      U4$ )zRReturn an `a` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. r   NNNahreftitle)getTextr   getLinkr   r   r   setr   )	rv   r   r   r   r>  handledrW  rX  r   s	            rO   r   LinkInlineProcessor.handleMatch  s    #||D%%(;W#&*ll4&?#U#]]3
vtFF7E"771:u$$rQ   c           	     6   SnSnSnU R                   R                  XS9nU(       aw  UR                  S5      (       aa  UR                  S5      SS R                  5       nUR                  S5      (       a  UR                  S5      SS nUR	                  S5      nS	nGOU(       Ga  SnSnUR	                  5       n	U	nSn
SnSnSnSnSnSnSnSn[        U[        U5      5       GH/  nUU   nUS
:X  a  U(       d  US-  nOUS:  a  US-  nOUS:X  a?  US:w  a  UU:X  d  US:w  a	  UU:X  a  SnOrU(       d  US-  nOeUS:  a  US-  nUS:X  a  US-   n
ONUS;   aH  U(       d  S	nUnSnUS-   nUnO3UU:w  a  U(       d  US-   nUnOUU:X  a  US-   nOU(       a  UU:X  a  US-   nUS-  nUS:X  a^  US:  a$  UU:X  a  XUS-
   nSR                  XUS-
   5      nO2US:  a%  UU:X  a  XUS-
   nSR                  UUUS-
   5      nOXUS-
   n  OUS:w  d  GM-  UnGM2     US:w  a  US:X  a  XU
S-
   nU
nSnUS:H  nUbB  U R                  R                  S[        U R                  UR                  5       5      5      5      nU R                  U5      R                  5       nX4X%4$ )z?Parse data between `()` of `[Text]()` allowing recursive `()`. r   NFr;  r   rU   r   r   T())rT   rS    )RE_LINKr4  r   r   r   ranger   r   RE_TITLE_CLEANr   rY   r   )rv   r   r>  rW  rX  r\  r   bracket_countbacktrack_countstart_indexlast_bracketquotestart_quote
exit_quoteignore_matches	alt_quotestart_alt_quoteexit_alt_quoter9  r;  cs                        rO   rZ  LinkInlineProcessor.getLink  s     LLt/771:a#))+Dwwqzz
1R(EE!HEG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**rQ   c                    Sn/ n[        U[        U5      5       H<  nX   nUS:X  a  US-  nOUS:X  a  US-  nUS-  nUS:X  a    OUR                  U5        M>     SR                  U5      X#S:H  4$ )zcParse the content between `[]` of the start of an image or link
resolving nested square brackets.

r   ][r   r   )rd  r   r,  r   )rv   r   r>  rf  r   r;  rq  s          rO   rY  LinkInlineProcessor.getText?  s    
 D	*C	ACx"c"QJE!KKN + wwt}ea%777rQ   rb   NrG  )r   r_   r>  r  r   z!tuple[str, str | None, int, bool])r   r_   r>  r  r   tuple[str, int, bool])rc   rd   re   rf   rg   rq   rr   rs   rt   rc  re  r   rZ  rY  ri   rb   rQ   rO   r7   r7     sH    7jjRTVT]T]`b`j`jTjkGZZ&N%*r+h8rQ   r7   c                  "    \ rS rSrSrSS jrSrg)r9   iS  z-Return a `img` element from the given match. c                r   U R                  X!R                  S5      5      u  p4nU(       d  gU R                  X$5      u  pgpEU(       d  g[        R                  " S5      nUR                  SU5        Ub  UR                  SU5        UR                  SU R                  U5      5        XR                  S5      U4$ )zTReturn an `img` [`Element`][xml.etree.ElementTree.Element] or `(None, None, None)`. r   rU  imgsrcrX  alt)rY  r   rZ  r   r   r[  r   r   )	rv   r   r   r   r>  r\  r{  rX  r   s	            rO   r    ImageInlineProcessor.handleMatchV  s    #||D%%(;W#%)\\$%>"E#]]5!
ucFF7E"
udmmD)*771:u$$rQ   rb   NrG  r   rb   rQ   rO   r9   r9   S  s
    8%rQ   r9   c                      \ rS rSrSr\R                  " S\R                  5      r\R                  " S\R                  \R                  -  5      rS
S jrSS jrSS jrSrg	)r5   ik  z5Match to a stored reference and return link element. z\s+z\s?\[([^\]]*)\]c                   U R                  X!R                  S5      5      u  p4nU(       d  gU R                  X$U5      u  pgnU(       d  gU R                  R	                  SU5      nX`R
                  R                  ;  a  SUR                  S5      U4$ U R
                  R                  U   u  pU R                  XU5      UR                  S5      U4$ )zj
Return [`Element`][xml.etree.ElementTree.Element] returned by `makeTag` method or `(None, None, None)`.

r   rU  rb  N)	rY  r   evalIdNEWLINE_CLEANUP_REr   rL   
referencesr   makeTag)
rv   r   r   r   r>  r\  r   r   rW  rX  s
             rO   r   $ReferenceInlineProcessor.handleMatchq  s    
  $||D%%(;W#;;tD9# $$((b1WW'''S((gg((,||D.
C??rQ   c                    U R                   R                  XS9nU(       d  SUS4$ UR                  S5      R                  5       nUR	                  S5      nU(       d  UR                  5       nXVS4$ )zD
Evaluate the id portion of `[ref][id]`.

If `[ref][]` use `[ref]`.
r_  NFr   r   T)rc  r4  r   lowerr   )rv   r   r>  r   r   r   r   s          rO   r  ReferenceInlineProcessor.evalId  sf     LLt/%%!!#B%%(CZZ\}rQ   c                    [         R                  " S5      nUR                  SU5        U(       a  UR                  SU5        X4l        U$ )z:Return an `a` [`Element`][xml.etree.ElementTree.Element]. rV  rW  rX  )r   r   r[  r   rv   rW  rX  r   r   s        rO   r   ReferenceInlineProcessor.makeTag  s9    ]]3
vtFF7E"	rQ   rb   NrG  )r   r_   r>  r  r   r_   r   ztuple[str | None, int, bool]rW  r_   rX  r_   r   r_   r   r   )rc   rd   re   rf   rg   rq   rr   	MULTILINEr  rs   rt   rc  r   r  r  ri   rb   rQ   rO   r5   r5   k  sH    @FBLL9jj+RYY-CDG@, 	rQ   r5   c                  "    \ rS rSrSrSS jrSrg)r=   i  z%Short form of reference: `[google]`. c                (    UR                  5       US4$ zEvaluate the id of `[ref]`.  Tr  rv   r   r>  r   s       rO   r  $ShortReferenceInlineProcessor.evalId       zz|UD((rQ   rb   Nr   r_   r>  r  r   r_   r   rw  rc   rd   re   rf   rg   r  ri   rb   rQ   rO   r=   r=     s
    /)rQ   r=   c                  "    \ rS rSrSrSS jrSrg)r;   i  z6Match to a stored reference and return `img` element. c                    [         R                  " S5      nUR                  SU5        U(       a  UR                  SU5        UR                  SU R                  U5      5        U$ )z<Return an `img` [`Element`][xml.etree.ElementTree.Element]. rz  r{  rX  r|  )r   r   r[  r   r  s        rO   r  %ImageReferenceInlineProcessor.makeTag  sK    ]]5!
udFF7E"
udmmD)*	rQ   rb   Nr  )rc   rd   re   rf   rg   r  ri   rb   rQ   rO   r;   r;     s
    ArQ   r;   c                  "    \ rS rSrSrSS jrSrg)r>   i  z)Short form of image reference: `![ref]`. c                (    UR                  5       US4$ r  r  r  s       rO   r  )ShortImageReferenceInlineProcessor.evalId  r  rQ   rb   Nr  r  rb   rQ   rO   r>   r>     s
    4)rQ   r>   c                  "    \ rS rSrSrSS jrSrg)r?   i  zCReturn a link Element given an auto-link (`<http://example/com>`). c                &   [         R                  " S5      nUR                  SU R                  UR	                  S5      5      5        [
        R                  " UR	                  S5      5      Ul        X1R                  S5      UR                  S5      4$ )zHReturn an `a` [`Element`][xml.etree.ElementTree.Element] of `group(1)`. rV  rW  r   r   )
r   r   r[  r   r   r   r   r   r   r   r   s       rO   r   #AutolinkInlineProcessor.handleMatch  sd    ]]3
vt}}QWWQZ01##AGGAJ/771:quuQx''rQ   rb   Nr   r   rb   rQ   rO   r?   r?     s
    N(rQ   r?   c                  "    \ rS rSrSrSS jrSrg)rA   i  zO
Return a `mailto` link Element given an auto-mail link (`<foo@example.com>`).
c           
     X   [         R                  " S5      nU R                  UR                  S5      5      nUR	                  S5      (       a  U[        S5      S nS
S jnU Vs/ s H  oe" [        U5      5      PM     nn[        R                  " SR                  U5      5      Ul
        SU-   nSR                  U Vs/ s H"  n[        R                  S[        U5      -  -   PM$     sn5      nUR                  SU5        X1R                  S	5      UR                  S	5      4$ s  snf s  snf )z`Return an [`Element`][xml.etree.ElementTree.Element] containing a `mailto` link  of `group(1)`. rV  r   zmailto:Nc                    [         R                  R                  U 5      nU(       a   SR                  [        R
                  U5      $ S[        R
                  U 4-  $ )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     rO   r  ;AutomailInlineProcessor.handleMatch.<locals>.codepoint2name  sH    ,,006F~~d&9&96BB4#6#6"===rQ   r   z#%d;rW  r   )r   r  r   r_   )r   r   r   r   rV   r   r   r   r   r   r   r  r[  r   r   )	rv   r   r   r   emailr  letterlettersmailtos	            rO   r   #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">)D'rb   Nr   r   rb   rQ   rO   rA   rA     s    (rQ   rA   )rL   r   rM   r   r   zutil.Registry[InlineProcessor])rX   r_   r   r_   )Crg   
__future__r   r   r   typingr   r   r   r	   rq   xml.etree.ElementTreer   ElementTreer$   r
   markdownr   rP   NOIMGr2   r4   rL  rK  rQ  rR  rP  rH  rN  rI  rO  rJ  r8   r:   r6   r<   rI   r@   rB   rF   rG   rD   rY   r[   rk   r   r   rH   r3   r   r   r   rC   r1   r   r  rE   rJ   rK   r7   r9   r5   r=   r;   r>   r?   rA   rb   rQ   rO   <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 )*$'/ $'NC CL
P+ 
P_8/ _8D%. %052 5p)$< )	$< 	))F )(o ((o (rQ   