B
    i|²b¤Ž  ã            !   @   s~  d Z ddlZddlZdZdZddddd	d
ddgZe d¡Ze d¡Ze d¡Z	e d¡Z
ejdejdZe dej¡Zddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4g!Zd5d6d7gZd8Zd9Zd:d; e¡ef Zd<Zd=d>„ Zd?d@„ ZdPdCd„ZdDdE„ ZdQdGdH„ZG dId„ deƒZG dJd„ deƒZG dKd„ deƒZG dLd„ deƒZG dMd	„ d	eƒZG dNd
„ d
eƒZ dRdOd„Z!dS )Sz”
    mistune
    ~~~~~~~

    The fastest markdown parser in pure Python with renderer feature.

    :copyright: (c) 2014 - 2018 by Hsiaoming Yang.
é    Nz0.8.4zHsiaoming Yang <me@lepture.com>ÚBlockGrammarÚ
BlockLexerÚInlineGrammarÚInlineLexerÚRendererÚMarkdownÚmarkdownÚescapez\s+z\Wz&(?!#?\w+;)z\r\n|\rz^ *> ?)Úflagsz^ {4}ÚaÚemÚstrongÚsmallÚsZciteÚqÚdfnZabbrÚdataÚtimeÚcodeÚvarZsampZkbdÚsubÚsupÚiÚbÚuÚmarkÚrubyÚrtÚrpZbdiZbdoÚspanÚbrÚwbrZinsÚdelÚimgÚfontÚpreÚscriptÚstylez(?!:/|[^\w\s@]*@)\bz7\s*[a-zA-Z\-](?:\s*\=\s*(?:"[^"]*"|'[^']*'|[^\s'">]+))?z(?!(?:%s)\b)\w+%sú|)zjavascript:z	vbscript:c             C   s    | j }| d¡r|dd … }|S )Nú^é   )ÚpatternÚ
startswith)Úregexr+   © r.   úJ/home/ankuromar296_gmail_com/.local/lib/python3.7/site-packages/mistune.pyÚ_pure_pattern+   s    
r0   c             C   s   t |  ¡ dd} t d| ¡S )NT)Úquoteú )r	   ÚlowerÚ_key_patternr   )Úkeyr.   r.   r/   Ú_keyify2   s    r6   FTc             C   sV   |rt  d| ¡} n|  dd¡} |  dd¡} |  dd¡} |rR|  dd¡} |  d	d
¡} | S )a3  Replace special characters "&", "<" and ">" to HTML-safe sequences.

    The original cgi.escape will always escape "&", but you can control
    this one for a smart escape amp.

    :param quote: if set to True, " and ' will be escaped.
    :param smart_amp: if set to False, & will always be escaped.
    z&amp;ú&ú<z&lt;ú>z&gt;ú"z&quot;ú'z&#39;)Ú_escape_patternr   Úreplace)Útextr1   Ú	smart_ampr.   r.   r/   r	   7   s    	c             C   sB   |   ¡  d¡}x$tD ]}t dd|¡ |¡rdS qW t| dddS )zDRemove dangerous URL schemes like javascript: and escape afterwards.z  
	z[^A-Za-z0-9\/:]+Ú TF)r1   r?   )r3   ÚstripÚ_scheme_blacklistÚrer   r,   r	   )ÚurlZ	lower_urlÚschemer.   r.   r/   Úescape_linkL   s
    
rF   é   c             C   s<   t  d| ¡} |  |¡} |  dd¡} t dtj¡}| d| ¡S )NÚ
u   â¤z^ +$r@   )Ú_newline_patternr   Ú
expandtabsr=   rC   ÚcompileÚM)r>   Útabr+   r.   r.   r/   ÚpreprocessingV   s
    
rN   c               @   s4  e Zd ZdZe d¡Ze d¡Ze d¡Ze d¡Z	e d¡Z
e d¡Ze d¡Ze d	¡Ze d
¡Ze deeƒeeƒf ¡ZejdejdZe d¡Ze dee
ƒ dd¡eeƒ dd¡eeƒeeƒeeƒeeƒeeƒeeƒde f	 ¡Ze dddeef deef f ¡Ze d¡Ze d¡Ze d¡ZdS )r   z Grammars for block level tokens.zB^ *\[([^^\]]+)\]: *<?([^\s>]+)>?(?: +["(]([^\n]+)[")])? *(?:\n+|$)z<^\[\^([^\]]+)\]: *([^\n]*(?:\n+|$)(?: {1,}[^\n]*(?:\n+|$))*)z^\n+z^( {4}[^\n]+\n*)+z:^ *(`{3,}|~{3,}) *([^`\s]+)? *\n([\s\S]+?)\s*\1 *(?:\n+|$)z&^ {0,3}[-*_](?: *[-*_]){2,} *(?:\n+|$)z%^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)z^([^\n]+)\n *(=|-)+ *(?:\n+|$)z^( *>[^\n]+(\n[^\n]+)*\n*)+z±^( *)(?=[*+-]|\d+\.)(([*+-])?(?:\d+\.)?) [\s\S]+?(?:\n+(?=\1?(?:[-*_] *){3,}(?:\n+|$))|\n+(?=%s)|\n+(?=%s)|\n+(?=\1(?(3)\d+\.|[*+-]) )|\n{2,}(?! )(?!\1(?:[*+-]|\d+\.) )\n*|\s*$)z@^(( *)(?:[*+-]|\d+\.) [^\n]*(?:\n(?!\2(?:[*+-]|\d+\.) )[^\n]*)*))r
   z^ *(?:[*+-]|\d+\.) +z2^((?:[^\n]+\n?(?!%s|%s|%s|%s|%s|%s|%s|%s|%s))+)\n*z\1z\2z\3r8   z ^ *(?:%s|%s|%s) *(?:\n{2,}|\s*$)z<!--[\s\S]*?-->z <(%s)((?:%s)*?)>([\s\S]*?)<\/\1>z<%s(?:%s)*?\s*\/?>z9^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*z=^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*z^[^\n]+N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__rC   rK   Ú	def_linksÚdef_footnotesÚnewlineÚ
