
    -Be2                        d Z ddlZddlZddlZej
                  j                  d      Zej
                  j                  e      Z	ej                  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y)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                 f    d|vrd|d<   t        dg      | _        t        |   |i | || _        y )Nconvert_charrefsFhr)set
empty_tagssuper__init__md)selfr   argskwargs	__class__s       3lib/python3.12/site-packages/markdown/htmlparser.pyr   zHTMLExtractor.__init__H   s@    V+).F%& tf+ 	$)&)    c                 h    d| _         d| _        g | _        g | _        g | _        t
        |           y)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                        rb| j                  r;| j
                  s/| j                  t        j                  | j                               n| j                  | j                         t        | j                        r_| j                  j                  | j                  j                  j                  dj                  | j                                     g | _	        yy)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C  .t{{MM  !2!2!8!89M!NODK r   c                    | j                   dkD  rwd| j                  v rit        j                  dj	                  | j                   dz
        | j                        }|r|j                         S | j                  j                  d      S y)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   sj     ;;?tt||3,33DKKMBDLLQAuuw ||))$//r   c                     | j                   dk(  ry| j                   dkD  ry| j                  | j                  | j                  | j                   z    j                         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   sV     ;;!;;?||D,,T-=-=-KLRRTXZZZr   c                     | j                   | j                  z   }t        j                  j	                  | j
                  |      }|r| j
                  ||j                          S dj                  |      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   s_       4;;.  ''e<<<aeeg.. >>#&&r   c                 *   || j                   v r| j                  ||       y | j                  j                  |      rJ| j                  s| j                         r.| j                  s"d| _        | j                  j                  d       | j                         }| j                  r7| j                  j                  |       | j                  j                  |       y | j                  j                  |       || j                  v r| j                          y y )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/77!!#&DKKD<N<N<PY]YcYcDJMM  &%%'::JJc"KKt$MM  &d111%%' 2r   c                 :   | j                  |      }| j                  rb| j                  j                  |       || j                  v r7| j                  r+| j                  j                         |k(  rn| j                  r+t        | j                        dk(  rt        j                  | j                  | j                  | j                  z   t        |      z   d        r| j                  j                  d       nd| _        d| _        | j                  j                  | j                  j                  j!                  dj#                  | j                                     | j                  j                  d       g | _        y y | j                  j                  |       y )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   s,   ##C(::KKt$djj jjzz~~'3. jj 4::!# &&t||D4D4Dt{{4RUXY]U^4^4_'`aKK&&t, #'DK"
$$TWW%6%6%<%<RWWT[[=Q%RS$$V,  $ MM  &r   c                     | j                   rd|v rd| _         | j                  r| j                  j                  |       y | j                  j                  |       y )Nr*   F)r   r   r   r$   r   r   datas     r   r"   zHTMLExtractor.handle_data   sA    ;;44<DK::KKt$MM  &r   c                    | j                   s| j                  r| j                  j                  |       y| j	                         r	|rt
        j                  | j                  | j                  | j                  z   t        |      z   d       r|dz  }nd| _        | j                  r| j                  d   nd}|j                  d      s,|j                  d      r| j                  j                  d       | j                  j                  | j                  j                  j                  |             | j                  j                  d       y| j                  j                  |       y)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   s    ::KKt$!h""4<<0@0@4;;0NQTUYQZ0Z0[#\] #(,4==$2D==(T]]4-@$$T*MM  !2!2!8!8!>?MM  (MM  &r   c                 x    | j                  | j                         | j                  j                  |             y )NrS   )rU   rB   r   rA   )r   r<   rE   s      r   r@   z HTMLExtractor.handle_startendtag   s.    d446AWAWX[A\]r   c                 H    | j                  dj                  |      d       y )Nz&#{};FrW   rU   r.   r   names     r   handle_charrefzHTMLExtractor.handle_charref   s    gnnT2UCr   c                 H    | j                  dj                  |      d       y )Nz&{};FrW   rY   rZ   s     r   handle_entityrefzHTMLExtractor.handle_entityref   s    fmmD1EBr   c                 H    | j                  dj                  |      d       y )Nz	<!--{}-->TrW   rY   rN   s     r   handle_commentzHTMLExtractor.handle_comment   s     k006Fr   c                 H    | j                  dj                  |      d       y )Nz<!{}>TrW   rY   rN   s     r   handle_declzHTMLExtractor.handle_decl   s    gnnT2TBr   c                 H    | j                  dj                  |      d       y )Nz<?{}?>TrW   rY   rN   s     r   	handle_pizHTMLExtractor.handle_pi   s    hood3dCr   c                 t    |j                  d      rdnd}| j                  dj                  ||      d       y )NzCDATA[z]]>z]>z<![{}{}TrW   )
startswithrU   r.   )r   rO   r/   s      r   unknown_declzHTMLExtractor.unknown_decl   s4    x0edi..tS9DIr   c                     | j                         s| j                  rt        |   |      S | j	                  d       |dz   S )Nz<?   )r8   r   r   parse_pir"   r   ir   s     r   rj   zHTMLExtractor.parse_pi   s>    4;;7#A&& 	1ur   c                     | j                         s| j                  rt        |   |      S | j	                  d       |dz   S )Nz<!ri   )r8   r   r   parse_html_declarationr"   rk   s     r   rn   z$HTMLExtractor.parse_html_declaration  s>    4;;71!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 | _         | j                  |      }|dk  r|S | j                  }||| | _         g }t        j                  j                  ||dz         }|sJ d       |j                         }|j                  d      j                         x| _	        }||k  rt        j                  j                  ||      }|sn|j                  ddd      \  }	}
}|
sd }n,|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        j                  |      }|j                  |	j                         |f       |j                         }||k  r||| j                         }|d	vr| j                         \  }}d
| j                   v rP|| j                   j                  d
      z   }t!        | j                         | j                   j#                  d
      z
  }n|t!        | j                         z   }| j%                  |||        |S |j'                  d      r| j)                  ||       |S || j*                  v r| j-                  |       | j/                  ||       |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A:M,,&q0 ++11'1Q3?;;;IIK"[[^1133s&j,,227A>A()1a(8%HdI 	2A$8)BC.82A#7237%aO	&//	:	LL(..*I67A &j a%%'k!![[]NFFt+++$"6"6"<"<T"BBT112//55d;<  #d&:&:";;WQv./M<<##C/  d1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    	 
 
['(*'6''.^DCGCDJ O$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
   
 #&L   RZZ'
 !rzz"?@
  #,,
 (2

 4 ZZ)
 %$ 

?+CJ)) Cr   