U
    \>e                     @  sV   d Z ddlmZ ddlmZmZmZmZ ddlm	Z	 erDddl
mZ G dd dZd	S )
a  
Markdown accepts an [`Extension`][markdown.extensions.Extension] instance for each extension. Therefore, each extension
must to define a class that extends [`Extension`][markdown.extensions.Extension] and over-rides the
[`extendMarkdown`][markdown.extensions.Extension.extendMarkdown] method. Within this class one can manage configuration
options for their extension and attach the various processors and patterns which make up an extension to the
[`Markdown`][markdown.Markdown] instance.
    )annotations)TYPE_CHECKINGAnyIterableMapping   )parseBoolValue)Markdownc                   @  s   e Zd ZU dZi Zded< dd Zd dddd	d
dZddddZddddZ	ddddddZ
dddddZdddddZdS )!	Extensionz( Base class for extensions to subclass. zMapping[str, list]configc                 K  s   |  | dS )z( Initiate Extension and set up configs. N)
setConfigs)selfkwargs r   @/tmp/pip-unpacked-wheel-wj0og6ym/markdown/extensions/__init__.py__init__8   s    zExtension.__init__ strr   )keydefaultreturnc                 C  s    || j kr| j | d S |S dS )a  
        Return a single configuration option value.

        Arguments:
            key: The configuration option name.
            default: Default value to return if key is not set.

        Returns:
            Value of stored configuration option.
        r   Nr   )r   r   r   r   r   r   	getConfig<   s    
zExtension.getConfigzdict[str, Any])r   c                   s    fdd j  D S )zl
        Return all configuration options.

        Returns:
            All configuration options.
        c                   s   i | ]}|  |qS r   )r   .0r   r   r   r   
<dictcomp>S   s      z(Extension.getConfigs.<locals>.<dictcomp>r   keysr   r   r   r   
getConfigsL   s    zExtension.getConfigszlist[tuple[str, str]]c                   s    fdd j  D S )z
        Return descriptions of all configuration options.

        Returns:
            All descriptions of configuration options.
        c                   s   g | ]}| j | d  fqS )   r   r   r   r   r   
<listcomp>\   s     z+Extension.getConfigInfo.<locals>.<listcomp>r   r   r   r   r   getConfigInfoU   s    zExtension.getConfigInfoNone)r   valuer   c                 C  sL   t | j| d trt|}| j| d dkr:t|dd}|| j| d< dS )a  
        Set a configuration option.

        If the corresponding default value set in [`config`][markdown.extensions.Extension.config]
        is a `bool` value or `None`, then `value` is passed through
        [`parseBoolValue`][markdown.util.parseBoolValue] before being stored.

        Arguments:
            key: Name of configuration option to set.
            value: Value to assign to option.

        Raises:
            KeyError: If `key` is not known.
        r   NT)Zpreserve_none)
isinstancer   boolr   )r   r   r$   r   r   r   	setConfig^   s
    zExtension.setConfigz-Mapping[str, Any] | Iterable[tuple[str, Any]])itemsr   c                 C  s0   t |dr| }|D ]\}}| || qdS )a  
        Loop through a collection of configuration options, passing each to
        [`setConfig`][markdown.extensions.Extension.setConfig].

        Arguments:
            items: Collection of configuration options.

        Raises:
            KeyError: for any unknown key.
        r(   N)hasattrr(   r'   )r   r(   r   r$   r   r   r   r   s   s    
zExtension.setConfigsr	   )mdr   c                 C  s   t d| jj| jjf dS )z
        Add the various processors and patterns to the Markdown Instance.

        This method must be overridden by every extension.

        Arguments:
            md: The Markdown instance.

        z8Extension "%s.%s" must define an "extendMarkdown"method.N)NotImplementedError	__class__
__module____name__)r   r*   r   r   r   extendMarkdown   s
    
zExtension.extendMarkdownN)r   )r.   r-   __qualname____doc__r   __annotations__r   r   r   r"   r'   r   r/   r   r   r   r   r
   %   s   
		r
   N)r1   
__future__r   typingr   r   r   r   utilr   Zmarkdownr	   r
   r   r   r   r   <module>   s   