block_codeÚfencesÚhruleÚheadingÚlheadingÚblock_quoter0   Ú
list_blockrL   Ú	list_itemÚlist_bulletr=   Ú
_block_tagÚ	paragraphÚ_valid_attrÚ
block_htmlÚtableÚnptabler>   r.   r.   r.   r/   r   ^   sT   








c               @   sì   e Zd ZdZeZdddddddd	d
ddddddgZdZdZd>dd„Z	d?dd„Z
d@dd„Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ Zd<d=„ ZdS )Ar   z%Block level lexer for block grammars.rU   rX   rV   rW   rY   rd   rZ   r[   r\   rb   rS   rT   rc   r`   r>   )	rU   rV   rW   rZ   rX   r[   r\   rb   r>   )rU   rV   rW   rY   rd   rZ   rX   r[   r\   rb   rc   r`   r>   Nc             K   sB   g | _ i | _i | _|s|  ¡ }|| _| dd¡| _d| _d| _d S )NZmax_recursive_depthé   r   )	ÚtokensrS   rT   Úgrammar_classÚrulesÚgetÚ_max_recursive_depthÚ_list_depthÚ_blockquote_depth)Úselfrh   Úkwargsr.   r.   r/   Ú__init__Ã   s    zBlockLexer.__init__c             C   s   |   ||¡S )N)Úparse)rm   r>   rh   r.   r.   r/   Ú__call__Ð   s    zBlockLexer.__call__c                sj   |  d¡}ˆ sˆj‰ ‡ ‡fdd„}x@|rb||ƒ}|dk	rP|t| d¡ƒd … }q$|r$td| ƒ‚q$W ˆjS )NrH   c                sB   x<ˆ D ]4}t ˆj|ƒ}| | ¡}|s&qt ˆd| ƒ|ƒ |S W dS )Nzparse_%sF)Úgetattrrh   Úmatch)r>   r5   ÚruleÚm)rh   rm   r.   r/   Ú
manipulateÙ   s    

z$BlockLexer.parse.<locals>.manipulateFr   zInfinite loop at: %s)ÚrstripÚdefault_rulesÚlenÚgroupÚRuntimeErrorrf   )rm   r>   rh   rv   ru   r.   )rh   rm   r/   rp   Ó   s    

zBlockLexer.parsec             C   s*   t | d¡ƒ}|dkr&| j ddi¡ d S )Nr   r*   ÚtyperU   )ry   rz   rf   Úappend)rm   ru   Úlengthr.   r.   r/   Úparse_newlineì   s    zBlockLexer.parse_newlinec             C   s*   t  d| d¡¡}| j dd |dœ¡ d S )Nr@   r   r   )r|   Úlangr>   )Ú_block_code_leading_patternr   rz   rf   r}   )rm   ru   r   r.   r.   r/   Úparse_block_codeñ   s
    zBlockLexer.parse_block_codec             C   s$   | j  d| d¡| d¡dœ¡ d S )Nr   é   é   )r|   r€   r>   )rf   r}   rz   )rm   ru   r.   r.   r/   Úparse_fencesú   s    zBlockLexer.parse_fencesc             C   s(   | j  dt| d¡ƒ| d¡dœ¡ d S )NrY   r*   rƒ   )r|   Úlevelr>   )rf   r}   ry   rz   )rm   ru   r.   r.   r/   Úparse_heading  s    zBlockLexer.parse_headingc             C   s0   | j  d| d¡dkrdnd| d¡dœ¡ dS )zParse setext heading.rY   rƒ   ú=r*   )r|   r†   r>   N)rf   r}   rz   )rm   ru   r.   r.   r/   Úparse_lheading  s    zBlockLexer.parse_lheadingc             C   s   | j  ddi¡ d S )Nr|   rX   )rf   r}   )rm   ru   r.   r.   r/   Úparse_hrule  s    zBlockLexer.parse_hrulec             C   sž   |  d¡}| j dd|kdœ¡ |  jd7  _| j| jkrf| j ddi¡ |  |¡ | j ddi¡ n|  d	¡}|  ||¡ | j dd
i¡ |  jd8  _d S )Nrƒ   Z
list_startÚ.)r|   Úorderedr*   r|   Úlist_item_startÚlist_item_endr   Úlist_end)rz   rf   r}   rk   rj   Ú
parse_textÚ_process_list_item)rm   ru   ÚbullÚcapr.   r.   r/   Úparse_list_block  s    


