a
    Yc                     @   s  d Z ddlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZmZmZmZmZ g dZdadd Zd/d	d
Zdd Zdd ZG dd dejZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZ G d#d$ d$eZ!G d%d& d&eZ"G d'd( d(eZ#G d)d* d*eZ$G d+d, d,eZ%G d-d. d.eZ&g a'e  dS )0z%
Built-in block-level token classes.
    N)zip_longest)token
span_token)followsshift_whitespace
whitespaceis_control_charnormalize_label)		BlockCodeHeadingQuote	CodeFenceThematicBreakListTableFootnote	Paragraphc                 C   s   t | tS )a  
    A wrapper around block_tokenizer.tokenize. Pass in all block-level
    token constructors as arguments to block_tokenizer.tokenize.

    Doing so (instead of importing block_token module in block_tokenizer)
    avoids cyclic dependency issues, and allows for future injections of
    custom token classes.

    _token_types variable is at the bottom of this module.

    See also: block_tokenizer.tokenize, span_token.tokenize_inner.
    )	tokenizertokenize_token_typeslines r   V/var/www/html/MEGASTUDIO_platform/lib/python3.9/site-packages/mistletoe/block_token.pyr   "   s    r   c                 C   s   t ||  dS )a'  
    Allows external manipulation of the parsing process.
    This function is usually called in BaseRenderer.__enter__.

    Arguments:
        token_cls (SpanToken): token to be included in the parsing process.
        position (int): the position for the token class to be inserted into.
    N)r   insert)	token_clspositionr   r   r   	add_token2   s    	r   c                 C   s   t |  dS )z
    Allows external manipulation of the parsing process.
    This function is usually called in BaseRenderer.__exit__.

    Arguments:
        token_cls (BlockToken): token to be removed from the parsing process.
    N)r   remove)r   r   r   r   remove_token>   s    r   c                   C   s   dd t D adS )zE
    Resets global _token_types to all token classes in __all__.
    c                 S   s   g | ]}t  | qS r   )globals).0cls_namer   r   r   
<listcomp>N       z reset_tokens.<locals>.<listcomp>N)__all__r   r   r   r   r   reset_tokensI   s    r&   c                   @   s,   e Zd ZdZdd Zdd Zedd ZdS )	
BlockTokena  
    Base class for block-level tokens. Recursively parse inner tokens.

    Naming conventions:

        * lines denotes a list of (possibly unparsed) input lines, and is
          commonly used as the argument name for constructors.

        * BlockToken.children is a list with all the inner tokens (thus if
          a token has children attribute, it is not a leaf node; if a token
          calls span_token.tokenize_inner, it is the boundary between
          span-level tokens and block-level tokens);

        * BlockToken.start takes a line from the document as argument, and
          returns a boolean representing whether that line marks the start
          of the current token. Every subclass of BlockToken must define a
          start function (see block_tokenizer.tokenize).

        * BlockToken.read takes the rest of the lines in the ducment as an
          iterator (including the start line), and consumes all the lines
          that should be read into this token.

          Default to stop at an empty line.
          
          Note that BlockToken.read does not have to return a list of lines.
          Because the return value of this function will be directly
          passed into the token constructor, we can return any relevant
          parsing information, sometimes even ready-made tokens,
          into the constructor. See block_tokenizer.tokenize.

          If BlockToken.read returns None, the read result is ignored,
          but the token class is responsible for resetting the iterator
          to a previous state. See block_tokenizer.FileWrapper.anchor,
          block_tokenizer.FileWrapper.reset.

    Attributes:
        children (list): inner tokens.
    c                 C   s   ||| _ d S N)children)selfr   Ztokenize_funcr   r   r   __init__x   s    zBlockToken.__init__c                    s   t  fdd| jD S )Nc                 3   s   | ]} |v V  qd S r(   r   )r!   childtextr   r   	<genexpr>|   r$   z*BlockToken.__contains__.<locals>.<genexpr>)anyr)   )r*   r.   r   r-   r   __contains__{   s    zBlockToken.__contains__c                 C   s.   t | g}| D ]}|dkr q*|| q|S )N
)nextappend)r   line_bufferliner   r   r   read~   s    
zBlockToken.readN)__name__
__module____qualname____doc__r+   r1   staticmethodr7   r   r   r   r   r'   Q   s
   &r'   c                   @   s   e Zd ZdZdd ZdS )Documentzv
    Document token.
    This is a container block token. Its children are block tokens - container or leaf ones.
    c                 C   sL   t |tr|jdd}dd |D }i | _| a| t_t|| _d t_d ad S )NT)keependsc                 S   s$   g | ]}| d r|nd|qS )r2   z{}
)endswithformatr!   r6   r   r   r   r#      r$   z%Document.__init__.<locals>.<listcomp>)
isinstancestr
splitlines	footnotes
_root_noder   r   r)   r*   r   r   r   r   r+      s    

