
    3yi]                         d dl mZ d dlZd dlmZ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 d d	lmZ  G d
 de      Z G d de	      ZddZd Z ej.                  d      Zy)    )annotationsN)
FileFilterFilterConfig)_RelativePathTreeprocessor)	ExtensionMarkdown)Treeprocessor)ConfigurationError)urlparse)Elementc                  ,     e Zd ZdZd fdZddZ xZS )PreviewProcessorz
    A Markdown treeprocessor to enable instant previews on links.

    Note that this treeprocessor is dependent on the `relpath` treeprocessor
    registered programmatically by MkDocs before rendering a page.
    c                2    t         |   |       || _        y)z
        Initialize the treeprocessor.

        Arguments:
            md: The Markdown instance.
            config: The configuration.
        N)super__init__config)selfmdr   	__class__s      ]/var/www/html/content_weaver/venv/lib/python3.12/site-packages/material/extensions/preview.pyr   zPreviewProcessor.__init__-   s     	    c                   | j                   j                  j                  d      }| j                   j                  |   }t        |t              st        d      | j                  d   }|j                  | j                  j                  d      | j                  j                  d      d       |D ]-  }|j                  d      s|j                  d      s't        |d      } ||j                        sFt        |d      }|j                  d      D ]  }|j                  d      }|sd	|j                  d
d      v r,t        |      }	|	j                  s|	j                  rP|j                  |j                  |	j                   |j                  j"                        D ];  }
|j$                  j'                  |
      }|s! ||      s*|j)                  dd       =  0 y)z
        Run the treeprocessor.

        Arguments:
            root: The root element of the parsed Markdown document.
        relpathz&Relative path processor not registeredconfigurationssourcestargets)r   r   ahrefzfootnote-refclass zdata-previewN)r   treeprocessorsget_index_for_name
isinstancer   	TypeErrorr   appendget
get_filterfileiterr   schemenetloc_possible_target_urispathuse_directory_urlsfilesget_file_from_pathset)r   rootat	processorr   configurationfilterelr   urlr-   targets               r   runzPreviewProcessor.run8   s    WW##66yA GG**2.	)%?@DEE %56{{y1{{y1
 	 , -	3M "%%i0!%%i0  y9F)..)  y9Fiin 3vvf~ "RVVGR%88 tn:: &;;NNCHH$$77 
3D '__??EF!  f~~r2
33)-	3r   )r   r   r   dict)r2   r   )__name__
__module____qualname____doc__r   r:   __classcell__r   s   @r   r   r   %   s    	L3r   r   c                  *     e Zd ZdZ fdZddZ xZS )PreviewExtensionab  
    A Markdown extension to enable instant previews on links.

    This extensions allows to automatically add the `data-preview` attribute to
    internal links matching specific criteria, so Material for MkDocs renders a
    nice preview on hover as part of a tooltip. It is the recommended way to
    add previews to links in a programmatic way.
    c                F    g dgi dgi dgd| _         t        |   |i | y)z	
        zFilter configurationszLink sourceszLink targets)r   r   r   N)r   r   r   )r   argskwargsr   s      r   r   zPreviewExtension.__init__   s;      "#:;N+N+

 	$)&)r   c                    |j                  |        t        || j                               }|j                  j	                  |dd       y)zi
        Register Markdown extension.

        Arguments:
            md: The Markdown instance.
        previewr   N)registerExtensionr   
getConfigsr!   register)r   r   r4   s      r   extendMarkdownzPreviewExtension.extendMarkdown   s?     	T" %R):;	
""9i;r   )r   r   )r<   r=   r>   r?   r   rL   r@   rA   s   @r   rC   rC      s    *<r   rC   c                   t               }|j                  | j                  |      xs i        |j                         \  }}|D ]   \  }}t        j                  d| d|        " |D ]  \  }}t        d| d|        t        |      S )z
    Get file filter from settings.

    Arguments:
        settings: The settings.
        key: The key in the settings.

    Returns:
        The file filter.
    z'Error reading filter configuration in 'z':
)r   )r   	load_dictr&   validatelogwarningr
   r   )settingskeyr   errorswarnings_wes           r   r'   r'      s     ^F
X\\#&,"- (FH 
15cU$c	


  
1 5cU$c
 	

 v&&r   c                     t        di | S )z
    Register Markdown extension.

    Arguments:
        **kwargs: Configuration options.

    Returns:
        The Markdown extension.
     )rC   )rF   s    r   makeExtensionr[      s     %f%%r   z"mkdocs.material.extensions.preview)rR   r;   rS   str)
__future__r   loggingmaterial.utilities.filterr   r   mkdocs.structure.pagesr   markdownr   r   markdown.treeprocessorsr	   mkdocs.exceptionsr
   urllib.parser   xml.etree.ElementTreer   r   rC   r'   r[   	getLoggerrP   rZ   r   r   <module>rg      s]   * #  > = ( 1 0 ! )_3} _3F"<y "<P'<
&" g<=r   