Ë
    ®¦jN>  ã            
       ó˜  — d Z ddlZddlZddlmZmZmZ ddœd„Zdedefd	„Z	dedefd
„Z
d%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dedee   defd„Zd%dededee   defd„Zd%dededee   defd„Zd&dededee   defd„Zd%dedee   defd„Zd'dedee   dedefd„Zdedefd„Zd(dedee   dee   defd„Zd(dedee   dee   defd „Zd)d!ed"ee   d#eeeef      defd$„Zy)*z'
Markdown & HTML formatting functions.
é    N)ÚOptionalÚListÚDictú
)Ú	separatorc                 ó$   — | j                  |«      S )a—  
    Formats a list of strings into a single string.

    .. code:: python3

        format_text( # just an example
            mbold('Hello'),
            mitalic('World')
        )

    :param args: Strings to format.
    :type args: :obj:`str`

    :param separator: The separator to use between each string.
    :type separator: :obj:`str`

    :return: The formatted string.
    :rtype: :obj:`str`
    )Újoin)r   Úargss     úE/var/www/html/venv/lib/python3.12/site-packages/telebot/formatting.pyÚformat_textr   
   s   € ð( �>‰>˜$ÓÐó    ÚcontentÚreturnc                 ó,   — t        j                  | «      S )zÀ
    Escapes HTML characters in a string of HTML.

    :param content: The string of HTML to escape.
    :type content: :obj:`str`

    :return: The escaped string.
    :rtype: :obj:`str`
    )ÚhtmlÚescape)r   s    r   Úescape_htmlr   !   s   € ô �;‰;�wÓÐr   c                 ób   — t        j                  dd| «      }t        j                  dd|«      }|S )zæ
    Escapes Markdown characters in a string of Markdown.

    Credits to: simonsmh

    :param content: The string of Markdown to escape.
    :type content: :obj:`str`

    :return: The escaped string.
    :rtype: :obj:`str`
    z ([_*\[\]()~`>\#\+\-=|\.!\{\}\\])z\\\1z$\\\\([_*\[\]()~`>\#\+\-=|\.!\{\}\\])z\1)ÚreÚsub)r   ÚparseÚreparses      r   Úescape_markdownr   /   s/   € ô �F‰FÐ6¸ÀÓI€EÜ�f‰fÐ<¸eÀUÓK€GØ€Nr   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a(  
    Returns a Markdown-formatted bold string.

    :param content: The string to bold.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z*{}*©Úformatr   ©r   r   s     r   Úmboldr   A   ó"   € ð �=‰=±Vœ¨Ó1ÓIÐIÀÓIÐIr   c                 óF   — dj                  |rt        | «      «      S | «      S )a%  
    Returns an HTML-formatted bold string.

    :param content: The string to bold.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z	<b>{}</b>©r   r   r   s     r   Úhboldr"   Q   ó$   € ð ×Ñ±fœk¨'Ó2ÓJÐJÀ'ÓJÐJr   c                 óF   — dj                  |rt        | «      «      S | «      S )a/  
    Returns a Markdown-formatted italic string.

    :param content: The string to italicize.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z_{}_r   r   s     r   Úmitalicr%   a   ó"   € ð �?‰?±vœ?¨7Ó3ÓKÐKÀ7ÓKÐKr   c                 óF   — dj                  |rt        | «      «      S | «      S )a,  
    Returns an HTML-formatted italic string.

    :param content: The string to italicize.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z	<i>{}</i>r!   r   s     r   Úhitalicr(   q   r#   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a2  
    Returns a Markdown-formatted underline string.

    :param content: The string to underline.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z__{}__r   r   s     r   Ú
munderliner*   �   r&   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a0  
    Returns an HTML-formatted underline string.

    :param content: The string to underline.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`

    z	<u>{}</u>r!   r   s     r   Ú
hunderliner,   ‘   s$   € ð ×Ñ±fœk¨'Ó2ÓJÐJÀ'ÓJÐJr   c                 óF   — dj                  |rt        | «      «      S | «      S )a:  
    Returns a Markdown-formatted strikethrough string.

    :param content: The string to strikethrough.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z~{}~r   r   s     r   Úmstrikethroughr.   ¢   r   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a7  
    Returns an HTML-formatted strikethrough string.

    :param content: The string to strikethrough.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z	<s>{}</s>r!   r   s     r   Úhstrikethroughr0   ²   r#   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a.  
    Returns a Markdown-formatted spoiler string.

    :param content: The string to spoiler.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z||{}||r   r   s     r   Úmspoilerr2   Â   r&   r   c                 óF   — dj                  |rt        | «      «      S | «      S )a+  
    Returns an HTML-formatted spoiler string.

    :param content: The string to spoiler.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z<tg-spoiler>{}</tg-spoiler>r!   r   s     r   Úhspoilerr4   Ò   s%   € ð )×/Ñ/É´¸GÓ0DÓ\Ð\ÐT[Ó\Ð\r   Úurlc                 óZ   — dj                  t        | «      |rt        |«      «      S |«      S )a`  
    Returns a Markdown-formatted link string.

    :param content: The string to link.
    :type content: :obj:`str`

    :param url: The URL to link to.
    :type url: str

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z[{}]({})r   ©r   r5   r   s      r   Úmlinkr8   â   s,   € ð  ×Ñœ_¨WÓ5Év´ÀsÓ7KÓ_Ð_Ð[^Ó_Ð_r   c                 óZ   — dj                  t        |«      |rt        | «      «      S | «      S )ad  
    Returns an HTML-formatted link string.

    :param content: The string to link.
    :type content: :obj:`str`

    :param url: The URL to link to.
    :type url: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z<a href="{}">{}</a>r!   r7   s      r   Úhlinkr:   õ   s-   € ð  !×'Ñ'¬°CÓ(8ÑRX¼+ÀgÓ:NÓfÐfÐ^eÓfÐfr   Úlanguagec                 óH   — dj                  ||rt        | «      «      S | «      S )a   
    Returns a Markdown-formatted code string.

    :param content: The string to code.
    :type content: :obj:`str`

    :param language: The programming language of the code. Defaults to an empty string.
    :type language: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z```{}
{}```r   )r   r;   r   s      r   Úmcoder=     s'   € ð  × Ñ  Áv¬?¸7Ó+CÓ[Ð[ÐSZÓ[Ð[r   c                 óF   — dj                  |rt        | «      «      S | «      S )a%  
    Returns an HTML-formatted code string.

    :param content: The string to code.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z<code>{}</code>r!   r   s     r   Úhcoder?     s$   € ð ×#Ñ#¹F¤K°Ó$8ÓPÐPÈÓPÐPr   c                 óH   — dj                  ||rt        | «      «      S | «      S )a­  
    Returns an HTML-formatted preformatted string.

    :param content: The string to preformatted.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :param language: The programming language of the code. Defaults to an empty string.
    :type language: :obj:`str`

    :return: The formatted string.
    :rtype: :obj:`str`
    z%<pre><code class="{}">{}</code></pre>r!   )r   r   r;   s      r   ÚhprerA   +  s)   € ð  3×9Ñ9¸(Ñ\bÄKÐPWÓDXÓpÐpÐhoÓpÐpr   c                 ó   — d| › d�S )z™
    Hide url of an image.

    :param url: The url of the image.
    :type url: :obj:`str`
    
    :return: The hidden url.
    :rtype: :obj:`str`
    z	<a href="z">&#8288;</a>© )r5   s    r   Ú	hide_linkrD   >  s   € ð �s�e˜=Ð)Ð)r   Ú
