a
    Yc$                     @   s  d Z ddlZddlZddlmZ ddlmZmZ g dZ	dZ
dd Zd7d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h d&Zd'Zd(Zd)e e d* Zd+e d, Z d-Z!d.Z"d/Z#d0Z$G d1d2 d2eZ%G d3d4 d4eZ&G d5d6 d6eZ'g a(e  dS )8z$
Built-in span-level token classes.
    N)core_tokenstoken)EscapeSequenceStrikethroughAutoLink
CoreTokens
InlineCode	LineBreakRawTextc                 C   s   t | tS )a  
    A wrapper around span_tokenizer.tokenize. Pass in all span-level token
    constructors as arguments to span_tokenizer.tokenize.

    Doing so (instead of importing span_token module in span_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: span_tokenizer.tokenize, block_token.tokenize.
    )	tokenizertokenize_token_typescontent r   U/var/www/html/MEGASTUDIO_platform/lib/python3.9/site-packages/mistletoe/span_token.pytokenize_inner   s    r      c                 C   s   t ||  dS )z
    Allows external manipulation of the parsing process.
    This function is called in BaseRenderer.__enter__.

    Arguments:
        token_cls (SpanToken): token to be included in the parsing process.
    N)r   insert)	token_clspositionr   r   r   	add_token%   s    r   c                 C   s   t |  dS )z
    Allows external manipulation of the parsing process.
    This function is called in BaseRenderer.__exit__.

    Arguments:
        token_cls (SpanToken): token to be removed from the parsing process.
    N)r   remove)r   r   r   r   remove_token0   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>@       z reset_tokens.<locals>.<listcomp>N)__all__r   r   r   r   r   reset_tokens;   s    r    c                   @   s4   e Zd ZdZdZdZdd Zdd Zedd	 Z	d
S )	SpanTokenTr      c                 C   s   | j s|| j| _d S N)parse_innergroupparse_groupr   selfmatchr   r   r   __init__H   s    zSpanToken.__init__c                    s,   t | dr"t fdd| jD S  | jv S )Nchildrenc                 3   s   | ]} |v V  qd S r#   r   )r   childtextr   r   	<genexpr>N   r   z)SpanToken.__contains__.<locals>.<genexpr>)hasattranyr+   r   )r(   r.   r   r-   r   __contains__L   s    
zSpanToken.__contains__c                 C   s   | j |S r#   )patternfinditerclsstringr   r   r   findQ   s    zSpanToken.findN)
__name__
__module____qualname__r$   r&   
precedencer*   r2   classmethodr8   r   r   r   r   r!   C   s   r!   c                   @   s(   e Zd ZdZdZdd Zedd ZdS )r   z
    Represents core tokens (Strong, Emphasis, Image, Link) during the early stage of parsing.
    Replaced with objects of the proper classes in the final stage of parsing.
       c                 C   s   t  |j |S r#   )r   typer'   r   r   r   __new__\   s    zCoreTokens.__new__c                 C   s   t |tS r#   )r   Zfind_core_tokens
_root_noder5   r   r   r   r8   _   s    zCoreTokens.findN)r9   r:   r;   __doc__r<   r@   r=   r8   r   r   r   r   r   V   s
   r   c                   @   s   e Zd ZdZdS )Strongz
    Strong token. ("**some text**")
    This is an inline token. Its children are inline (span) tokens.
    One of the core tokens.
    Nr9   r:   r;   rB   r   r   r   r   rC   d   s   rC   c                   @   s   e Zd ZdZdS )Emphasisz
    Emphasis token. ("*some text*")
    This is an inline token. Its children are inline (span) tokens.
    One of the core tokens.
    NrD   r   r   r   r   rE   l   s   rE   c                   @   s:   e Zd ZdZedejZdZdZ	dd Z