zDocument.__init__N)r8   r9   r:   r;   r+   r   r   r   r   r=      s   r=   c                       sN   e Zd ZdZdZedZdZdZ	 fddZ
edd	 Zed
d Z  ZS )r   z
    ATX heading token. (["### some heading ###\n"])
    This is a leaf block token. Its children are inline (span) tokens.

    Attributes:
        level (int): heading level.
        children (list): inner tokens.
    levelz0 {0,3}(#{1,6})(?:\n|\s+?(.*?)(?:\n|\s+?#+\s*?$))r    c                    s   |\| _ }t |tj d S r(   )rI   superr+   r   tokenize_inner)r*   matchcontent	__class__r   r   r+      s    
zHeading.__init__c                 C   sV   | j |}|d u rdS t|d| _|dp4d | _t| jdhkrRd| _dS )NF      rJ   #T)patternrM   lengrouprI   striprN   set)clsr6   	match_objr   r   r   start   s    zHeading.startc                 C   s   t | | j| jfS r(   )r3   rI   rN   rY   r   r   r   r   r7      s    zHeading.read)r8   r9   r:   r;   repr_attributesrecompilerT   rI   rN   r+   classmethodr[   r7   __classcell__r   r   rO   r   r      s   


r   c                       s<   e Zd ZdZdZ fddZedd Zedd Z  Z	S )	SetextHeadingz
    Setext heading token.
    This is a leaf block token. Its children are inline (span) tokens.

    Not included in the parsing process, but called by Paragraph.__new__.

    Attributes:
        level (int): heading level.
    rH   c                    sD   |   drdnd| _ddd |D }t |tj d S )N=rQ   rR   r2   c                 S   s   g | ]}|  qS r   rW   rA   r   r   r   r#      r$   z*SetextHeading.__init__.<locals>.<listcomp>)	poplstrip
startswithrI   joinrK   r+   r   rL   r*   r   rN   rO   r   r   r+      s    zSetextHeading.__init__c                 C   s
   t  d S r(   NotImplementedErrorrY   r6   r   r   r   r[      s    zSetextHeading.startc                 C   s
   t  d S r(   rj   r\   r   r   r   r7      s    zSetextHeading.read)
r8   r9   r:   r;   r]   r+   r`   r[   r7   ra   r   r   rO   r   rb      s   	
rb   c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Z	d
S )r   z
    Block quote token. (["> # heading\n", "> paragraph\n"])
    This is a container block token. Its children are block tokens - container or leaf ones.
    c                 C   s   t || _d S r(   )r   make_tokensr)   )r*   parse_bufferr   r   r   r+      s    zQuote.__init__c                 C   s,   |  d}t| t| dkr"dS |dS )N    F>)rf   rU   rg   )r6   strippedr   r   r   r[      s    
zQuote.startc                 C   s|  |  t| ddd }t|dkrB|d dkrB|dd  }|g}t|}t|}| dk}|	 }|d ur`| dkr`t
|s`t|s`t|s`t|s`|  | }d}	|d dkr,|	d7 }	|d dkr|	d7 }	||	d  }t|}t|}| dk}|| n"|s`|s`|rDq`n
|| t| |	 }qpdt_t|t}
dt_|
S )Nrq   rQ   r   ro   rJ   FT)convert_leading_tabsr3   rf   splitrU   r   r[   r
   rW   peekr   r   r   r4   r   parse_setextr   tokenize_blockr   )rY   r   r6   r5   Zin_code_fenceZin_block_codeZ