expandablec                 ó    — |rt        | «      n| } dj                  | j                  d«      D �cg c]  }d|z   ‘Œ	 c}«      } |rd| › d�S | S c c}w )a­  
    Returns a Markdown-formatted block-quotation string.

    :param content: The string to bold.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :param expandable: True if you need the quote to be expandable. Defaults to False.
    :type expandable: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    r   ú>z**z||)r   r	   Úsplit)r   r   rE   Úlines       r   ÚmciterJ   K  sU   € ñ  +1Œo˜gÔ&°g€GØ�i‰i°·±¸dÓ0CÖD¨˜˜t›ÒDÓE€GÙØ�G�9˜BÐÐØ€Nùò Es   ®Ac                 óP   — dj                  |rdnd|rt        | «      «      S | «      S )a©  
    Returns a html-formatted block-quotation string.

    :param content: The string to bold.
    :type content: :obj:`str`

    :param escape: True if you need to escape special characters. Defaults to True.
    :type escape: :obj:`bool`

    :param expandable: True if you need the quote to be expandable. Defaults to False.
    :type expandable: :obj:`bool`

    :return: The formatted string.
    :rtype: :obj:`str`
    z<blockquote{}>{}</blockquote>z expandableÚ r!   )r   r   rE   s      r   ÚhciterM   b  s5   € ð  +×1Ñ1Ù#‰¨Ù &Œ�GÓóð à,3óð r   ÚtextÚentitiesÚcustom_subsc                 óB  ‡‡	‡
