o
    >h+                  
   @  sB  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d	lmZmZ erEdd
lmZ ddlmZ ddlZddlm  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e Zd e 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/d0 Z,dS )1z
Convert 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)Registry)TYPE_CHECKINGSequence)Markdown)inlinepatternsNz)[!"#\$\%'()*+,-.\/:;<=>?\@\[\\\]\^_`{|}~]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
(?<=%s)\'"z
(?<=%s)\"'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dZdddZdS )SubstituteTextPatternpatternstrreplace#Sequence[int | str | etree.Element]mdr   c                 C  s   t | | || _|| _dS )z" Replaces matches with some text. N)r   __init__r   r   )selfr   r   r    r!   z/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/markdown/extensions/smarty.pyr      s   
zSubstituteTextPattern.__init__mre.Match[str]datareturntuple[str, int, int]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    r#   r%   resultpartr!   r!   r"   handleMatch   s   

z!SubstituteTextPattern.handleMatchN)r   r   r   r   r   r   )r#   r$   r%   r   r&   r'   )__name__
__module____qualname__r   r2   r!   r!   r!   r"   r      s    
r   c                      sZ   e Zd ZdZ fddZd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substitutionsr;   )defaultr!   )configsuperr   dictr;   update	getConfig)r    kwargs	__class__r!   r"   r      s   
zSmartyExtension.__init__r   r   patterns9Sequence[tuple[str, Sequence[int | str | etree.Element]]]serier   priorityr*   c                 C  sH   t |D ]\}}||f7 }t| }d||f }| j||||  qd S )Nzsmarty-%s-%d)	enumerater   inlinePatternsregister)r    r   rE   rG   rH   indr   namer!   r!   r"   _addPatterns   s   
zSmartyExtension._addPatternsr&   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   r;   rJ   rK   )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
   rS   )r    r   ellipsesPatternr!   r!   r"   educateEllipses   s   zSmartyExtension.educateEllipsesc                 C  rP   )	Nz\<\<r   z\>\>r   zsmarty-left-angle-quotes(   zsmarty-right-angle-quotes#   rS   )r    r   leftAngledQuotePatternrightAngledQuotePatternr!   r!   r"   educateAngledQuotes   rW   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|| 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   )r;   singleQuoteStartRedoubleQuoteStartRedoubleQuoteSetsResingleQuoteSetsRedoubleQuoteSetsRe2singleQuoteSetsRe2decadeAbbrReopeningSingleQuotesRegexclosingSingleQuotesRegexclosingSingleQuotesRegex2remainingSingleQuotesRegexopeningDoubleQuotesRegexclosingDoubleQuotesRegexclosingDoubleQuotesRegex2remainingDoubleQuotesRegexrN   )r    r   lsquorsquoldquordquorE   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 )Nr:   r7   r8   htmlZ   r9   smarty   r   r   )
getConfigsr	   rJ   rZ   ru   r_   rK   r   HTML_STRICT_RErV   r   treeprocessorsESCAPED_CHARSextend)r    r   configsinlineProcessorr!   r!   r"   extendMarkdown  s   



zSmartyExtension.extendMarkdown)r   r   rE   rF   rG   r   rH   r*   )r   r   r&   rO   )r3   r4   r5   __doc__r   rN   rV   rZ   r_   ru   r   __classcell__r!   r!   rC   r"   r6      s    






r6   c                  K  s   t di | S )Nr!   )r6   )rB   r!   r!   r"   makeExtension  s   r   )-r   
__future__r   r(   r   r   r   r   r|   r   utilr	   typingr
   r   markdownr   rexml.etree.ElementTreeetreeElementTree
punctClassendOfWordClass
closeClassopeningQuotesBaser;   rb   rc   rd   re   rf   rg   rh   rm   rn   ro   ri   rj   rk   rl   rp   r{   r   r6   r   r!   r!   r!   r"   <module>   s\   Nb