blank_line	next_linerr   prependrn   r   r   r   r7      sN    







z
Quote.readc                 C   sp   |  ddd} d}t| D ]0\}}|dkr4|d7 }q|dkrF|d7 }q qLq|dkrX| S dd|  | |d   S )	Nz>	   rQ   r   	   ro   rq   )replace	enumeratestringcounticr   r   r   rs     s    

zQuote.convert_leading_tabsN)
r8   r9   r:   r;   r+   r<   r[   r`   r7   rs   r   r   r   r   r      s   

0r   c                       s^   e Zd ZdZedZdZ fddZ fddZ	e
dd	 Zed
d Zedd Z  ZS )r   z
    Paragraph token. (["some\n", "continuous\n", "lines\n"])
    This is a leaf block token. Its children are inline (span) tokens.
    z {0,3}(=|-)+ *$Tc                    s   t |ts|S t | S r(   )rB   listrK   __new__r\   rO   r   r   r   .  s    
zParagraph.__new__c                    s,   d dd |D  }t |tj d S )NrJ   c                 S   s   g | ]}|  qS r   )rf   rA   r   r   r   r#   5  r$   z&Paragraph.__init__.<locals>.<listcomp>)rh   rW   rK   r+   r   rL   ri   rO   r   r   r+   4  s    zParagraph.__init__c                 C   s   |   dkS NrJ   rd   r6   r   r   r   r[   8  s    zParagraph.startc                 C   s"  t |g}| }|d ur| dkrt|st|st|st|}t	|t	|
  dk r|d ur|\}}|d | dr|d d  r|d d dkrqt|}|r|dkrАq| jr| |r|t | t|S t|rq|t | | }q|S )NrJ   r|   ro   1   )r3   ru   rW   r   r[   r   r   ListItemparse_markerrU   rf   r?   isdigit	HTMLBlockrv   is_setext_headingr4   rb   r   )rY   r   r5   rx   Z	list_pairry   leaderZ
html_blockr   r   r   r7   <  s<    



 

zParagraph.readc                 C   s   | j |S r(   )setext_patternrM   rl   r   r   r   r   d  s    zParagraph.is_setext_heading)r8   r9   r:   r;   r^   r_   r   rv   r   r+   r<   r[   r`   r7   r   ra   r   r   rO   r   r   &  s   


'r   c                   @   s@   e Zd ZdZdZdd Zedd Zedd Z	ed	d
 Z
dS )r
   z
    Indented code block token.
    This is a leaf block token with a single child of type span_token.RawText.

    Attributes:
        children (list): contains a single span_token.RawText token.
        language (str): always the empty string.
    languagec                 C   s(   d| _ td|dd f| _d S NrJ   r2   )r   r   RawTextrh   rW   r)   rG   r   r   r   r+   s  s    zBlockCode.__init__c                 C   s   |  ddddS )Nr{       rQ   )r}   rg   r   r   r   r   r[   w  s    zBlockCode.startc                 C   sx   g }|D ]j}|  dkrB|t|dk r2|dn
