
    iC                    "   S r SSKJr  SSKrSSKrSSKrSSKJrJ	r	  \(       a  SSK
Jr  \R                  " S5      r\R                  R                  S5      r\R                  R#                  \5      r\R&                  R)                  \5        \\R*                  S'   \R                  " S	5      \l        \R                  " S
5      \l        \R                  " S5      \l        \R                  " S5      \l        \R2                  \l        \R                  " S\R6                  5      \l        \R                  " S\R6                  5      \l        \R                  " S5      r " S S\R>                  5      r \ \l         " S S\R>                  5      r!g)a  
This module imports a copy of [`html.parser.HTMLParser`][] and modifies it heavily through monkey-patches.
A copy is imported rather than the module being directly imported as this ensures that the user can import
and  use the unmodified library for their own needs.
    )annotationsN)TYPE_CHECKINGSequence)Markdownz--!?>zhtml.parser
htmlparserz<[a-zA-Z]|</>z</[a-zA-Z]?z\?>z&([a-zA-Z][-.a-zA-Z0-9]*);a  
  <[a-zA-Z][^`\t\n\r\f />\x00]*       # tag name <= added backtick here
  (?:[\s/]*                           # optional whitespace before attribute name
    (?:(?<=['"\s/])[^`\s/>][^\s/=>]*  # attribute name <= added backtick here
      (?:\s*=+\s*                     # value indicator
        (?:'[^']*'                    # LITA-enclosed value
          |"[^"]*"                    # LIT-enclosed value
          |(?!['"])[^`>\s]*           # bare value <= added backtick here
         )
         (?:\s*,)*                    # possibly followed by a comma
       )?(?:\s|/(?!>))*
     )*
   )?
  \s*                                 # trailing whitespace
a  
  [a-zA-Z][^`\t\n\r\f />]*           # tag name
  [\t\n\r\f /]*                     # optional whitespace before attribute name
  (?:(?<=['"\t\n\r\f /])[^`\t\n\r\f />][^\t\n\r\f /=>]*  # attribute name
    (?:=                            # value indicator
      (?:'[^']*'                    # LITA-enclosed value
        |"[^"]*"                    # LIT-enclosed value
        |(?!['"])[^>\t\n\r\f ]*     # bare value
       )
     )?
    [\t\n\r\f /]*                   # possibly followed by a space
   )*
   >?
z^([ ]*\n){2}c                  <   ^  \ rS rSrSrU 4S jrSU 4S jjrSrU =r$ )_HTMLParser`   z"Handle special start and end tags.c                  > U R                   XS-    n[        US   5      n[        U5      S:  d  SUs=::  a  S::  d6  O  SUs=::  a  S::  d'  O  U R                  U R                   XS-    5        US-   $ [        TU ]  U5      $ )N   A   Z   a   z      )rawdataordlenhandle_datasuperparse_endtag)selfistartc	__class__s       E/var/www/ias/venv/lib/python3.13/site-packages/markdown/htmlparser.pyr   _HTMLParser.parse_endtagc   su    Qs#b	Nu:>"-R-2>c>T\\!E23q5Lw#A&&    c                   > U R                   XS-    S:X  a%  U R                  U R                   XS-    5        US-   $ [        TU ]  U5      $ )Nr   </>)r   r   r   parse_starttagr   r   r   s     r   r#   _HTMLParser.parse_starttagk   sL    <<a% E)T\\!E23q5Lw%a((r     r   intreturnr(   )	__name__
__module____qualname____firstlineno____doc__r   r#   __static_attributes____classcell__r   s   @r   r	   r	   `   s    ,') )r    r	   c                  @  ^  \ rS rSr% SrSU 4S jjrU 4S jrU 4S jr\SS j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#S j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'U 4S jjrS(S jrS'U 4S jjrS)S*U 4S jjjrSrS\S'   S+S jrS'S jrSrU =r $ ),HTMLExtractorx   z
Extract raw HTML from text.

The raw HTML is stored in the [`htmlStash`][markdown.util.HtmlStash] of the
[`Markdown`][markdown.Markdown] instance passed to `md` and the remaining text
is stored in `cleandoc` as a list of strings.
c                z   > SU;  a  SUS'   [        S/5      U l        S/U l        [        TU ]  " U0 UD6  Xl        g )Nconvert_charrefsFhrr   )set
empty_tagslineno_start_cacher   __init__md)r   r<   argskwargsr   s       r   r;   HTMLExtractor.__init__   sH    V+).F%& tf+#$# 	$)&)r    c                x   > SU l         SU l        / U l        / U l        / U l        S/U l        [        TU ]  5         g)z1Reset this instance.  Loses all unprocessed data.Fr   N)inrawintailstack_cachecleandocr:   r   resetr   r   s    r   rF   HTMLExtractor.reset   s9    
 "