zBlockLexer.parse_list_blockc             C   s  | j j |¡}d}t|ƒ}xìt|ƒD ]à}|| d }t|ƒ}| j j d|¡}d|kr€|t|ƒ }tjd| tj	d}| d|¡}|}	|	s˜t 
d|¡r˜d}	t|ƒ}
||d	 krÈ|
rÈ||
d	  d
k}|	sÈ|}	|	rÒd}nd}| j d|i¡ |  || j¡ | j ddi¡ q$W d S )NFr   r@   z
 z^ {1,%d})r
   z\n\n(?!\s*$)Tr*   rH   Zloose_item_startr   r|   rŽ   )rh   r]   Úfindallry   Úranger^   r   rC   rK   rL   Úsearchrf   r}   rp   Ú
list_rules)rm   r“   r’   Ú_nextr~   r   ÚitemÚspacer+   ÚlooseÚrestÚtr.   r.   r/   r‘   $  s2    zBlockLexer._process_list_itemc             C   st   | j  ddi¡ |  jd7  _| j| jkr6|  |¡ nt d| d¡¡}|  |¡ | j  ddi¡ |  jd8  _d S )Nr|   Zblock_quote_startr*   r@   r   Úblock_quote_end)	rf   r}   rl   rj   r   Ú_block_quote_leading_patternr   rz   rp   )rm   ru   r“   r.   r.   r/   Úparse_block_quoteL  s    
zBlockLexer.parse_block_quotec             C   s.   t | d¡ƒ}| d¡| d¡dœ| j|< d S )Nr*   rƒ   r„   )ÚlinkÚtitle)r6   rz   rS   )rm   ru   r5   r.   r.   r/   Úparse_def_linksX  s    zBlockLexer.parse_def_linksc       	      C   sö   t | d¡ƒ}|| jkrd S d| j|< | j d|dœ¡ | d¡}d|krÒ| d¡}d }x<|dd … D ],}t|ƒt| ¡ ƒ }|rf|rŽ||k rf|}qfW |d g}x&|dd … D ]}| ||d … ¡ q®W d |¡}|  	|| j
¡ | j d|dœ¡ d S )Nr*   r   Zfootnote_start)r|   r5   rƒ   rH   Úfootnote_end)r6   rz   rT   rf   r}   Úsplitry   ÚlstripÚjoinrp   Úfootnote_rules)	rm   ru   r5   r>   ÚlinesÚ
whitespaceÚliner›   Únewlinesr.   r.   r/   Úparse_def_footnotes_  s.    






zBlockLexer.parse_def_footnotesc             C   sz   |   |¡}t dd| d¡¡}| d¡}x2t|ƒD ]&\}}t dd|¡}t d|¡||< q2W |  |¡|d< | j |¡ d S )Nz(?: *\| *)?\n$r@   r„   rH   z^ *\| *| *\| *$z *(?<!\\)\| *Úcells)	Ú_process_tablerC   r   rz   r¦   Ú	enumerateÚ_process_cellsrf   r}   )rm   ru   rš   r¯   r   Úvr.   r.   r/   Úparse_table  s    

zBlockLexer.parse_tablec             C   sl   |   |¡}t dd| d¡¡}| d¡}x$t|ƒD ]\}}t d|¡||< q2W |  |¡|d< | j |¡ d S )Nz\n$r@   r„   rH   z *(?<!\\)\| *r¯   )	r°   rC   r   rz   r¦   r±   r²   rf   r}   )rm   ru   rš   r¯   r   r³   r.   r.   r/   Úparse_nptable  s    

zBlockLexer.parse_nptablec             C   s°   t  dd| d¡¡}t  d|¡}t  dd| d¡¡}t  d|¡}x^t|ƒD ]R\}}t  d|¡rhd||< qJt  d	|¡r~d
||< qJt  d|¡r”d||< qJd ||< qJW d||dœ}|S )Nz^ *| *\| *$r@   r*   z *\| *z *|\| *$rƒ   z	^ *-+: *$Úrightz
^ *:-+: *$Úcenterz	^ *:-+ *$Úleftrc   )r|   ÚheaderÚalign)rC   r   rz   r¦   r±   r—   )rm   ru   r¹   rº   r   r³   rš   r.   r.   r/   r°   ˜  s     


zBlockLexer._process_tablec             C   sF   x@t |ƒD ]4\}}x*t |ƒD ]\}}t dd|¡|| |< qW q
W |S )Nz\\\|r(   )r±   rC   r   )rm   r¯   r   r¬   ÚcÚcellr.   r.   r/   r²   ¯  s    zBlockLexer._process_cellsc             C   sZ   |  d¡}|s,|  d¡}| j d|dœ¡ n*|  d¡}|  d¡}| j d|||dœ¡ d S )	Nr*   r   Z
close_html)r|   r>   rƒ   r„   Z	open_html)r|   ÚtagÚextrar>   )rz   rf   r}   )rm   ru   r½   r>   Úattrr.   r.   r/   Úparse_block_html·  s    



