
    c2                        d Z ddlZddlZddlZej                            d          Zej                            e          Z	ej
                            e	           e	ej        d<    ej        d          e	_         ej        d          e	_        e	j        e	_         ej        dej                  e	_         ej        d          Z G d	 d
e	j                  ZdS )a  
Python Markdown

A Python implementation of John Gruber's Markdown.

Documentation: https://python-markdown.github.io/
GitHub: https://github.com/Python-Markdown/markdown/
PyPI: https://pypi.org/project/Markdown/

Started by Manfred Stienstra (http://www.dwerg.net/).
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
Currently maintained by Waylan Limberg (https://github.com/waylan),
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).

Copyright 2007-2020 The Python Markdown Project (v. 1.7 and later)
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
Copyright 2004 Manfred Stienstra (the original version)

License: BSD (see LICENSE.md for details).
    Nzhtml.parser
htmlparserz\?>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
z^([ ]*\n){2}c                        e Zd ZdZ fdZ fdZ fdZed             Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Z fdZ fdZdZd Zd Z xZS )HTMLExtractorz
    Extract raw HTML from text.

    The raw HTML is stored in the `htmlStash` of the Markdown instance passed
    to `md` and the remaining text is stored in `cleandoc` as a list of strings.
    c                     d|vrd|d<   t          dg          | _         t                      j        |i | || _        d S )Nconvert_charrefsFhr)set
empty_tagssuper__init__md)selfr   argskwargs	__class__s       3lib/python3.11/site-packages/markdown/htmlparser.pyr   zHTMLExtractor.__init__H   sU    V+ 	/).F%& tf++ 	$)&)))    c                     d| _         d| _        g | _        g | _        g | _        t                                                       dS )z1Reset this instance.  Loses all unprocessed data.FN)inrawintailstack_cachecleandocr   resetr   r   s    r   r   zHTMLExtractor.resetS   s;    

r   c                    t                                                       t          | j                  r[| j        r:| j        s3|                     t                              | j                             n|                     | j                   t          | j	                  rX| j
                            | j        j                            d                    | j	                                       g | _	        dS dS )zHandle any buffered data. N)r   closelenrawdatar   
cdata_elemhandle_datar   unescaper   r   appendr   	htmlStashstorejoinr   s    r   r   zHTMLExtractor.close\   s    t| 	/ $ /T_ /  !4!4T\!B!BCCCC  ...t{ 	M  !2!8!89M9M!N!NOOODKKK	 	r   c                     | j         dk    rnd| j        v ret          j        d                    | j         dz
            | j                  }|r|                                S | j                            d          S dS )zFReturns char index in self.rawdata for the start of the current line.    
