σ
§]c           @@ sb   d  Z  d d l m Z m Z d d l Z d d l m Z d d l m Z d e f d     YZ	 d S(	   sΥ   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.
i    (   t   print_functiont   absolute_importNi   (   t   Preprocessor(   t   Dictt   HighlightMagicsPreprocessorc           B@ s   e  Z d  Z e i
 d d 6d d 6d d 6d d 6d	 d
 6d d 6d d 6d d 6d d 6d d 6 Z e d d  j d e  Z d d  Z	 d   Z
 d   Z RS(   sQ   
    Detects and tags code cells that use a different languages than Python.
    t   rs   %%Rt   bashs   %%basht   cythons   %%cythont
   javascripts   %%javascriptt   julias   %%juliat   latexs   %%latext   octaves   %%octavet   perls   %%perlt   rubys   %%rubyt   shs   %%sht   helps   Syntax highlighting for magic's extension languages. Each item associates a language magic extension such as %%R, with a pygments lexer such as r.t   configc         K@ sf   t  t |   j d | |  |  j j |  j  d j |  j j    } t j	 d j
 |   |  _ d S(   s   Public constructorR   t   |s   ^\s*({0})\s+N(   t   superR   t   __init__t   default_languagest   updatet	   languagest   joint   keyst   ret   compilet   formatt   re_magic_language(   t   selfR   t   kwt   any_language(    (    sF   lib/python2.7/site-packages/nbconvert/preprocessors/highlightmagics.pyR   ,   s
    c         C@ s4   |  j  j |  } | r, |  j | j d  Sd Sd S(   s(  
        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
        i   N(   R   t   matchR   t   groupt   None(   R   t   sourcet   m(    (    sF   lib/python2.7/site-packages/nbconvert/preprocessors/highlightmagics.pyt   which_magic_language:   s    c         C@ sE   | j  d k r; |  j | j  } | r; | | d d <q; n  | | f S(   s―  
        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)
        t   codet   metadatat   magics_language(   t	   cell_typeR%   R#   (   R   t   cellt	   resourcest
   cell_indext   magic_language(    (    sF   lib/python2.7/site-packages/nbconvert/preprocessors/highlightmagics.pyt   preprocess_cellO   s
    N(   t   __name__t
   __module__t   __doc__R   R   t   tagt   TrueR   R"   R   R%   R.   (    (    (    sF   lib/python2.7/site-packages/nbconvert/preprocessors/highlightmagics.pyR      s$   		(
   R1   t
   __future__R    R   R   t   baseR   t	   traitletsR   R   (    (    (    sF   lib/python2.7/site-packages/nbconvert/preprocessors/highlightmagics.pyt   <module>   s
   