zBlockLexer.parse_block_htmlc             C   s&   |  d¡ d¡}| j d|dœ¡ d S )Nr*   rH   r`   )r|   r>   )rz   rw   rf   r}   )rm   ru   r>   r.   r.   r/   Úparse_paragraphÉ  s    zBlockLexer.parse_paragraphc             C   s    |  d¡}| j d|dœ¡ d S )Nr   r>   )r|   r>   )rz   rf   r}   )rm   ru   r>   r.   r.   r/   r   Í  s    
zBlockLexer.parse_text)N)N)N)rO   rP   rQ   rR   r   rg   rx   r˜   r©   ro   rq   rp   r   r‚   r…   r‡   r‰   rŠ   r”   r‘   r¡   r¤   r®   r´   rµ   r°   r²   rÀ   rÁ   r   r.   r.   r.   r/   r   ­   s:   



	("c               @   s¾   e Zd ZdZe d¡Ze dddeef deef f ¡Z	e d¡Z
e d¡Ze d	¡Ze d
¡Ze d¡Ze d¡Ze d¡Ze d¡Ze d¡Ze d¡Ze d¡Ze d¡Zdd„ ZdS )r   z!Grammars for inline level tokens.z^\\([\\`*{}\[\]()#+\-.!_>~|])z^(?:%s|%s|%s)z<!--[\s\S]*?-->z&<(\w+%s)((?:%s)*?)\s*>([\s\S]*?)<\/\1>z<\w+%s(?:%s)*?\s*\/?>z^<([^ >]+(@|:)[^ >]+)>zi^!?\[((?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\(\s*(<)?([\s\S]*?)(?(2)>)(?:\s+['"]([\s\S]*?)['"])?\s*\)z@^!?\[((?:\[[^^\]]*\]|[^\[\]]|\](?=[^\[]*\]))*)\]\s*\[([^^\]]*)\]z ^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]z$^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])z4^_{2}([\s\S]+?)_{2}(?!_)|^\*{2}([\s\S]+?)\*{2}(?!\*)z4^\b_((?:__|[^_])+?)_\b|^\*((?:\*\*|[^\*])+?)\*(?!\*)z ^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)z^ {2,}\n(?!\s*$)z^~~(?=\S)([\s\S]*?\S)~~z^\[\^([^\]]+)\]z-^[\s\S]+?(?=[\\<!\[_*`~]|https?://| {2,}\n|$)c             C   s   t  d¡| _t  d¡| _dS )zhGrammar for hard wrap linebreak. You don't need to add two
        spaces at the end of a line.
        z^ *\n(?!\s*$)z*^[\s\S]+?(?=[\\<!\[_*`~]|https?://| *\n|$)N)rC   rK   Ú	linebreakr>   )rm   r.   r.   r/   Ú	hard_wrapý  s    zInlineGrammar.hard_wrapN)rO   rP   rQ   rR   rC   rK   r	   Ú
_valid_endra   Úinline_htmlÚautolinkr¢   ÚreflinkÚnolinkrD   Údouble_emphasisÚemphasisr   rÂ   ÚstrikethroughÚfootnoter>   rÃ   r.   r.   r.   r/   r   Ò  s2   








c               @   sò   e Zd ZdZeZdddddddd	d
dddddgZddddddd	d
dddddgZd7dd„Zd8dd„Z	dd„ Z
d9dd„Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd:d)d*„Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ ZdS );r   z'Inline level lexer for inline grammars.r	   rÅ   rÆ   rD   rÌ   r¢   rÇ   rÈ   rÉ   rÊ   r   rÂ   rË   r>   Nc             K   sf   || _ i | _i | _d| _|s$|  ¡ }| | j j¡ | d¡rD| ¡  || _	d| _
d| _| d¡| _d S )Nr   rÃ   FZparse_inline_html)ÚrendererÚlinksÚ	footnotesÚfootnote_indexrg   ÚupdateÚoptionsri   rÃ   rh   Ú_in_linkÚ_in_footnoteÚ_parse_inline_html)rm   rÍ   rh   rn   r.   r.   r/   ro     s    
zInlineLexer.__init__c             C   s   |   ||¡S )N)Úoutput)rm   r>   rh   r.   r.   r/   rq   *  s    zInlineLexer.__call__c             C   s   d| _ |pi | _|pi | _d S )Nr   )rÐ   rÎ   rÏ   )rm   rÎ   rÏ   r.   r.   r/   Úsetup-  s    
zInlineLexer.setupc                sž   |  d¡}ˆ stˆjƒ‰ ˆjr0dˆ kr0ˆ  d¡ ˆj ¡ }‡ ‡fdd„}xP|r˜||ƒ}|dk	r†|\}}||7 }|t| d¡ƒd … }qJ|rJt	d| ƒ‚qJW |S )NrH   rÌ   c                sV   xPˆ D ]H}t ˆj|ƒ}| | ¡}|s&q|ˆ_t ˆd| ƒ|ƒ}|d k	r||fS qW dS )Nz	output_%sF)rr   rh   rs   Z
line_match)r>   r5   r+   ru   Úout)rh   rm   r.   r/   rv   <  s    

z&InlineLexer.output.<locals>.manipulateFr   zInfinite loop at: %s)
rw   Úlistrx   rÔ   ÚremoverÍ   Úplaceholderry   rz   r{   )rm   r>   rh   rÖ   rv   Úretru   rØ   r.   )rh   rm   r/   rÖ   2  s"    



zInlineLexer.outputc             C   s   |  d¡}| j |¡S )Nr*   )rz   rÍ   r	   )rm   ru   r>   r.   r.   r/   Úoutput_escapeT  s    
zInlineLexer.output_escapec             C   s0   |  d¡}|  d¡dkrd}nd}| j ||¡S )Nr*   rƒ   ú@TF)rz   rÍ   rÆ   )rm   ru   r¢   Úis_emailr.   r.   r/   Úoutput_autolinkX  s
    
zInlineLexer.output_autolinkc             C   s*   |  d¡}| jr| j |¡S | j |d¡S )Nr*   F)rz   rÓ   rÍ   r>   rÆ   )rm   ru   r¢   r.   r.   r/   Ú
output_url`  s    
zInlineLexer.output_urlc             C   sŽ   |  d¡}| jrx|tkrx|  d¡}|dkrHd| _| j|| jd}d| _n| j|| jd}|  d¡pdd}d	||||f }n
|  d
¡}| j |¡S )Nr*   r„   r   T)rh   Frƒ   r@   z<%s%s>%s</%s>r   )rz   rÕ   Ú_inline_tagsrÓ   rÖ   Úinline_html_rulesrÍ   rÅ   )rm   ru   r½   r>   r¾   Úhtmlr.   r.   r/   Úoutput_inline_htmlf  s    