‡— |s2| j                  dd«      j                  dd«      j                  dd«      S ddd	d
dddddddddœŠ|r|j                  «       D ]
  \  }}|‰|<   Œ t        |d„ ¬«      }| j                  d«      }d„ Š	ˆfd„Š
dˆ	ˆ
ˆfd„	Š ‰||«      }|S )zz
    Apply HTML formatting to text based on provided entities.
    Handles nested and overlapping entities correctly.
    ú&ú&amp;ú<ú&lt;rG   ú&gt;z<b>{text}</b>z<i>{text}</i>z<pre>{text}</pre>z<code>{text}</code>z<a href="{url}">{text}</a>z<s>{text}</s>z<u>{text}</u>z&<span class="tg-spoiler">{text}</span>z8<tg-emoji emoji-id="{custom_emoji_id}">{text}</tg-emoji>zH<tg-time unix="{unix_time}" format="{date_time_format}">{text}</tg-time>z<blockquote>{text}</blockquote>z*<blockquote expandable>{text}</blockquote>)ÚboldÚitalicÚpreÚcodeÚ	text_linkÚstrikethroughÚ	underlineÚspoilerÚcustom_emojiÚ	date_timeÚ
blockquoteÚexpandable_blockquotec                 ó4   — | j                   | j                   fS )N)ÚoffsetÚlength)Úes    r   ú<lambda>z%apply_html_entities.<locals>.<lambda>”  s   € °a·h±hÀÇÁÀ	Ð5J€ r   )Úkeyú	utf-16-lec                 ó¨   — t        | t        «      r| j                  d«      } | j                  dd«      j                  dd«      j                  dd«      S )z-Escape HTML special characters in a text partri   rR   rS   rT   rU   rG   rV   )Ú
isinstanceÚbytesÚdecodeÚreplace)Ú	text_parts    r   Úescape_entityz*apply_html_entities.<locals>.escape_entity™  sJ   € ä�i¤Ô'Ø!×(Ñ(¨Ó5ˆIØ× Ñ   gÓ.×6Ñ6°s¸FÓC×KÑKÈCÐQWÓXÐXr   c                 óf  •— | j                   }|dk(  r)t        | d«      rd| j                  j                  › d|› d�S |dk(  r,t        | d«      r ‰d   j	                  | j
                  |¬«      S |d	k(  r,t        | d
«      r ‰d	   j	                  | j                  |¬«      S |dk(  rCt        | d«      r7t        | d«      r+‰d   j	                  | j                  | j                  |¬«      S |dk(  r+t        | d«      r| j                  rd| j                  › d|› d�S |‰v r‰|   }|j	                  |¬«      S |S )z&Apply entity formatting to the contentÚtext_mentionÚuserz<a href="tg://user?id=z">z</a>r[   r5   )r5   rN   r_   Úcustom_emoji_id)rt   rN   r`   Ú	unix_timeÚdate_time_format)Úunixrv   rN   rY   r;   z<pre><code class="language-z</code></pre>)rN   )
ÚtypeÚhasattrrs   Úidr   r5   rt   ru   rv   r;   )Úentityr   Úentity_typeÚtemplateÚ_subss       €r   Úformat_entityz*apply_html_entities.<locals>.format_entityŸ  sE  ø€ à—k‘kˆð ˜.Ò(¬W°V¸VÔ-DØ,¨V¯[©[¯^©^Ð,<¸CÀ¸yÈÐMÐMð ˜KÒ'¬G°F¸EÔ,BØ˜Ñ%×,Ñ,°·±À'Ð,ÓJÐJØ˜NÒ*¬w°vÐ?PÔ/QØ˜Ñ(×/Ñ/À×@VÑ@VÐ]dÐ/ÓeÐeØ˜KÒ'¬G°F¸KÔ,HÌWÐU[Ð]oÔMpØ˜Ñ%×,Ñ,°&×2BÑ2BÐU[×UlÑUlÐszÐ,Ó{Ð{Ø˜EÒ!¤g¨f°jÔ&AÀfÇoÂoØ1°&·/±/Ð1BÀ#ÀgÀYÈmÐ\Ð\Ø˜EÑ!Ø˜[Ñ)ˆHØ—?‘?¨�?Ó0Ð0ð ˆr   c                 óœ  •— |€t        | «      }|r||k\  r ‰| || «      S |d   }|j                  dz  }||j                  dz  z   }||k  s||k\  r ‰| || «      S g }||kD  r|j                   ‰| || «      «       g }g }	|dd  D ]B  }
|
j                  dz  }||cxk  r|k  rn n|j                  |
«       Œ2|	j                  |
«       ŒD |r ‰| |||«      }n ‰| || «      }|j                   ‰||«      «       ||k  r|	r|j                   ‰| |	||«      «       n||k  r|j                   ‰| || «      «       dj	                  |«      S )Nr   é   é   rL   )Úlenrd   re   Úappendr	   )Ú	byte_textÚentity_listÚ	start_posÚend_posÚcurrent_entityÚcurrent_startÚcurrent_endÚresultÚnested_entitiesÚremaining_entitiesr{   Úentity_startÚinner_contentrp   r   Úprocess_entitiess                €€€r   r‘   z-apply_html_entities.<locals>.process_entities¸  s–  ø€ Øˆ?Ü˜)“nˆGá˜i¨7Ò2Ù  ¨9°WÐ!=Ó>Ð>à$ Q™ˆØ&×-Ñ-°Ñ1ˆØ# n×&;Ñ&;¸aÑ&?Ñ?ˆà˜)Ò# }¸Ò'?Ù  ¨9°WÐ!=Ó>Ð>àˆà˜9Ò$Ø�M‰M™-¨	°)¸MÐ(JÓKÔLàˆØÐà! ! "�oò 	2ˆFØ!Ÿ=™=¨1Ñ,ˆLð  Ô:¨{Õ:Ø×&Ñ& vÕ.à"×)Ñ)¨&Õ1ð	2ñ Ù,ØØØØó	‰Mñ *¨)°MÀ+Ð*NÓOˆMà�‰‘m N°MÓBÔCà˜Ò Ñ%7Ø�M‰MÑ*ØØ"ØØó	õ ð ˜7Ò"Ø�M‰M™-¨	°+¸gÐ(FÓGÔHà�w‰w�v‹Ðr   )r   N)rn   ÚitemsÚsortedÚencode)rN   rO   rP   rh   ÚvalueÚsorted_entitiesÚ
utf16_textÚhtml_resultr~   rp   r   r‘   s           @@@@r   Úapply_html_entitiesr™   x  sÎ   û€ ñ
 Ø�|‰|˜C Ó)×1Ñ1°#°vÓ>×FÑFÀsÈFÓSÐSð  Ø!Ø"Ø%Ø3Ø(Ø$Ø=ØTØcØ7Ø!Mñ€Eñ Ø%×+Ñ+Ó-ò 	‰JˆC�ØˆE�#ŠJð	ô ˜XÑ+JÔK€Oð —‘˜[Ó)€JòYô÷25ñn # :¨Ó?€KàÐr   )T)rL   T)TrL   )TF)NN)Ú__doc__r   r   Útypingr   r   r   r   Ústrr   r   Úboolr   r"   r%   r(   r*   r,   r.   r0   r2   r4   r8   r:   r=   r?   rA   rD   rJ   rM   r™   rC   r   r   ú<module>rž      s
  ðñó 
Û ß 'Ñ 'ð "&ô  ð.
 ˜ð 
  ó 
 ð˜Sð  Só ñ$J�3ð J ¨¡ð J¸ó Jñ K�3ð K ¨¡ð K¸ó Kñ L�Sð L (¨4¡.ð L¸#ó Lñ K�Sð K (¨4¡.ð K¸#ó Kñ L˜ð L X¨d¡^ð L¸Só Lñ K˜ð K X¨d¡^ð K¸Só Kñ"J˜Cð J¨°$©ð JÀó Jñ K˜Cð K¨°$©ð KÀó Kñ L�cð L 8¨D¡>ð L¸3ó Lñ ]�cð ] 8¨D¡>ð ]¸3ó ]ñ `�3ð `˜Sð `¨(°4©.ð `À#ó `ñ&g�3ð g˜Sð g¨(°4©.ð gÀ#ó gñ&\�3ð \ #ð \°(¸4±.ð \È#ó \ñ&Q�3ð Q ¨¡ð Q¸ó Qñ q�#ð q˜x¨™~ð q¸cð qÈó qð&
*�3ð 
*˜3ó 
*ñ�3ð  ¨¡ð À8ÈDÁ>ð Ð^aó ñ.�3ð  ¨¡ð À8ÈDÁ>ð Ð^aó ñ,y˜cð y¨X°d©^ð yÈxÐX\Ð]`ÐbeÐ]eÑXfÑOgð yÐqtô yr   