B
    ]\F                 @   sz   d Z ddlZddlZddlZddlZddlmZ ddlm	Z	 yddl
mZ W n ek
rd   dZY nX G dd de	ZdS )	z;Module that pre-processes the notebook for export to HTML.
    N)Unicode   )Preprocessor)DEFAULT_STATIC_FILES_PATHc               @   sX   e Zd ZdZedddjddZedddjddZd	d
 Zdd Z	dd Z
dd ZdS )CSSHTMLHeaderPreprocessorz
    Preprocessor used to pre-process notebook for HTML output.  Adds IPython notebook
    front-end CSS and Pygments CSS to HTML output.
    z
.highlightzCSS highlight class identifier)helpT)Zconfigdefaultz!Name of the pygments style to usec             O   s   t j| f|| d | _d S )N)r   __init___default_css_hash)selfZpargskwargs r   Dlib/python3.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyr	   #   s    z"CSSHTMLHeaderPreprocessor.__init__c             C   s"   i |d< |  ||d d< ||fS )a  Fetch and add CSS to the resource dictionary

        Fetch CSS from IPython and Pygments to add at the beginning
        of the html files.  Add this css in resources in the 
        "inlining.css" key
        
        Parameters
        ----------
        nb : NotebookNode
            Notebook being converted
        resources : dictionary
            Additional resources used in the conversion process.  Allows
            preprocessors to pass variables into the Jinja engine.
        ZinliningZcss)_generate_header)r   Znb	resourcesr   r   r   
preprocess'   s    z$CSSHTMLHeaderPreprocessor.preprocessc       
   	   C   s  ddl m} g }tjtjtjjd}t	j
|dd}||  W dQ R X || jd}|| j}|| |d |d	 }tj|d
d}	tj|	rtr| jdkr| tjtd
d| _| |	| jkrt	j
|	dd}||  W dQ R X |S )zd 
        Fills self.header with lines of CSS extracted from IPython 
        and Pygments.
        r   )HtmlFormatterzstyle.min.csszutf-8)encodingN)stylea  
/* Temporary definitions which will become obsolete with Notebook release 5.0 */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }

.ansi-bold { font-weight: bold; }

config_dirZcustomz
custom.css)Zpygments.formattersr   ospathjoindirname	nbconvertr   __file__ioopenappendreadr   Zget_style_defshighlight_classisfiler   r
   _hash)
r   r   r   headerZsheet_filenamefZ	formatterZpygments_cssr   Zcustom_css_filenamer   r   r   r   :   s*    
$z*CSSHTMLHeaderPreprocessor._generate_headerc          	   C   s4   t  }t|d}||  W dQ R X | S )zCompute the hash of a file.rbN)hashlibmd5r   updater   Zdigest)r   filenamer'   r$   r   r   r   r"      s    zCSSHTMLHeaderPreprocessor._hashN)__name__
__module____qualname____doc__r   tagr    r   r	   r   r   r"   r   r   r   r   r      s   Mr   )r-   r   r   r&   Znbconvert.resourcesr   Z	traitletsr   baser   Znotebookr   ImportErrorr   r   r   r   r   <module>   s   