zInlineLexer.output_inline_htmlc             C   sT   t | d¡ƒ}|| jkrd S | j| r*d S |  jd7  _| j| j|< | j || j¡S )Nr*   )r6   rz   rÏ   rÐ   rÍ   Úfootnote_ref)rm   ru   r5   r.   r.   r/   Úoutput_footnotev  s    

zInlineLexer.output_footnotec             C   s   |   || d¡| d¡¡S )Nr„   rG   )Ú_process_linkrz   )rm   ru   r.   r.   r/   Úoutput_link€  s    zInlineLexer.output_linkc             C   sF   t | d¡p| d¡ƒ}|| jkr&d S | j| }|  ||d |d ¡S )Nrƒ   r*   r¢   r£   )r6   rz   rÎ   rè   )rm   ru   r5   rÜ   r.   r.   r/   Úoutput_reflinkƒ  s
    

zInlineLexer.output_reflinkc             C   s<   t | d¡ƒ}|| jkrd S | j| }|  ||d |d ¡S )Nr*   r¢   r£   )r6   rz   rÎ   rè   )rm   ru   r5   rÜ   r.   r.   r/   Úoutput_nolinkŠ  s
    

zInlineLexer.output_nolinkc             C   sV   |  d¡}|  d¡}|d dkr0| j |||¡S d| _|  |¡}d| _| j |||¡S )Nr   r*   ú!TF)rz   rÍ   ÚimagerÓ   rÖ   r¢   )rm   ru   r¢   r£   r¬   r>   r.   r.   r/   rè   ‘  s    


zInlineLexer._process_linkc             C   s*   |  d¡p|  d¡}|  |¡}| j |¡S )Nrƒ   r*   )rz   rÖ   rÍ   rÉ   )rm   ru   r>   r.   r.   r/   Úoutput_double_emphasisœ  s    
z"InlineLexer.output_double_emphasisc             C   s*   |  d¡p|  d¡}|  |¡}| j |¡S )Nrƒ   r*   )rz   rÖ   rÍ   rÊ   )rm   ru   r>   r.   r.   r/   Úoutput_emphasis¡  s    
zInlineLexer.output_emphasisc             C   s   |  d¡}| j |¡S )Nrƒ   )rz   rÍ   Úcodespan)rm   ru   r>   r.   r.   r/   Úoutput_code¦  s    
zInlineLexer.output_codec             C   s
   | j  ¡ S )N)rÍ   rÂ   )rm   ru   r.   r.   r/   Úoutput_linebreakª  s    zInlineLexer.output_linebreakc             C   s   |   | d¡¡}| j |¡S )Nr*   )rÖ   rz   rÍ   rË   )rm   ru   r>   r.   r.   r/   Úoutput_strikethrough­  s    z InlineLexer.output_strikethroughc             C   s   |  d¡}| j |¡S )Nr   )rz   rÍ   r>   )rm   ru   r>   r.   r.   r/   Úoutput_text±  s    
zInlineLexer.output_text)N)N)N)N)rO   rP   rQ   rR   r   rg   rx   rã   ro   rq   r×   rÖ   rÝ   rà   rá   rå   rç   ré   rê   rë   rè   rî   rï   rñ   rò   ró   rô   r.   r.   r.   r/   r     s8   




"

c               @   sø   e Zd ZdZdd„ Zdd„ Zd=dd„Zd	d
„ Zdd„ Zd>dd„Z	dd„ Z
d?dd„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd@d-d.„Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ ZdS )Ar   z6The default HTML renderer for rendering Markdown.
    c             K   s
   || _ d S )N)rÒ   )rm   rn   r.   r.   r/   ro   º  s    zRenderer.__init__c             C   s   dS )a  Returns the default, empty output value for the renderer.

        All renderer methods use the '+=' operator to append to this value.
        Default is a string so rendering HTML can build up a result string with
        the rendered Markdown.

        Can be overridden by Renderer subclasses to be types like an empty
        list, allowing the renderer to create a tree-like structure to
        represent the document (which can then be reprocessed later into a
        separate format like docx or pdf).
        r@   r.   )rm   r.   r.   r/   rÛ   ½  s    zRenderer.placeholderNc             C   s<   |  d¡}|s"t|dd}d| S t|ddd}d||f S )z›Rendering block level code. ``pre > code``.

        :param code: text content of the code block.
        :param lang: language of the given code.
        rH   F)r?   z<pre><code>%s
</code></pre>
T)r1   r?   z,<pre><code class="lang-%s">%s
</code></pre>
)rw   r	   )rm   r   r€   r.   r.   r/   rV   Ë  s    
zRenderer.block_codec             C   s   d|  d¡ S )zjRendering <blockquote> with the given text.

        :param text: text content of the blockquote.
        z<blockquote>%s