|dd   q|ddddsb|   qt||  | q|S )NrJ      ro   r|   r{   r   rQ   )rW   r4   rU   rf   r}   rg   backsteprY   r   r5   r6   r   r   r   r7   {  s    (zBlockCode.readc                 C   sh   d}t | D ]V\}}|dkr0| |d d    S |dkrB|d7 }n qd|dkr| |d d    S q| S )Nr   r{   rQ   ro   r|   )r~   r   r   r   r   rW     s    
zBlockCode.stripN)r8   r9   r:   r;   r]   r+   r<   r[   r`   r7   rW   r   r   r   r   r
   i  s   

r
   c                   @   sB   e Zd ZdZdZedZdZdd Z	e
dd Ze
d	d
 ZdS )r   a0  
    Fenced code block token. (["```sh\n", "rm -rf /", ..., "```"])
    This is a leaf block token with a single child of type span_token.RawText.

    Attributes:
        children (list): contains a single span_token.RawText token.
        language (str): language of code block (default to empty).
    r   z( {0,3})(`{3,}|~{3,}) *(\S*)Nc                 C   s2   |\}}t j|d | _t d|f| _d S )NrR   rJ   )r   EscapeSequencerW   r   r   rh   r)   )r*   rM   r   Z	open_infor   r   r   r+     s    zCodeFence.__init__c                 C   s^   | j |}|sdS | \}}}|d |v sF|d || d  v rJdS t|||f| _dS )NFr   T)rT   rM   groupsendrU   
_open_info)rY   r6   rZ   ry   r   langr   r   r   r[     s    $zCodeFence.startc                 C   s   t | g }|D ]|}|d}t|t| }|| jd r^t|jdddkr^|dk r^ q|| jd krd|| jd   | }|| q|| jfS )Nro   rQ   )maxsplitr|   r   )r3   rf   rU   rg   r   rt   r4   )rY   r   r5   r6   Zstripped_linediffr   r   r   r7     s    
zCodeFence.read)r8   r9   r:   r;   r]   r^   r_   rT   r   r+   r`   r[   r7   r   r   r   r   r     s   


r   c                   @   sJ   e Zd ZdZdZedZdd Ze	dd Z
e	dd	 Zed
d ZdS )r   a#  
    List token.
    This is a container block token. Its children are list item tokens.

    Attributes:
        children (list): a list of ListItem tokens.
        loose (bool): whether the list is loose.
        start (NoneType or int): None if unordered, starting number if ordered.
    )looser[   z. {0,3}(?:\d{0,9}[.)]|[+\-*])(?:[ \t]*$|[ \t]+)c                 C   sZ   dd |D | _ tdd | j D | _| j d j}d | _t|dkrVt|d d | _d S )Nc                 S   s   g | ]}t | qS r   )r   )r!   rM   r   r   r   r#     r$   z!List.__init__.<locals>.<listcomp>c                 s   s   | ]}|j V  qd S r(   )r   )r!   itemr   r   r   r/     r$   z List.__init__.<locals>.<genexpr>r   rQ   r   )r)   r0   r   r   r[   rU   int)r*   matchesr   r   r   r   r+     s    zList.__init__c                 C   s   | j |S r(   rT   rM   rl   r   r   r   r[     s    z
List.startc                 C   s   d }d }g }t ||\}}|d }|d u r2|}n| ||sH|  q^|| |d u rq^q|r|d d }t|dko~|j|_|S )NrR   r   r   rQ   )r   r7   same_marker_typeresetr4   rU   r   )rY   r   r   next_markerr   outputZitem_leaderZlast_parse_bufferr   r   r   r7     s"    
z	List.readc                 C   sD   t | dkr| |kS | d d  oB|d d  oB| d |d kS )NrQ   r   )rU   r   )r   otherr   r   r   r     s    zList.same_marker_typeN)r8   r9   r:   r;   r]   r^   r_   rT   r+   r`   r[   r7   r<   r   r   r   r   r   r     s   	


r   c                   @   sX   e Zd ZdZdZedZdd Ze	dd Z
e	dd	 Zed
d ZedddZdS )r   z
    List item token.
    This is a container block token. Its children are block tokens - container or leaf ones.

    Not included in the parsing process, but called by List.
    )r   ry   r   z!\s*(\d{0,9}[.)]|[+\-*])(\s*$|\s+)c                 C   s$   || _ || _t|| _|j| _d S r(   )r   ry   r   rm   r)   r   )r*   rn   ry   r   r   r   r   r+     s    zListItem.__init__c                 C   s$   |   dkp"t| t|   |kS r   )rW   rU   rf   )r6   ry   r   r   r   in_continuation  s    zListItem.in_continuationc                 C   s(   t | p&t| p&t| p&t| S r(   )r   r[   r   r   r   r   r   r   r   other_token  s    
