o
    g:)                  
   @  s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ d	Zd
ZdZdZdddddddddd	Zde Zde ZdZdZdZde ZdZde Zde Zd e Zd!Zd"Zd#Zed$ ZG d%d& d&eZG d'd( d(eZ d)d* Z!d+S ),z
Adds conversion of ASCII dashes, quotes and ellipses to their HTML
entity equivalents.

See the [documentation](https://Python-Markdown.github.io/extensions/smarty)
for details.
    )annotations   )	Extension   )HtmlInlineProcessorHTML_RE)InlineProcessor)Registryz)[!"#\$\%'()*+,-.\/:;<=>?\@\[\\\]\^_`{|}~]z[\s.,;:!?)]z[^\ \t\r\n\[\{\(\-\u0002\u0003]u1   (\s|&nbsp;|--|–|—|&[mn]dash;|&#8211;|&#8212;)z&mdash;z&ndash;z&hellip;z&laquo;z&raquo;z&lsquo;z&rsquo;z&ldquo;z&rdquo;)	mdashndashellipsisleft-angle-quoteright-angle-quoteleft-single-quoteright-single-quoteleft-double-quoteright-double-quotez
^'(?=%s\B)z
^"(?=%s\B)z"'(?=\w)z'"(?=\w)z(?<!\w)'(?=\d{2}s)z	%s"(?=\w)z"(?=\s)z(?<=%s)"z	%s'(?=\w)z(?<=%s)'(?!\s|s\b|\d)z	'(\s|s\b)'"z(?!\>)c                   @  s   e Zd Zdd Zdd ZdS )SubstituteTextPatternc                 C  s   t | | || _|| _dS )z" Replaces matches with some text. N)r   __init__replacemd)selfpatternr   r    r   Z/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/markdown/extensions/smarty.pyr      s   
zSubstituteTextPattern.__init__c                 C  sR   d}| j D ]}t|tr|||7 }q|| jj|7 }q||d|dfS )N r   )	r   
isinstanceintgroupr   	htmlStashstorestartend)r   mdataresultpartr   r   r   handleMatch   s   

z!SubstituteTextPattern.handleMatchN)__name__
__module____qualname__r   r)   r   r   r   r   r      s    r   c                      sX   e Zd ZdZ fddZdd Zddd	Zdd
dZdddZdddZ	dd Z
  ZS )SmartyExtensionz Add Smarty to Markdown. c                   s^   ddgddgddgddgi dgd| _ 	 t jdi | tt| _| j| jd	i d
 d S )NTzEducate quotesFzEducate angled quoteszEducate dasheszEducate ellipseszOverwrite default substitutions)smart_quotessmart_angled_quotessmart_dashessmart_ellipsessubstitutionsr2   )defaultr   )configsuperr   dictr2   update	getConfig)r   kwargs	__class__r   r   r      s   
zSmartyExtension.__init__c                 C  sH   t |D ]\}}||f7 }t| }d||f }| j||||  qd S )Nzsmarty-%s-%d)	enumerater   inlinePatternsregister)r   r   patternsseriepriorityindr   namer   r   r   _addPatterns   s   
zSmartyExtension._addPatternsreturnNonec                 C  L   t d| jd f|}t d| jd f|}| j|dd | j|dd d S )	Nz(?<!-)---(?!-)r
   z(?<!-)--(?!-)r   zsmarty-em-dashes2   zsmarty-en-dashes-   r   r2   r=   r>   )r   r   emDashesPatternenDashesPatternr   r   r   educateDashes      zSmartyExtension.educateDashesc                 C  s(   t d| jd f|}| j|dd d S )Nz(?<!\.)\.{3}(?!\.)r   zsmarty-ellipses
   rJ   )r   r   ellipsesPatternr   r   r   educateEllipses   s   zSmartyExtension.educateEllipsesc                 C  rG   )	Nz\<\<r   z\>\>r   zsmarty-left-angle-quotes(   zsmarty-right-angle-quotes#   rJ   )r   r   leftAngledQuotePatternrightAngledQuotePatternr   r   r   educateAngledQuotes   rN   z#SmartyExtension.educateAngledQuotesc                 C  s   | j d }| j d }| j d }| j d }t|fft|fft|| fft|| fft|fftd|fft|fft|dfft	|fft
d|fft|fft|fft|fff}| ||dd d S )Nr   r   r   r   r   quotes   )r2   singleQuoteStartRedoubleQuoteStartRedoubleQuoteSetsResingleQuoteSetsRedecadeAbbrReopeningSingleQuotesRegexclosingSingleQuotesRegexclosingSingleQuotesRegex2remainingSingleQuotesRegexopeningDoubleQuotesRegexclosingDoubleQuotesRegexclosingDoubleQuotesRegex2remainingDoubleQuotesRegexrD   )r   r   lsquorsquoldquordquor?   r   r   r   educateQuotes   s&   






zSmartyExtension.educateQuotesc                 C  s   |   }t | _|d r| | |d r| | |d r.| | |jtt|dd |d r7| 	| t
|}| j|_|j|dd |jd	d
g d S )Nr1   r.   r/   htmlZ   r0   smartyr   r   r   )
getConfigsr	   r=   rQ   rj   rV   r>   r   HTML_STRICT_RErM   r   treeprocessorsESCAPED_CHARSextend)r   r   configsinlineProcessorr   r   r   extendMarkdown   s   



zSmartyExtension.extendMarkdown)rE   rF   )r*   r+   r,   __doc__r   rD   rM   rQ   rV   rj   ru   __classcell__r   r   r:   r   r-      s    





r-   c                  K  s   t di | S )Nr   )r-   )r9   r   r   r   makeExtension  s   rx   N)"rv   
__future__r   r   r   inlinepatternsr   r   rp   r   utilr	   
punctClassendOfWordClass
closeClassopeningQuotesBaser2   rY   rZ   r[   r\   r]   rb   rc   rd   r^   r_   r`   ra   re   ro   r   r-   rx   r   r   r   r   <module>   sL   NZ