</blockquote>
rH   )rw   )rm   r>   r.   r.   r/   r[   Ø  s    zRenderer.block_quotec             C   s6   | j  d¡r| ¡  d¡rdS | j  d¡r2t|ƒS |S )ziRendering block level pure html content.

        :param html: text content of the html snippet.
        Z
skip_stylez<styler@   r	   )rÒ   ri   r3   r,   r	   )rm   rä   r.   r.   r/   rb   ß  s    zRenderer.block_htmlc             C   s   d|||f S )zóRendering header/heading tags like ``<h1>`` ``<h2>``.

        :param text: rendered text content for the header.
        :param level: a number for the header level, for example: 1.
        :param raw: raw text content of the header.
        z<h%d>%s</h%d>
r.   )rm   r>   r†   Úrawr.   r.   r/   r¹   ë  s    zRenderer.headerc             C   s   | j  d¡rdS dS )z"Rendering method for ``<hr>`` tag.Ú	use_xhtmlz<hr />
z<hr>
)rÒ   ri   )rm   r.   r.   r/   rX   ô  s    zRenderer.hruleTc             C   s   d}|rd}d|||f S )z¦Rendering list tags like ``<ul>`` and ``<ol>``.

        :param body: body contents of the list.
        :param ordered: whether this list is ordered or not.
        ÚulÚolz<%s>
%s</%s>
r.   )rm   ÚbodyrŒ   r½   r.   r.   r/   rÙ   ú  s    zRenderer.listc             C   s   d| S )z+Rendering list item snippet. Like ``<li>``.z<li>%s</li>
r.   )rm   r>   r.   r.   r/   r]     s    zRenderer.list_itemc             C   s   d|  d¡ S )z'Rendering paragraph tags. Like ``<p>``.z
<p>%s</p>
r2   )rA   )rm   r>   r.   r.   r/   r`   	  s    zRenderer.paragraphc             C   s   d||f S )zœRendering table element. Wrap header and body in it.

        :param header: header part of the table.
        :param body: body part of the table.
        z6<table>
<thead>%s</thead>
<tbody>
%s</tbody>
</table>
r.   )rm   r¹   rù   r.   r.   r/   rc     s    zRenderer.tablec             C   s   d| S )zeRendering a table row. Like ``<tr>``.

        :param content: content of current table row.
        z<tr>
%s</tr>
r.   )rm   Úcontentr.   r.   r/   Ú	table_row  s    zRenderer.table_rowc             K   s<   |d rd}nd}|d }|s,d|||f S d||||f S )zÙRendering a table cell. Like ``<th>`` ``<td>``.

        :param content: content of current table cell.
        :param header: whether this is header or not.
        :param align: align of current table cell.
        r¹   ÚthÚtdrº   z<%s>%s</%s>
z"<%s style="text-align:%s">%s</%s>
r.   )rm   rú   r
   r½   rº   r.   r.   r/   Ú
table_cell  s    zRenderer.table_cellc             C   s   d| S )zTRendering **strong** text.

        :param text: text content for emphasis.
        z<strong>%s</strong>r.   )rm   r>   r.   r.   r/   rÉ   1  s    zRenderer.double_emphasisc             C   s   d| S )zTRendering *emphasis* text.

        :param text: text content for emphasis.
        z<em>%s</em>r.   )rm   r>   r.   r.   r/   rÊ   8  s    zRenderer.emphasisc             C   s   t | ¡ dd}d| S )zZRendering inline `code` text.

        :param text: text content for inline code.
        F)r?   z<code>%s</code>)r	   rw   )rm   r>   r.   r.   r/   rð   ?  s    zRenderer.codespanc             C   s   | j  d¡rdS dS )z#Rendering line break like ``<br>``.rö   z<br />
z<br>
)rÒ   ri   )rm   r.   r.   r/   rÂ   G  s    zRenderer.linebreakc             C   s   d| S )z`Rendering ~~strikethrough~~ text.

        :param text: text content for strikethrough.
        z<del>%s</del>r.   )rm   r>   r.   r.   r/   rË   M  s    zRenderer.strikethroughc             C   s   | j  d¡r|S t|ƒS )zHRendering unformatted text.

        :param text: text content.
        rÀ   )rÒ   ri   r	   )rm   r>   r.   r.   r/   r>   T  s    zRenderer.textc             C   s   t |ƒS )zGRendering escape sequence.

        :param text: text content.
        )r	   )rm   r>   r.   r.   r/   r	   ]  s    zRenderer.escapeFc             C   s$   t |ƒ }}|rd| }d||f S )z Rendering a given link or email address.

        :param link: link content or email address.
        :param is_email: whether this is an email or not.
        z	mailto:%sz<a href="%s">%s</a>)rF   )rm   r¢   rß   r>   r.   r.   r/   rÆ   d  s    zRenderer.autolinkc             C   s2   t |ƒ}|sd||f S t|dd}d|||f S )zÖRendering a given link with content and title.

        :param link: href link for ``<a>`` tag.
        :param title: title content for `title` attribute.
        :param text: text content for description.
        z<a href="%s">%s</a>T)r1   z<a href="%s" title="%s">%s</a>)rF   r	   )rm   r¢   r£   r>   r.   r.   r/   r¢   o  s
    zRenderer.linkc             C   s\   t |ƒ}t|dd}|r4t|dd}d|||f }nd||f }| j d¡rTd| S d| S )z¹Rendering a image with title and text.

        :param src: source link of the image.
        :param title: title text of the image.
        :param text: alt text of the image.
        T)r1   z!<img src="%s" alt="%s" title="%s"z<img src="%s" alt="%s"rö   z%s />z%s>)rF   r	   rÒ   ri   )rm   Úsrcr£   r>   rä   r.   r.   r/   rí   |  s    zRenderer.imagec             C   s   | j  d¡rt|ƒS |S )zhRendering span level pure html content.

        :param html: text content of the html snippet.
        r	   )rÒ   ri   r	   )rm   rä   r.   r.   r/   rÅ   Ž  s    zRenderer.inline_htmlc             C   s   dS )zRendering newline element.r@   r.   )rm   r.   r.   r/   rU   —  s    zRenderer.newlinec             C   s   dt |ƒt |ƒ|f }|S )zŸRendering the ref anchor of a footnote.

        :param key: identity key for the footnote.
        :param index: the index count of current footnote.
        zE<sup class="footnote-ref" id="fnref-%s"><a href="#fn-%s">%d</a></sup>)r	   )rm   r5   Úindexrä   r.   r.   r/   ræ   ›  s    zRenderer.footnote_refc             C   sR   dt |ƒ }| ¡ }| d¡r2t dd| |¡}nd||f }dt |ƒ|f }|S )zŠRendering a footnote item.

        :param key: identity key for the footnote.
        :param text: text content of the footnote.
        z0<a href="#fnref-%s" class="footnote">&#8617;</a>z</p>z<\/p>$z%s</p>z%s<p>%s</p>z<li id="fn-%s">%s</li>
)r	   rw   ÚendswithrC   r   )rm   r5   r>   Úbackrä   r.   r.   r/   Úfootnote_item§  s    