zListItem.other_tokenc                 C   s   | j |}|du rdS |d}|d|d |d d}t|}|t|dkrh|dd }nL|d}|dr|ddd}|dd}t|}|d	kr|dd }||fS )
zS
        Returns a pair (prepend, leader) iff the line has a valid leader.
        NrQ   r   r{   rz   r2   rR   r   r|   )rT   rM   rV   r}   rU   rstripr   rg   )rY   r6   rZ   r   rN   ry   spacesZn_spacesr   r   r   r     s     


zListItem.parse_markerNc                 C   s  d }|   d}d }g }t|}|r(|n| |\}}||d |d ddd}||d   dk}|s~|||d   | }	|r|	d ur|	 dkrtt|gt	}
| }	|	d ur| |	}|d ur|}|
||f|fS d}|	d u r|r|
  || d = q|	dd}	| |	|s| |	rT|r|
  || d = q| |	}|d urp|}q|r|
  || d = qt| |	}|d}t|t| }||krd||  | }|| |	 dkr|d nd}| }	qt|t	}
|
||f|fS )	Nr   r{   rz   rQ   r   rJ   r   ro   )anchorr3   r   r}   rW   r4   ru   r   rw   r   r   r   r   rf   rU   )rY   r   Zprev_markerr   ry   r   r5   r6   Zempty_first_linerx   rn   Zmarker_infonewlinerr   r   r   r   r   r7   .  sh    







