U
    Sh                     @  s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ d
d Zdd ZG dd deZG dd deZdS )zMyST specific directives    )annotations)copy)cast)nodes)
directives)SphinxDirective)
SphinxRole)	MockStatec                 C  s   t | dS )N)leftcenterright)r   choiceargument r   T/root/rtd-docs/venv/lib/python3.8/site-packages/myst_parser/sphinx_ext/directives.pyalign   s    r   c                 C  s    |   dkrdS t| dS d S )NimageZpx)lowerr   Z length_or_percentage_or_unitlessr   r   r   r   figwidth_value   s    r   c                   @  s   e Zd ZdZddddZdS )SubstitutionReferenceRolez}Implement substitution references as a role.

    Note, in ``docutils/parsers/rst/roles.py`` this is left unimplemented.
    z3tuple[list[nodes.Node], list[nodes.system_message]]returnc                 C  s8   t | j| j}| || j t | j|d< |gg fS )NZrefname)r   Zsubstitution_referenceZrawtexttextset_source_infolinenoZfully_normalize_name)selfZsubref_noder   r   r   run!   s    zSubstitutionReferenceRole.runN)__name__
__module____qualname____doc__r   r   r   r   r   r      s   r   c                   @  sH   e Zd ZdZdZdZdZdZee	j
ee	jdZdddd	Zd
d ZdS )FigureMarkdowna  Directive for creating a figure with Markdown compatible syntax.

    Example::

        :::{figure-md} target
        <img src="img/fun-fish.png" alt="fishy" class="bg-primary mb-1" width="200px">

        This is a caption in **Markdown**
        :::

    r      T)widthclassr   namezlist[nodes.Node]r   c                 C  s  | j dd }| j dd }| j dd }t| jtsB| dgS tt| j}t|jj	j
}t }z&|jj	j
d || j| j| W 5 ||jj	_
X t|jdkr| dgS |j\}}t|tjr|d }t|tjs| d	gS t|tjs| d
gS tj|jdf|j }	|j|	_|j|	_td||	}
| |
 |d k	rR||
d< |rh|
d  |7  < |rv||
d< | jr| jd | j d< | |
 |
gS )Nr$   r%   r   z*Directive is only supported in myst parserZ
html_image   zCcontent should be one image, followed by a single paragraph captionr   zMcontent should be one image (not found), followed by single paragraph captionzMcontent should be one image, followed by single paragraph caption (not found) classesr&   )optionspop
isinstancestater	   figure_errorr   r   Z	_rendererZ	md_configZenable_extensionsr   ZElementaddZnested_parsecontentZcontent_offsetlenchildrenZ	paragraphr   captionZ	rawsourcesourcelineZfigurer   	argumentsZadd_name)r   ZfigwidthZ
figclassesr   r-   Zmyst_extensionsnodeZ
image_nodeZcaption_paraZcaption_nodeZfigure_noder   r   r   r   A   sZ    



zFigureMarkdown.runc                 C  s&   | j jj|t| j| j| jd}|S )z*A warning for reporting an invalid figure.)r5   )Zstate_machinereportererrorr   Zliteral_blockZ
block_textr   )r   messager9   r   r   r   r.      s    zFigureMarkdown.figure_errorN)r   r   r    r!   Zrequired_argumentsZoptional_argumentsZfinal_argument_whitespaceZhas_contentr   r   Zclass_optionr   Z	unchangedZoption_specr   r.   r   r   r   r   r"   (   s   Ar"   N)r!   
__future__r   r   typingr   Zdocutilsr   Zdocutils.parsers.rstr   Zsphinx.directivesr   Zsphinx.util.docutilsr   Zmyst_parser.mockingr	   r   r   r   r"   r   r   r   r   <module>   s   