zRenderer.footnote_itemc             C   s   d}||   ¡ |f S )zTWrapper for all footnotes.

        :param text: contents of all footnotes.
        z-<div class="footnotes">
%s<ol>%s</ol>
</div>
)rX   )rm   r>   rä   r.   r.   r/   rÏ   ¸  s    zRenderer.footnotes)N)N)T)F) rO   rP   rQ   rR   ro   rÛ   rV   r[   rb   r¹   rX   rÙ   r]   r`   rc   rû   rþ   rÉ   rÊ   rð   rÂ   rË   r>   r	   rÆ   r¢   rí   rÅ   rU   ræ   r  rÏ   r.   r.   r.   r/   r   ¶  s:   

	
	
	c               @   sÌ   e Zd ZdZd1dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	d2dd„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ ZdS )3r   zµThe Markdown parser.

    :param renderer: An instance of ``Renderer``.
    :param inline: An inline lexer class or instance.
    :param block: A block lexer class or instance.
    Nc             K   sš   |st f |Ž}n| |j¡ || _|r<t |¡r<||f|Ž}|rTt |¡rT|f |Ž}|r`|| _nt|f|Ž| _|pztt	ƒ ƒ| _
g | _g | _| d¡| _d S )NrÀ   )r   rÑ   rÒ   rÍ   ÚinspectÚisclassÚinliner   r   r   ÚblockrÏ   rf   ri   Ú_parse_block_html)rm   rÍ   r  r  rn   r.   r.   r/   ro   È  s    
zMarkdown.__init__c             C   s
   |   |¡S )N)rp   )rm   r>   r.   r.   r/   rq   á  s    zMarkdown.__call__c             C   s
   |   |¡S )zYRender the Markdown text.

        :param text: markdown formatted text content.
        )rp   )rm   r>   r.   r.   r/   Úrenderä  s    zMarkdown.renderc                sº   |   t|ƒ¡}| jj‰ i | j_i | j_i | j_i | j_| js@|S t‡ fdd„| jƒ}t	|‡ fdd„dd| _| j
 ¡ }x.| jr¤| j ¡ }|| j
 |d |d ¡7 }qxW || j
 |¡7 }|S )Nc                s   ˆ   | d ¡S )Nr5   )ri   )Úo)Úkeysr.   r/   Ú<lambda>û  ó    z Markdown.parse.<locals>.<lambda>c                s   ˆ   | d ¡S )Nr5   )ri   )r
  )r  r.   r/   r  ý  r  T)r5   Úreverser5   r>   )rÖ   rN   r  rT   rS   r  rÎ   rÏ   ÚfilterÚsortedrÍ   rÛ   Úpopr  )rm   r>   rØ   rÏ   rù   Znoter.   )r  r/   rp   ë  s$    

zMarkdown.parsec             C   s   | j s
d S | j  ¡ | _| jS )N)rf   r  Útoken)rm   r.   r.   r/   r  
  s    zMarkdown.popc             C   s   | j r| j d S d S )Néÿÿÿÿ)rf   )rm   r.   r.   r/   Úpeek  s    
zMarkdown.peekc             C   sV   |   ||¡| _| j ¡  | j | j j| j j¡ | j ¡ }x|  	¡ rP||  
¡ 7 }q:W |S )N)r  rf   r  r  r×   rS   rT   rÍ   rÛ   r  Útok)rm   r>   rh   rØ   r.   r.   r/   rÖ     s    


zMarkdown.outputc             C   s0   | j d }| d¡r |d d… }t| d| ƒƒ S )Nr|   Ú_startiúÿÿÿz	output_%s)r  r  rr   )rm   rž   r.   r.   r/   r     s    

