a
    t=icm'                  
   @   s   d 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e 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 )*a  
Smarty extension for Python-Markdown
====================================

Adds conversion of ASCII dashes, quotes and ellipses to their HTML
entity equivalents.

See <https://Python-Markdown.github.io/extensions/smarty>
for documentation.

Author: 2013, Dmitry Shachnev <mitya57@gmail.com>

All changes Copyright 2013-2014 The Python Markdown Project

License: [BSD](https://opensource.org/licenses/bsd-license.php)

SmartyPants license:

   Copyright (c) 2003 John Gruber <https://daringfireball.net/>
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:

   *  Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

   *  Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.

   *  Neither the name "SmartyPants" nor the names of its contributors
      may be used to endorse or promote products derived from this
      software without specific prior written permission.

   This software is provided by the copyright holders and contributors "as
   is" and any express or implied warranties, including, but not limited
   to, the implied warranties of merchantability and fitness for a
   particular purpose are disclaimed. In no event shall the copyright
   owner or contributors be liable for any direct, indirect, incidental,
   special, exemplary, or consequential damages (including, but not
   limited to, procurement of substitute goods or services; loss of use,
   data, or profits; or business interruption) however caused and on any
   theory of liability, whether in contract, strict liability, or tort
   (including negligence or otherwise) arising in any way out of the use
   of this software, even if advised of the possibility of such damage.


smartypants.py license:

   smartypants.py is a derivative work of SmartyPants.
   Copyright (c) 2004, 2007 Chad Miller <http://web.chad.org/>

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions are
   met:

   *  Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

   *  Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the
      distribution.

   This software is provided by the copyright holders and contributors "as
   is" and any express or implied warranties, including, but not limited
   to, the implied warranties of merchantability and fitness for a
   particular purpose are disclaimed. In no event shall the copyright
   owner or contributors be liable for any direct, indirect, incidental,
   special, exemplary, or consequential damages (including, but not
   limited to, procurement of substitute goods or services; loss of use,
   data, or profits; or business interruption) however caused and on any
   theory of liability, whether in contract, strict liability, or tort
   (including negligence or otherwise) arising in any way out of the use
   of this software, even if advised of the possibility of such damage.

   )	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|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   k/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/markdown/extensions/smarty.pyr      s    zSubstituteTextPattern.__init__c                 C   sR   d}| j D ]0}t|tr(|||7 }q
|| jj|7 }q
||d|dfS )N     )	r   
isinstanceintgroupr   Z	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                       sL   e Zd Z fddZdd Zdd Zdd Zd	d
 Zdd Zdd Z	  Z
S )SmartyExtensionc                    s\   ddgddgddgddgi dgd| _ t jf 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substitutionsr0   )default)configsuperr   dictr0   updateZ	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   patternsZseriepriorityindr   namer   r   r   _addPatterns   s
    
zSmartyExtension._addPatternsc                 C   sL   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   r0   r:   r;   )r   r   ZemDashesPatternZenDashesPatternr   r   r   educateDashes   s    zSmartyExtension.educateDashesc                 C   s(   t d| jd f|}| j|dd d S )Nz(?<!\.)\.{3}(?!\.)r
   zsmarty-ellipses
   rC   )r   r   ZellipsesPatternr   r   r   educateEllipses   s    zSmartyExtension.educateEllipsesc                 C   sL   t d| jd f|}t d| jd f|}| j|dd | j|dd d S )	Nz\<\<r   z\>\>r   zsmarty-left-angle-quotes(   zsmarty-right-angle-quotes#   rC   )r   r   ZleftAngledQuotePatternZrightAngledQuotePatternr   r   r   educateAngledQuotes   s    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   )r0   singleQuoteStartRedoubleQuoteStartRedoubleQuoteSetsResingleQuoteSetsRedecadeAbbrReopeningSingleQuotesRegexclosingSingleQuotesRegexclosingSingleQuotesRegex2remainingSingleQuotesRegexopeningDoubleQuotesRegexclosingDoubleQuotesRegexclosingDoubleQuotesRegex2remainingDoubleQuotesRegexr@   )r   r   lsquorsquoldquordquor<   r   r   r   educateQuotes   s&    






zSmartyExtension.educateQuotesc                 C   s   |   }t | _|d r"| | |d r4| | |d r\| | |jtt|dd |d rn| 	| t
|}| j|_|j|dd |jd	d
g d S )Nr/   r,   r-   htmlZ   r.   smartyr   r   r   )Z
getConfigsr   r:   rF   r]   rI   r;   r   HTML_STRICT_RErD   r   treeprocessorsZESCAPED_CHARSextend)r   r   ZconfigsZinlineProcessorr   r   r   extendMarkdown   s    



zSmartyExtension.extendMarkdown)r(   r)   r*   r   r@   rD   rF   rI   r]   rd   __classcell__r   r   r7   r   r+      s   

r+   c                  K   s   t f i | S )N)r+   )r6   r   r   r   makeExtension   s    rf   N) __doc__r   r   Zinlinepatternsr   r   rb   r   utilr   Z
punctClassZendOfWordClassZ
closeClassZopeningQuotesBaser0   rL   rM   rN   rO   rP   rU   rV   rW   rQ   rR   rS   rT   rX   ra   r   r+   rf   r   r   r   r   <module>   sH   RX