!##%#$#r    c                   > [         TU ]  5         [        U R                  5      (       al  U R                  (       a@  U R
                  (       d/  U R                  [        R                  U R                  5      5        OU R                  U R                  5        [        U R                  5      (       a_  U R                  R                  U R                  R                  R                  SR                  U R                  5      5      5        / U l	        gg)zHandle any buffered data. N)r   closer   r   r6   
cdata_elemr   r   unescaperD   rE   appendr<   	htmlStashstorejoinrG   s    r   rK   HTMLExtractor.close   s    t|| $$T__  !4!4T\\!BC  .t{{MM  !2!2!8!89M!NODK r    c                n   [        [        U R                  5      S-
  U R                  S-
  5       Hg  nU R                  U   nU R                  R                  SU5      nUS:X  a  [        U R                  5      nU R                  R                  US-   5        Mi     U R                  U R                  S-
     $ )zHReturns char index in `self.rawdata` for the start of the current line.    
r   )ranger   r:   linenor   findrN   )r   iilast_line_start_poslf_poss       r   line_offsetHTMLExtractor.line_offset   s     D334Q6AFB"&"9"9""=\\&&t-@AF|T\\*##**6!84 G &&t{{1}55r    c                    U R                   S:X  a  gU R                   S:  a  gU R                  U R                  U R                  U R                   -    R                  5       S:H  $ )zn
Returns True if current position is at start of line.

Allows for up to three blank spaces at start of line.
r   Tr   FrJ   )offsetr   r\   stripr   s    r   at_line_startHTMLExtractor.at_line_start   sV     ;;!;;?||D,,T-=-=-KLRRTXZZZr    c                    U R                   U R                  -   n[        R                  R	                  U R
                  U5      nU(       a  U R
                  X#R                  5        $ SR                  U5      $ )z
Returns the text of the end tag.

If it fails to extract the actual text from the raw data, it builds a closing tag with `tag`.
z</{}>)r\   r_   r   	endendtagsearchr   endformat)r   tagr   ms       r   get_endtag_textHTMLExtractor.get_endtag_text   s]       4;;.  ''e<<<eeg.. >>#&&r    c                ^   XR                   ;   a  U R                  X5        g U R                  R                  U5      (       aY  U R                  (       d&  U R                  5       (       a3  U R                  (       d"  SU l        U R                  R                  S5        U R                  5       nU R                  (       a7  U R                  R                  U5        U R                  R                  U5        g U R                  R                  U5        XR                  ;   a  U R                  5         g g )NTrU   )r9   handle_startendtagr<   is_block_levelrB   rb   rA   rE   rN   get_starttag_textrC   rD   CDATA_CONTENT_ELEMENTSclear_cdata_mode)r   ri   attrstexts       r   handle_starttagHTMLExtractor.handle_starttag   s    //!##C/77!!#&&DKKD<N<N<P<PY]YcYcDJMM  &%%'::JJc"KKt$MM  &111%%' 2r    c                j   U R                  U5      nU R                  (       Gau  U R                  R                  U5        XR                  ;   aC  U R                  (       a2  U R                  R                  5       U:X  a  OU R                  (       a  M2  [        U R                  5      S:X  a  [        R                  U R                  U R                  U R                  -   [        U5      -   S  5      (       a  U R                  R                  S5        OSU l        SU l        U R                  R                  U R                  R                  R!                  SR#                  U R                  5      5      5        U R                  R                  S5        / U l        g g U R                  R                  U5        g )Nr   rU   TFrJ   

)rk   rA   rD   rN   rC   popr   blank_line_rematchr   r\   r_   rB   rE   r<   rO   rP   rQ   )r   ri   rt   s      r   handle_endtagHTMLExtractor.handle_endtag   s1   ##C(:::KKt$jj jjzz~~'3. jjj 4::!# &&t||D4D4Dt{{4RUXY]U^4^4_'`aaKK&&t, #'DK"
$$TWW%6%6%<%<RWWT[[=Q%RS$$V,  $ MM  &r    c                    U R                   (       a  SU;   a  SU l         U R                  (       a  U R                  R                  U5        g U R                  R                  U5        g )NrU   F)rB   rA   rD   rN   rE   r   datas     r   r   HTMLExtractor.handle_data  sA    ;;44<DK::KKt$MM  &r    c                &   U R                   (       d  U R                  (       a  U R                  R                  U5        gU R	                  5       (       Ga"  U(       Ga  [
        R                  U R                  U R                  U R                  -   [        U5      -   S 5      (       a  US-  nOSU l        U R                  (       a  U R                  S   OSnUR                  S5      (       d1  UR                  S5      (       a  U R                  R                  S5        U R                  R                  U R                  R                  R                  U5      5        U R                  R                  S5        gU R                  R                  U5        g)zHandle empty tags (`<data>`). NrU   Tr   rJ   rx   )rA   rB   rD   rN   rb   rz   r{   r   r\   r_   r   rE   endswithr<   rO   rP   )r   r   is_blockitems       r   handle_empty_tagHTMLExtractor.handle_empty_tag	  s   ::KKt$!!h""4<<0@0@4;;0NQTUYQZ0Z0[#\]] #(,4==$2D==((T]]4-@-@$$T*MM  !2!2!8!8!>?MM  (MM  &r    c                r    U R                  U R                  5       U R                  R                  U5      S9  g )Nr   )r   rp   r<   ro   )r   ri   rs   s      r   rn    HTMLExtractor.handle_startendtag   s.    d446AWAWX[A\]r    c                B    U R                  SR                  U5      SS9  g )Nz&#{};Fr   r   rh   r   names     r   handle_charrefHTMLExtractor.handle_charref#  s    gnnT2UCr    c                B    U R                  SR                  U5      SS9  g )Nz&{};Fr   r   r   s     r   handle_entityrefHTMLExtractor.handle_entityref&  s    fmmD1EBr    c                B    U R                  SR                  U5      SS9  g )Nz	<!--{}-->Tr   r   r   s     r   handle_commentHTMLExtractor.handle_comment)  s     k006Fr    c                B    U R                  SR                  U5      SS9  g )Nz<!{}>Tr   r   r   s     r   handle_declHTMLExtractor.handle_decl-  s    gnnT2TBr    c                B    U R                  SR                  U5      SS9  g )Nz<?{}?>Tr   r   r   s     r   	handle_piHTMLExtractor.handle_pi0  s    hood3dCr    c                v    UR                  S5      (       a  SOSnU R                  SR                  X5      SS9  g )NzCDATA[z]]>z]>z<![{}{}Tr   )
startswithr   rh   )r   r   rg   s      r   unknown_declHTMLExtractor.unknown_decl3  s5    x00edi..t9DIr    c                   > U R                  5       (       d  U R                  (       a  [        TU ]  U5      $ U R	                  S5        US-   $ )Nz<?r   )rb   rB   r   parse_pir   r$   s     r   r   HTMLExtractor.parse_pi7  sA    4;;7#A&& 	1ur    c                :   U R                   nUR                  SU5      (       d   S5       e[        R                  X1S-   5      nU(       d  U R	                  S5        US-   $ U(       a&  UR                  5       nU R                  X1S-   U 5        UR                  5       $ )Nz<!--z"unexpected call to parse_comment()   <rT   )r   r   commentcloserf   r   r   r   rg   )r   r   reportr   r{   js         r   parse_commentHTMLExtractor.parse_commentA  s    ,,!!&!,,R.RR,##GqS1S!q5LA!Q0yy{r    c                j  > U R                  5       (       d  U R                  (       aw  U R                  XS-    S:X  aS  U R                  XS-    S:X  d>  U R                  U5      nUS:X  a%  U R	                  U R                  XS-    5        US-   $ U$ [
        TU ]  U5      $ U R	                  S5        US-   $ )	Nr   z<![	   z	<![CDATA[r   rT   z<!r   )rb   rB   r   parse_bogus_commentr   r   parse_html_declaration)r   r   resultr   s      r   r   $HTMLExtractor.parse_html_declarationM  s    4;;||Ac"e+DLLQ34G;4V 11!4R<$$T\\!E%:;q5L71!44 	1ur    c                l   > [         TU ]  X5      nUS:X  a  gU R                  U R                  X SS9  U$ )Nr   Fr   )r   r   r   r   )r   r   r   posr   s       r   r   !HTMLExtractor.parse_bogus_comment]  s?     g)!4"9dll11EB
r    Nz
str | None_HTMLExtractor__starttag_textc                    U R                   $ )z)Return full source of start tag: `<...>`.)r   ra   s    r   rp   HTMLExtractor.get_starttag_textl  s    ###r    c                   U R                   XS-    S:X  a%  U R                  U R                   XS-    5        US-   $ S U l        U R                  U5      nUS:  a%  U R                  U R                   XS-    5        US-   $ U R                   nX1U U l        / n[        R
                  R                  X1S-   5      nU(       d   S5       eUR                  5       nUR                  S5      R                  5       =U l
        nXb:  a  [        R                  R                  X65      nU(       d  OUR                  SSS5      u  pnU
(       d  S nO0US S Ss=:X  a	  USS  :X  d  O  US S S	s=:X  a	  USS  :X  a  O  OUSS nU(       a  [        R                  U5      nUR                  U	R                  5       U45        UR                  5       nXb:  a  M  X6U R                  5       nUS
;  a  U R                  5       u  pSU R                  ;   aO  XR                  R!                  S5      -   n[#        U R                  5      U R                  R%                  S5      -
  nOU[#        U R                  5      -   nU R                  X1U 5        U$ UR'                  S5      (       a  U R)                  Xt5        U$ XpR*                  ;   a  U R-                  U5        U R/                  Xt5        U$ )Nr   r"   r   rT   z#unexpected call to parse_starttag()r   'r   ")>/>rU   r   )r   r   r   check_for_whole_start_tagr   tagfind_tolerantr{   rg   grouplowerlasttagattrfind_tolerantrM   rN   r`   getposcountr   rfindr   rn   rq   set_cdata_moderu   )r   r   endposr   rs   r{   kri   rj   attrnamerest	attrvaluerg   rW   r_   s                  r   r#   HTMLExtractor.parse_starttagp  s   <<a% E)T\\!E23q5L#//2A:T\\!E23q5L,,&0 ++11'Q3?;;;uIIK"[[^1133sj,,227>A()1a(8%HI 	2A$8)BC.82A#7237%aO	&//	:	LL(..*I67A j %%'k!![[]NFt+++"6"6"<"<T"BBT112//55d;<  #d&:&:";;Wv./M<<##C/  111##C(  ,r    )
__starttag_textrD   rE   r9   rA   rB   r   r:   r<   rC   )r<   r   )r)   r(   )r)   bool)ri   strr)   r   )ri   r   rs   zSequence[tuple[str, str]])ri   r   )r   r   )r   r   r   r   )r   r   r'   )T)r   )r   r(   r   r(   r)   r(   )r)   r   )!r*   r+   r,   r-   r.   r;   rF   rK   propertyr\   rb   rk   ru   r|   r   r   rn   r   r   r   r   r   r   r   r   r   r   r   __annotations__rp   r#   r/   r0   r1   s   @r   r3   r3   x   s    	 
6 
6['(*'6''.^DCGCDJ
   #'OZ&$6 6r    r3   )"r.   
__future__r   reimportlib.util	importlibsystypingr   r   markdownr   compiler   util	find_specspecmodule_from_specr   loaderexec_modulemodulesstarttagopen
endtagopenpiclose	entityref
incompleteVERBOSElocatestarttagend_tolerantlocatetagendrz   
HTMLParserr	   r3   r&   r    r   <module>r      sT  ( # 	  
 *! zz(# ~~.^^,,T2
   
 #&L  **_5
 

=1
  ZZ'
 zz"?@
  #,,
 (*

 4 ZZ)
 % ** & ZZ
 " 

?+)*'' )* $
 nJ)) nr    