zMarkdown.tokc             C   s>   | j d }x(|  ¡ d dkr2|d|  ¡ d  7 }qW |  |¡S )Nr>   r|   rH   )r  r  r  r  )rm   r>   r.   r.   r/   Útok_text)  s    
zMarkdown.tok_textc             C   s
   | j  ¡ S )N)rÍ   rU   )rm   r.   r.   r/   Úoutput_newline/  s    zMarkdown.output_newlinec             C   s
   | j  ¡ S )N)rÍ   rX   )rm   r.   r.   r/   Úoutput_hrule2  s    zMarkdown.output_hrulec             C   s(   | j  |  | jd ¡| jd | jd ¡S )Nr>   r†   )rÍ   r¹   r  r  )rm   r.   r.   r/   Úoutput_heading5  s    zMarkdown.output_headingc             C   s   | j  | jd | jd ¡S )Nr>   r€   )rÍ   rV   r  )rm   r.   r.   r/   rñ   <  s    zMarkdown.output_codec             C   s&  | j d }t|ƒ}| j ¡ }| j ¡ }xRt| j d ƒD ]@\}}||k rN|| nd }d|dœ}|| jj|  |¡f|Ž7 }q6W || j |¡7 }| j ¡ }	x‚t| j d ƒD ]p\}}
| j ¡ }xLt|
ƒD ]@\}}||k rØ|| nd }d|dœ}|| jj|  |¡f|Ž7 }qÀW |	| j |¡7 }	q¤W | j ||	¡S )Nrº   r¹   T)r¹   rº   r¯   F)	r  ry   rÍ   rÛ   r±   rþ   r  rû   rc   )rm   ZalignsZaligns_lengthr¼   r¹   r   Úvaluerº   r
   rù   ÚrowÚjr.   r.   r/   Úoutput_tableA  s$    






zMarkdown.output_tablec             C   s8   | j  ¡ }x |  ¡ d dkr*||  ¡ 7 }qW | j  |¡S )Nr|   rŸ   )rÍ   rÛ   r  r  r[   )rm   rù   r.   r.   r/   Úoutput_block_quote[  s    
zMarkdown.output_block_quotec             C   sD   | j d }| j ¡ }x |  ¡ d dkr4||  ¡ 7 }qW | j ||¡S )NrŒ   r|   r   )r  rÍ   rÛ   r  r  rÙ   )rm   rŒ   rù   r.   r.   r/   Úoutput_lista  s
    

zMarkdown.output_listc             C   sT   | j  ¡ }x<|  ¡ d dkrF| jd dkr8||  ¡ 7 }q||  ¡ 7 }qW | j  |¡S )Nr|   rŽ   r>   )rÍ   rÛ   r  r  r  r  r]   )rm   rù   r.   r.   r/   Úoutput_list_itemh  s    
zMarkdown.output_list_itemc             C   s8   | j  ¡ }x |  ¡ d dkr*||  ¡ 7 }qW | j  |¡S )Nr|   rŽ   )rÍ   rÛ   r  r  r]   )rm   rù   r.   r.   r/   Úoutput_loose_itemr  s    
zMarkdown.output_loose_itemc             C   sb   d| j _| j ¡ }| jd }x |  ¡ d dkr<||  ¡ 7 }qW | j ||dœ¡ d| j _| j ¡ S )NTr5   r|   r¥   )r5   r>   F)	r  rÔ   rÍ   rÛ   r  r  r  rÏ   r}   )rm   rù   r5   r.   r.   r/   rç   x  s    

zMarkdown.output_footnotec             C   s   | j d }| j |¡S )Nr>   )r  rÍ   rb   )rm   r>   r.   r.   r/   Úoutput_close_html‚  s    
zMarkdown.output_close_htmlc             C   s`   | j d }| j d }| jr4|tkr4| j|| jjd}| j  d¡pBd}d||||f }| j |¡S )Nr>   r½   )rh   r¾   r@   z<%s%s>%s</%s>)r  r  Ú	_pre_tagsr  rã   ri   rÍ   rb   )rm   r>   r½   r¾   rä   r.   r.   r/   Úoutput_open_html†  s    

zMarkdown.output_open_htmlc             C   s   | j  |  | jd ¡¡S )Nr>   )rÍ   r`   r  r  )rm   r.   r.   r/   Úoutput_paragraph  s    zMarkdown.output_paragraphc             C   s   | j  |  ¡ ¡S )N)rÍ   r`   r  )rm   r.   r.   r/   rô   ’  s    zMarkdown.output_text)NNN)N)rO   rP   rQ   rR   ro   rq   r	  rp   r  r  rÖ   r  r  r  r  r  rñ   r  r  r   r!  r"  rç   r#  r%  r&  rô   r.   r.   r.   r/   r   Á  s0   

	

	c             K   s   t f d|i|—Ž| ƒS )a©  Render markdown formatted text to html.

    :param text: markdown formatted text content.
    :param escape: if set to False, all html tags will not be escaped.
    :param use_xhtml: output with xhtml tags.
    :param hard_wrap: if set to True, it will use the GFM line breaks feature.
    :param parse_block_html: parse text only in block level html.
    :param parse_inline_html: parse text only in inline level html.
    r	   )r   )r>   r	   rn   r.   r.   r/   r   –  s    
)FT)rG   )T)"rR   rC   r  Ú__version__Ú
__author__Ú__all__rK   r4   Z_nonalpha_patternr<   rI   rL   r    r   râ   r$  rÄ   ra   r¨   r_   rB   r0   r6   r	   rF   rN   Úobjectr   r   r   r   r   r   r   r.   r.   r.   r/   Ú<module>	   sR   







O  '5 0   V