
    ʯei                         d dl Z d dlmc mZ d dlmc mZ d dlmZ d dlZd dlZd dl	Z
d dlmZ d dlmZ 	 d dl	mZ dZdZd	Zd
ZdZdZ G d de      Zy# e$ r	 d dl	mZ Y %w xY w)    N)Tuple)InlineProcessor)mention)
cache_data)experimental_memo)githubnotiontwitter	streamlitz3https://cdn-icons-png.flaticon.com/512/25/25231.pngzGhttps://upload.wikimedia.org/wikipedia/commons/4/45/Notion_app_logo.pngzWhttps://seeklogo.com/images/T/twitter-icon-circle-blue-logo-0902F48837-seeklogo.com.pngzuhttps://aws1.discourse-cdn.com/business7/uploads/streamlit/original/2X/f/f0d0d26db1f2d99da8472951c60e5a1b782eb6fe.pngz3@(?P<a>\([^)]+\))(?P<b>\([^)]+\))?(?P<c>\([^)]+\))?c                       e Zd ZdZededefd       Zddej                  de	e
j                  eef   fdZeededefd              Zeededefd	              Zdede	eef   fd
Zy)AtSignProcessorzoTransforms '@(icon)(label)(url)' into HTML.
    Also works with '@(label)(url)' or '@(url)' in some cases.
    urlreturnc                 2    | j                  d      sd| z   } | S )Nzhttps://)
startswith)r   s    `/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/markdownlit/extensions/at_sign.py
_add_httpszAtSignProcessor._add_https   s    ~~j)s"C
    Nmc                    |j                         D cg c]  }||j                  d       }}t        |      }|dk(  r|d   }| j                  |      \  }}n*|dk(  r|\  }}| j                  |      \  }}	n|dk(  r|\  }}}| j	                        }t        |d      }
|
j                  d	      d
k7  r |
|
j                  d	      t        d	      z   d }
t        j                  t        j                  t        |
                  j                         }|j                  dd       ||j                  d      |j                  d      fS c c}w )ar  This function is called whenever a match is found.
        We want it to replace the '@(...)' pattern with an HTML element for the link.

        Args:
            m (re.Match): Match object
            data (_type_): [Not used - not sure what this does]

        Returns:
            (etree.Element, int, int): HTML element, with its starting and ending index.
        Nz()   r         F)labeliconr   writez</style>stylez8display: inline; color:inherit; text-decoration:inherit;)groupsstriplen_guess_icon_and_labelr   r   findETElementTree
fromstringstrgetrootsetstartend)selfr   datagroupr   
num_groupsr   r   r   _htmlels               r   handleMatchzAtSignProcessor.handleMatch%   s5    23Qu?P%++d#QQ[
?)C44S9KD%1_JE3005GD!1_%D%ooc"U3eD 99Z B&		*-J?ABD^^BMM#d)45==?
wRS1771:quuQx''+ Rs
   EEc                 N    t        j                  | d      }|d   j                  S )Nr   )timeoutr   )favicongetr   )r   faviconss     r   _get_faviconzAtSignProcessor._get_faviconG   s"     ;;sA.{r   c                     t        j                  |       }|j                  }||j                  d      dz   |j                  d       S )Nz<title>   z</title>)requestsr7   textr#   )r   nals      r   _get_page_titlezAtSignProcessor._get_page_titleM   s?     LLVV"'')$q(277:+>??r   c                    d|v rHd}d|v r*|j                  d      d   j                  d      d   }||fS |j                  d      d   }||fS d	|v sd
|v sd|v rd}d}||fS d|v r)d}dj                  |j                  d      dd       }||fS d|v rd}d}||fS 	 | j                  |      }| j                  |      }||fS # t        $ r}d}d}Y d}~||fS d}~ww xY w)zFind out plausible icon and label from URL alone

        Args:
            url (str): URL of the link

        Returns:
            str: Icon of the link
            str: Label of the link
        ztwitter.comr
   statusztwitter.com/r   /r   r   zstreamlitapp.comzstreamlit.iozstreamlit.appr   zStreamlit Appz
github.comr   Nz	notion.sor	   zNotion pageu   🔗Link)splitjoinr9   r@   	Exception)r,   r   r   r   es        r   r"   z%AtSignProcessor._guess_icon_and_labelT   sE    CD3		.1!4::3?B. U{) 		#r*( U{% #%3)>/UXBXD#E U{ S DHHSYYs^BC01E U{ CD!E U{((-,,S1
 U{	  U{	s   "C 	C
CC)N)__name__
__module____qualname____doc__staticmethodr'   r   reMatchr   etreeElementintr3   r   r9   r@   r"    r   r   r   r      s        
 (RXX  (U5==#s;R5S  (D # #    @S @S @  @
% %sCx %r   r   )rO   xml.etree.ElementTreerQ   r%   r$   typingr   r6   r<   r   stmarkdown.inlinepatternsr   streamlit_extras.mentionr   r   ImportErrorr   SUPPORTED_PLATFORMSGITHUB_ICONNOTION_ICONTWITTER_ICONSTREAMLIT_ICON
AT_SIGN_REr   rT   r   r   <module>ra      su    	 % % " "     3 ,:$ C CWh IC
_o _  :9:s   A A"!A"