z([^\n]*\n){{{}}}r   )linenor    rematchformatendrfind)r   ms     r   line_offsetzHTMLExtractor.line_offsetk   sz     ;? 	0tt|3 	0,33DKMBBDLQQA 0uuww |))$///qr   c                     | j         dk    rdS | j         dk    rdS | j        | j        | j        | j         z                                            dk    S )z
        Returns True if current position is at start of line.

        Allows for up to three blank spaces at start of line.
        r   T   Fr   )offsetr    r2   stripr   s    r   at_line_startzHTMLExtractor.at_line_startx   s\     ;! 	4;? 	5|D,T-=-KKLRRTTXZZZr   c                     | j         | j        z   }t          j                            | j        |          }|r!| j        ||                                         S d                    |          S )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</{}>)r2   r5   r   	endendtagsearchr    r/   r.   )r   tagstartr1   s       r   get_endtag_textzHTMLExtractor.get_endtag_text   sb      4;. ''e<< 	'<aeegg.. >>#&&&r   c                    || j         v r|                     ||           d S | j                            |          rC| j        s|                                 r(| j        s!d| _        | j                            d           | 	                                }| j        r6| j
                            |           | j                            |           d S | j                            |           || j        v r|                                  d S d S )NTr*   )r
   handle_startendtagr   is_block_levelr   r8   r   r   r$   get_starttag_textr   r   CDATA_CONTENT_ELEMENTSclear_cdata_mode)r   r<   attrstexts       r   handle_starttagzHTMLExtractor.handle_starttag   s   $/! 	##C///F7!!#&& 	'DK 	'D<N<N<P<P 	'Y]Yc 	'DJM  &&&%%'': 	(Jc"""Kt$$$$$M  &&&d11 (%%'''''( (r   c                    |                      |          }| j        rH| j                            |           || j        v r,| j        r%| j                                        |k    rn| j        %t          | j                  dk    rt                              | j	        | j
        | j        z   t          |          z   d                    r| j                            d           nd| _        d| _        | j                            | j        j                            d                    | j                                       | j                            d           g | _        d S d S | j                            |           d S )Nr   r*   TFr   

)r>   r   r   r$   r   popr   blank_line_rer-   r    r2   r5   r   r   r   r%   r&   r'   )r   r<   rF   s      r   handle_endtagzHTMLExtractor.handle_endtag   sr   ##C((: 	'Kt$$$dj  j z~~''3.  j  4:!# ! &&t|D4Dt{4RUXY]U^U^4^4_4_'`aa 'K&&t,,,, #'DK"
$$TW%6%<%<RWWT[=Q=Q%R%RSSS$$V,,, ! ! M  &&&&&r   c                     | j         rd|v rd| _         | j        r| j                            |           d S | j                            |           d S )Nr*   F)r   r   r   r$   r   r   datas     r   r"   zHTMLExtractor.handle_data   s`    ; 	 44< 	 DK: 	'Kt$$$$$M  &&&&&r   c                    | j         s| j        r| j                            |           dS |                                 r |rt
                              | j        | j        | j	        z   t          |          z   d                   r|dz  }nd| _        | j        r| j        d         nd}|                    d          s/|                    d          r| j                            d           | j                            | j        j                            |                     | j                            d           dS | j                            |           dS )z Handle empty tags (`<data>`). Nr*   Tr   rI   )r   r   r   r$   r8   rK   r-   r    r2   r5   r   r   endswithr   r%   r&   )r   rO   is_blockitems       r   handle_empty_tagzHTMLExtractor.handle_empty_tag   sR   : 	' 	'Kt$$$$$!! 	'h 	'""4<0@4;0NQTUYQZQZ0Z0[0[#\]] # #(,=4=$$2D==(( +T]]4-@-@ +$$T***M  !2!8!8!>!>???M  (((((M  &&&&&r   c                     |                      |                                 | j                            |                     d S )NrS   )rU   rB   r   rA   )r   r<   rE   s      r   r@   z HTMLExtractor.handle_startendtag   s>    d4466AWAWX[A\A\]]]]]r   c                 Z    |                      d                    |          d           d S )Nz&#{};FrW   rU   r.   r   names     r   handle_charrefzHTMLExtractor.handle_charref   s-    gnnT22UCCCCCr   c                 Z    |                      d                    |          d           d S )Nz&{};FrW   rY   rZ   s     r   handle_entityrefzHTMLExtractor.handle_entityref   s-    fmmD11EBBBBBr   c                 Z    |                      d                    |          d           d S )Nz	<!--{}-->TrW   rY   rN   s     r   handle_commentzHTMLExtractor.handle_comment   s/    k0066FFFFFr   c                 Z    |                      d                    |          d           d S )Nz<!{}>TrW   rY   rN   s     r   handle_declzHTMLExtractor.handle_decl   s-    gnnT22TBBBBBr   c                 Z    |                      d                    |          d           d S )Nz<?{}?>TrW   rY   rN   s     r   	handle_pizHTMLExtractor.handle_pi   s-    hood33dCCCCCr   c                     |                     d          rdnd}|                     d                    ||          d           d S )NzCDATA[z]]>z]>z<![{}{}TrW   )
startswithrU   r.   )r   rO   r/   s      r   unknown_declzHTMLExtractor.unknown_decl   sK    x00:eedi..tS99DIIIIIr   c                     |                                  s| j        r!t                                          |          S |                     d           |dz   S )Nz<?   )r8   r   r   parse_pir"   r   ir   s     r   rj   zHTMLExtractor.parse_pi   sW     	'4; 	'77##A&&& 	1ur   c                     |                                  s| j        r!t                                          |          S |                     d           |dz   S )Nz<!ri   )r8   r   r   parse_html_declarationr"   rk   s     r   rn   z$HTMLExtractor.parse_html_declaration  sW     	54; 	57711!444 	1ur   Nc                     | j         S )z)Return full source of start tag: '<...>'.)_HTMLExtractor__starttag_textr7   s    r   rB   zHTMLExtractor.get_starttag_text  s    ##r   c                    d | _         |                     |          }|dk     r|S | j        }|||         | _         g }t          j                            ||dz             }|s
J d            |                                }|                    d                                          x| _	        }||k     rt          j
                            ||          }|sn|                    ddd          \  }	}
}|
sd }nI|d d         dcxk    r|dd          k    s"n |d d         dcxk    r|dd          k    rn n
|dd         }|rt                              |          }|                    |	                                |f           |                                }||k     |||                                         }|d	vr|                                 \  }}d
| j         v rM|| j                             d
          z   }t!          | j                   | j                             d
          z
  }n|t!          | j                   z   }|                     |||                    |S |                    d          r|                     ||           n4|| j        v r|                     |           |                     ||           |S )Nr   r)   z#unexpected call to parse_starttag()ri   r4   'rQ   ")>/>r*   ru   )rp   check_for_whole_start_tagr    r   tagfind_tolerantr-   r/   grouplowerlasttagattrfind_tolerantr#   r$   r6   getposcountr   r0   r"   rR   r@   rC   set_cdata_moderG   )r   rl   endposr    rE   r-   kr<   r1   attrnamerest	attrvaluer/   r+   r5   s                  r   parse_starttagzHTMLExtractor.parse_starttag  s&   #//22A: 	M,&qx0 +11'1Q3??;;;;;;IIKK"[[^^11333s&j 	,227A>>A ()1a(8(8%HdI , 		2A2$ , , , ,)BCC. , , , ,2A2#, , , ,)2233, , , , ,%adO	 ;&//	::	LL(..**I6777A &j 	 ah%%''k! 		![[]]NFFt++ <$"6"<"<T"B"BBT122/55d;;<  #d&:";";;WQvX.///M<< 	-##C//// d11 )##C(((  e,,,r   )__name__
__module____qualname____doc__r   r   r   propertyr2   r8   r>   rG   rL   r"   rU   r@   r\   r^   r`   rb   rd   rg   rj   rn   rp   rB   r   __classcell__)r   s   @r   r   r   @   s        	 	 	 	 	         
 
 X
[ [ [' ' '( ( (*' ' '6' ' '' ' '.^ ^ ^D D DC C CG G GC C CD D DJ J J         O$ $ $0 0 0 0 0 0 0r   r   )r   r,   importlib.util	importlibsysutil	find_specspecmodule_from_specr   loaderexec_modulemodulescompilepiclose	entityref
incompleteVERBOSElocatestarttagend_tolerantrK   
HTMLParserr    r   r   <module>r      s+   * 
			     




 ~..^,,T22
   
 # # #&L   RZ''
 !rz"?@@
  #,
 (2
 4 Z) )
 %$ 
?++C C C C CJ) C C C C Cr   