zListItem.read)N)r8   r9   r:   r;   r]   r^   r_   rT   r+   r<   r   r   r`   r   r7   r   r   r   r   r     s   



r   c                   @   sL   e Zd ZdZdZdd Zedd Zedd Zed	d
 Z	edd Z
dS )r   a+  
    Table token.
    This is a container block token. Its children are table row tokens.

    Attributes:
        has_header (bool): whether table has header row.
        column_align (list): align options for each column (default to [None]).
        children (list): inner tokens (TableRows).
    )column_alignc                    sv   d|d v rZ fdd  |d D  _t|d  j _ fdd|dd  D  _nd g _dd |D  _d S )	N---rQ   c                    s   g | ]}  |qS r   )parse_align)r!   columnr*   r   r   r#     s   z"Table.__init__.<locals>.<listcomp>r   c                    s   g | ]}t | jqS r   )TableRowr   rA   r   r   r   r#     r$   rR   c                 S   s   g | ]}t |qS r   )r   rA   r   r   r   r#     r$   )split_delimiterr   r   headerr)   rG   r   r   r   r+     s    
zTable.__init__c                 C   s   t d| S )z
        Helper function; returns a list of align options.

        Args:
            delimiter (str): e.g.: "| :--- | :---: | ---: |
"

        Returns:
            a list of align options (None, 0 or 1).
        z:?---+:?)r^   findall)	delimiterr   r   r   r     s    zTable.split_delimiterc                 C   s$   | d dkr | d dkrdq"dS dS )z
        Helper function; returns align option from cell content.

        Returns:
            None if align = left;
            0    if align = center;
            1    if align = right.
        r   :r   rQ   Nr   )r   r   r   r   r     s    
zTable.parse_alignc                 C   s   d| v S )N|r   r   r   r   r   r[     s    zTable.startc                 C   sb   |    t| g}|  d ur:d|  v r:|t|  qt|dk sRd|d vr^|   d S |S )Nr   rR   r   rQ   )r   r3   ru   r4   rU   r   )r   r5   r   r   r   r7     s    
z
Table.readN)r8   r9   r:   r;   r]   r+   r<   r   r   r[   r7   r   r   r   r   r   t  s   	



r   c                   @   s2   e Zd ZdZdZedZedZdddZ	dS )	r   z
    Table row token. Supports escaped pipes in table cells (for primary use within code spans).
    This is a container block token. Its children are table cell tokens.

    Should only be called by Table.__init__().
    )	row_alignz	(?<!\\)\|z(?<!\\)(\\\\)*\\\|Nc                    sB   |pd g _ td  j| } fddt| j D  _d S )Nc                    s0   g | ](\}}t |r$ jd | nd|qS )z\1|rJ   )	TableCellescaped_pipe_patternsubrW   )r!   cellalignr   r   r   r#     s   z%TableRow.__init__.<locals>.<listcomp>)r   filtersplit_patternrt   rW   r   r)   )r*   r6   r   cellsr   r   r   r+     s
    

zTableRow.__init__)N)
r8   r9   r:   r;   r]   r^   r_   r   r   r+   r   r   r   r   r     s
   

r   c                       s&   e Zd ZdZdZd fdd	Z  ZS )r   a  
    Table cell token.
    This is a leaf block token. Its children are inline (span) tokens.

    Should only be called by TableRow.__init__().

    Attributes:
        align (bool): align option for current cell (default to None).
        children (list): inner (span-)tokens.
    )r   Nc                    s   || _ t |tj d S r(   )r   rK   r+   r   rL   )r*   rN   r   rO   r   r   r+     s    zTableCell.__init__)N)r8   r9   r:   r;   r]   r+   ra   r   r   rO   r   r     s   
r   c                   @   s   e Zd ZdZedejZdd Ze	dd Z
e	dd Ze	d	d
 Ze	dd Ze	dd Ze	dd Zedd Zedd ZdS )r   z
    Footnote token. A "link reference definition" according to the spec.
    This is a leaf block token. Its children are inline (span) tokens.

    The constructor returns None, because the footnote information
    is stored in Footnote.read.
    z[ \n]{0,3}\[(.+?)\]c                 C   s   d S r(   r   )rY   _r   r   r   r     s    zFootnote.__new__c                 C   s   |  dS )N[)rf   rg   rl   r   r   r   r[     s    zFootnote.startc           	      C   s   g }|  }|d ur8| dkr8|t| |  }qd|}d}g }|t|d k r| |||}|d u rrq|\}}|| qJ| |t |pd S )NrJ   r   rQ   )	ru   rW   r4   r3   rh   rU   match_referenceappend_footnotesrF   )	rY   r   r5   rx   r   offsetr   
match_inforM   r   r   r   r7     s     

zFootnote.readc                 C   s   |  ||}|s"| ||| d S |\}}}t||d dsN| ||| d S | ||}|sp| ||| d S |\}}}	| ||}|s| ||| d S |\}}
}|
||	|ffS )NrQ   r   )match_link_label	backtrackr   match_link_destmatch_link_title)rY   r   r   r   r   r   Z	label_endlabelZdest_enddestZ	title_endtitler   r   r   r     s&    


zFootnote.match_referencec           	      C   s   d}d}d}t ||d  |dD ]\}}|dkr:|s:d}q |dkr\|s\|dkrT|}q d S q |dkr|s|}||d | }| d	kr||d |f  S  d S |r d}q d S )
Nr   Fr[   \Tr   ]rQ   rJ   )r~   rW   )	rY   r   r   r[   r   escapedr   r   r   r   r   r   r     s&    zFootnote.match_link_labelc                 C   sr  t ||d }|t|krd S || dkrd}t||d d  |d dD ]n\}}|dkrd|sdd}qJ|dks|dks|dkr|s d S |d	kr|s||d ||d | f  S |rJd}qJd S d}d
}t||d  |dD ]r\}}|dkr|sd}q|tv r qNq|s4|dkr |d7 }n|dkrL|d8 }qt|rD d S |rd}q|d
kr\d S ||||| fS d S )NrQ   <Fr   r   Tro   r2   rq   r   ())r   rU   r~   r   r   )rY   r   r   r   r   r   r   r   r   r   r   .  sD    $






zFootnote.match_link_destc                 C   s0  t ||}|t|ks2d||| v r<|| dkr<||dfS || dkrNd}nB|| dkr`d}n0|| dkrrd}nd||| v r||dfS d S |}d}t||d	 d  |d	 d
D ]v\}}|dkr|sd}q||kr"|s"t ||d	 }d||d	 | vr d S ||||d	 | f  S |rd}qd S )Nr2   r   rJ   "'r   r   FrQ   r   r   T)r   rU   r~   )rY   r   r   Z
new_offsetclosingr   r   r   r   r   r   r   T  s:    



