a
    ø£Be�  ã                   @   s8   d Z ddlZddlmZ ddlmZ G dd„ deƒZdS )zÕThis preprocessor detect cells using a different language through
magic extensions such as `%%R` or `%%octave`. Cell's metadata is marked
so that the appropriate highlighter can be used in the `highlight`
filter.
é    N)ÚDicté   )ÚPreprocessorc                       sd   e Zd ZdZedddddddd	d
dddœƒZedd�jdd�Zd‡ fdd„	Zdd„ Z	dd„ Z
‡  ZS )ÚHighlightMagicsPreprocessorzQ
    Detects and tags code cells that use a different languages than Python.
    ÚrÚbashÚcythonÚ
javascriptÚjuliaÚlatexÚoctaveÚperlÚrubyÚshÚsql)z%%Rz%%bashz%%cythonz%%javascriptz%%juliaz%%latexz%%octavez%%perlz%%rubyz%%shz%%sqlz’Syntax highlighting for magic's extension languages. Each item associates a language magic extension such as %%R, with a pygments lexer such as r.)ÚhelpT)ÚconfigNc                    sL   t ƒ jf d|i|¤Ž | j | j¡ d | j ¡ ¡}t d|› d�¡| _	dS )zPublic constructorr   ú|z^\s*(z)\s+N)
ÚsuperÚ__init__Údefault_languagesÚupdateÚ	languagesÚjoinÚkeysÚreÚcompileÚre_magic_language)Úselfr   ÚkwZany_language©Ú	__class__© új/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/nbconvert/preprocessors/highlightmagics.pyr   1   s    z$HighlightMagicsPreprocessor.__init__c                 C   s(   | j  |¡}|r | j| d¡ S dS dS )a(  
        When a cell uses another language through a magic extension,
        the other language is returned.
        If no language magic is detected, this function returns None.

        Parameters
        ----------
        source: str
            Source code of the cell to highlight
        r   N)r   Úmatchr   Úgroup)r   ÚsourceÚmr"   r"   r#   Úwhich_magic_language>   s    z0HighlightMagicsPreprocessor.which_magic_languagec                 C   s.   |j dkr&|  |j¡}|r&||d d< ||fS )a¯  
        Tags cells using a magic extension language

        Parameters
        ----------
        cell : NotebookNode cell
            Notebook cell being processed
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        cell_index : int
            Index of the cell being processed (see base.py)
        ÚcodeÚmetadataZmagics_language)Z	cell_typer(   r&   )r   ÚcellÚ	resourcesZ
cell_indexZmagic_languager"   r"   r#   Úpreprocess_cellS   s
    
z+HighlightMagicsPreprocessor.preprocess_cell)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Útagr   r   r(   r-   Ú__classcell__r"   r"   r    r#   r      s.   õÿþúr   )r1   r   Z	traitletsr   Úbaser   r   r"   r"   r"   r#   Ú<module>   s   