edd Zd	S )
r   zm
    Inline code token. ("`some code`")
    This is an inline token with a single child of type RawText.
    z-(?<!\\|`)(?:\\\\)*(`+)(?!`)(.+?)(?<!`)\1(?!`)F   c                 C   s.   | | j}tdtd| f| _d S )N z[ 
]+)r%   r&   r
   joinresplitstripr+   r(   r)   r   r   r   r   r*   }   s    zInlineCode.__init__c                 C   s   t j}g t _|S r#   )r   Z_code_matches)r6   r7   matchesr   r   r   r8      s    zInlineCode.findN)r9   r:   r;   rB   rI   compileDOTALLr3   r$   r&   r*   r=   r8   r   r   r   r   r   t   s   r   c                   @   s   e Zd ZdZedejZdS )r   zt
    Strikethrough token. ("~~some text~~")
    This is an inline token. Its children are inline (span) tokens.
    z(?<!\\)(?:\\\\)*~~(.+?)~~N)r9   r:   r;   rB   rI   rN   rO   r3   r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdZdd ZdS )Imagea  
    Image token. ("![alt](src "title")")
    This is an inline token. Its children are inline (span) tokens holding the image description.
    One of the core tokens.

    Attributes:
        src (str): image source.
        title (str): image title (default to empty).
    )srctitlec                 C   s,   t |d | _t |d| _d S NrF   r>   )r   rK   r%   rQ   rR   r'   r   r   r   r*      s    zImage.__init__Nr9   r:   r;   rB   repr_attributesr*   r   r   r   r   rP      s   	rP   c                   @   s   e Zd ZdZdZdd ZdS )Linka  
    Link token. ("[name](target)")
    This is an inline token. Its children are inline (span) tokens holding the link text.
    One of the core tokens.

    Attributes:
        target (str): link target.
        title (str): link title (default to empty).
    )targetrR   c                 C   s,   t |d | _t |d| _d S rS   )r   rK   r%   rW   rR   r'   r   r   r   r*      s    zLink.__init__NrT   r   r   r   r   rV      s   	rV   c                   @   s*   e Zd ZdZdZedZdZdd Z	dS )r   z
    Autolink token. ("<http://www.google.com>")
    This is an inline token with a single child of type RawText.

    Attributes:
        children (iterator): a single RawText node for the link target.
        target (str): link target.
    )rW   mailtoz(?<!\\)(?:\\\\)*<([A-Za-z][A-Za-z0-9+.-]{1,31}:[^ <>]*?|[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*)>Fc                 C   s<   | | j}t|f| _|| _d| jv o4d| j v| _d S )N@rX   )r%   r&   r
   r+   rW   casefoldrX   rL   r   r   r   r*      s    zAutoLink.__init__N)
r9   r:   r;   rB   rU   rI   rN   r3   r$   r*   r   r   r   r   r      s
   
r   c                   @   s6   e Zd ZdZedZdZdZdd Z	e
dd Zd	S )
r   z
    Escape sequence token. ("\*")
    This is an inline token with a single child of type RawText.

    Attributes:
        children (iterator): a single RawText node containing the escaped character.
    z*\\([!\"#$%&'()*+,-./:;<=>?@\[\\\]^_`{|}~])FrF   c                 C   s   t || jf| _d S r#   )r
   r%   r&   r+   r'   r   r   r   r*      s    zEscapeSequence.__init__c                 C   s   t | jd|S )Nz\1)htmlunescaper3   subr5   r   r   r   rK      s    zEscapeSequence.stripN)r9   r:   r;   rB   rI   rN   r3   r$   r<   r*   r=   rK   r   r   r   r   r      s   
r   c                   @   s.   e Zd ZdZdZedZdZdZ	dd Z
dS )	r	   zW
    Line break token. Hard or soft.
    This is an inline token without children.
    )softz	( *|\\)\nFr   c                 C   s"   | d}|d | _d| _d S )Nr   )z  \ )r%   
startswithr^   r   rL   r   r   r   r*      s    
zLineBreak.__init__N)r9   r:   r;   rB   rU   rI   rN   r3   r$   r&   r*   r   r   r   r   r	      s   
r	   c                   @   s   e Zd ZdZdd ZdS )r
   z
    Raw text token.
    This is an inline token without children.

    RawText is the only token that accepts a string for its constructor,
    instead of a match object. Also, all recursions should bottom out here.
    c                 C   s
   || _ d S r#   r   )r(   r   r   r   r   r*      s    zRawText.__init__N)r9   r:   r;   rB   r*   r   r   r   r   r
      s   r
   >?   addressuldlbodyheadframesetZlegendsourcesummarytfootiframeformZmenuitemr[   tablebasefontsectioncolgroupfieldsetasidelinkdirmetah3tdthrR   dth4captionparamfooterddcolmenudetailsoptgrouphrcenteroldialognavtrack
figcaptionh1ph5divarticlelimainframetheadtbodytrbase
blockquotefigurenoframesh2optionh6headerz[A-Za-z][A-Za-z0-9-]*zT(?:\s+[A-Za-z_:][A-Za-z0-9_.:-]*(?:\s*=\s*(?:[^ "\'=<>`]+|\'[^\']*?\'|"[^\"]*?"))?)*z(?<!\\)<z\s*/?>z	(?<!\\)</z\s*>z)(?<!\\)<!--(?!>|->)(?:(?!--).)+?(?<!-)-->z(?<!\\)<\?.+?\?>z(?<!\\)<![A-Z].+?>z(?<!\\)<!\[CDATA.+?\]\]>c                
   @   s8   e Zd ZdZedeee	e
eegejZdZdZdS )HTMLSpanz
    Span-level HTML token.
    This is an inline token without children.

    Attributes:
        content (str): the raw HTML content.
    |Fr   N)r9   r:   r;   rB   rI   rN   rH   	_open_tag_closing_tag_comment_instruction_declaration_cdatarO   r3   r$   r&   r   r   r   r   r   	  s   r   c                   @   s"   e Zd ZdZedZdZdZdS )XWikiBlockMacroStartz
    A "block" macro opening tag. ("{{macroName<optionalParams>}}<newLine>") 
    
    We want to keep it on a separate line instead of "soft" merging it with the *following* line.
    z&(?<!\\)(\{\{\w+.*?(?<![\\/])\}\})\s*\nFr   N)	r9   r:   r;   rB   rI   rN   r3   r$   r&   r   r   r   r   r     s   
r   c                   @   s&   e Zd ZdZedejZdZdZ	dS )XWikiBlockMacroEndz
    A "block" macro closing tag. ("<onlySpacesAllowed>{{/macroName}}") 
    
    We want to keep it on a separate line instead of "soft" merging it with the *preceding* line.
    z^(?:\s*)(\{\{/\w+\}\})Fr   N)
r9   r:   r;   rB   rI   rN   	MULTILINEr3   r$   r&   r   r   r   r   r   #  s   r   )r   ))rB   r[   rI   Zmistletoe.span_tokenizerZspan_tokenizerr   Z	mistletoer   r   r   rA   r   r   r   r    Tokenr!   r   rC   rE   r   r   rP   rV   r   r   r	   r
   Z_tagsZ_tag_attrsr   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sH   