$zFootnote.match_link_titlec                 C   sP   | D ]F\}}}t |}tj| }tj|}||jvr||f|j|< qd S r(   )r	   r   r   rW   rE   )r   rootkeyr   r   r   r   r   r   t  s    
zFootnote.append_footnotesc                 C   s$   |  j ||d  d8  _ dS )z
        Called when we iterated over some lines and found nothing
        relevant on them. This returns those lines back to the parsing process.
        Nr2   )_indexrf   r   )r   r   r   r   r   r   r   }  s    
zFootnote.backtrackN)r8   r9   r:   r;   r^   r_   DOTALLZlabel_patternr   r`   r[   r7   r   r   r   r   r<   r   r   r   r   r   r   r     s&   	




%

r   c                   @   s:   e Zd ZdZedZdd Zedd Z	e
dd Zd	S )
r   zi
    Thematic break token (a.k.a. horizontal rule.)
    This is a leaf block token without children.
    z$ {0,3}(?:([-_*])\s*?)(?:\1\s*?){2,}$c                 C   s   d S r(   r   )r*   r   r   r   r   r+     s    zThematicBreak.__init__c                 C   s   | j |S r(   r   rl   r   r   r   r[     s    zThematicBreak.startc                 C   s
   t | gS r(   )r3   r   r   r   r   r7     s    zThematicBreak.readN)r8   r9   r:   r;   r^   r_   rT   r+   r`   r[   r<   r7   r   r   r   r   r     s   

r   c                   @   sh   e Zd ZdZdZedZedZedd	e
je
jf d Zdd	 Zed
d Zedd ZdS )r   z
    Block-level HTML token.
    This is a leaf block token without children.

    Attributes:
        content (str): the raw HTML content.
    Nz<(script|pre|style)[ >\n]z<\/?(.+?)(?:\/?>|[ \n])z(?:r   z)\s*$c                 C   s   d |d| _d S r   )rh   r   rN   rG   r   r   r   r+     s    zHTMLBlock.__init__c                 C   s   |  }t|t| dkr dS | j|}|d urNd|d | _dS |drbd| _dS |drvd	| _d
S |dr|d 	 rd| _dS |drd| _dS | j
|}|d ur|d tjv rd | _dS | j|}|d urd | _dS dS )Nr|   Fz</{}>rQ   z<!--z-->rR   z<?z?>rp   z<!rq   z	<![CDATA[z]]>r      r   )rf   rU   
multiblockrM   r@   rV   casefold	_end_condrg   isupper
predefinedr   Z_tags
custom_tag)rY   r6   rr   rZ   r   r   r   r[     s8    


zHTMLBlock.startc                 C   sR   g }|D ]D}| | | jd ur4| j| v rL qNq| dkr|   qNq|S r   )r4   r   r   rW   re   r   r   r   r   r7     s    

zHTMLBlock.read)r8   r9   r:   r;   r   r^   r_   r   r   rh   r   Z	_open_tagZ_closing_tagr   r+   r`   r[   r7   r   r   r   r   r     s   


%r   )r   )(r;   r^   	itertoolsr   Zmistletoe.block_tokenizerZblock_tokenizerr   Z	mistletoer   r   Zmistletoe.core_tokensr   r   r   r   r	   r%   rF   r   r   r   r&   Tokenr'   r=   r   rb   r   r   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s<   

7"QC.-7y> 4F