ó
§]c           @   s   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 Wn e k
 r d Z n Xd e	 f d     YZ d S(	   s;   Module that pre-processes the notebook for export to HTML.
iĸĸĸĸN(   t   Unicodei   (   t   Preprocessor(   t   DEFAULT_STATIC_FILES_PATHt   CSSHTMLHeaderPreprocessorc           B   sn   e  Z d  Z e d d d j d e  Z e d d d j d e  Z d   Z d   Z	 d	   Z
 d
   Z RS(   s   
    Preprocessor used to pre-process notebook for HTML output.  Adds IPython notebook
    front-end CSS and Pygments CSS to HTML output.
    s
   .highlightt   helps   CSS highlight class identifiert   configt   defaults!   Name of the pygments style to usec         O   s    t  j |  | |  d  |  _ d  S(   N(   R   t   __init__t   Nonet   _default_css_hash(   t   selft   pargst   kwargs(    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyR   #   s    c         C   s+   i  | d <|  j  |  | d d <| | f S(   sė  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.
        t   inliningt   css(   t   _generate_header(   R
   t   nbt	   resources(    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyt
   preprocess'   s    
c   
      C   sb  d d l  m } g  } t j j t j j t j j  d  } t	 j
 | d d  } | j | j    Wd QX| d |  j  } | j |  j  } | j |  | d } t j j | d	 d
  }	 t j j |	  r^t r|  j d k r|  j t j j t d	 d
   |  _ n  |  j |	  |  j k r^t	 j
 |	 d d  } | j | j    Wd QXq^n  | S(   sd    
        Fills self.header with lines of CSS extracted from IPython 
        and Pygments.
        iĸĸĸĸ(   t   HtmlFormatters   style.min.csst   encodings   utf-8Nt   stylet
   config_dirt   customs
   custom.css(   t   pygments.formattersR   t   ost   patht   joint   dirnamet	   nbconvertR   t   __file__t   iot   opent   appendt   readR   t   get_style_defst   highlight_classt   isfileR   R	   R   t   _hash(
   R
   R   R   t   headert   sheet_filenamet   ft	   formattert   pygments_cssR   t   custom_css_filename(    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyR   :   s&    		
'c         C   sA   t  j   } t | d   } | j | j    Wd QX| j   S(   s   Compute the hash of a file.t   rbN(   t   hashlibt   md5R    t   updateR"   t   digest(   R
   t   filenameR/   R)   (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyR&   ^   s    (   t   __name__t
   __module__t   __doc__R    t   tagt   TrueR$   R   R   R   R   R&   (    (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyR      s   							$(   R5   R   R   R.   t   nbconvert.resourcesR   t	   traitletsR    t   baseR   t   notebookR   t   ImportErrorR   R   (    (    (    sD   lib/python2.7/site-packages/nbconvert/preprocessors/csshtmlheader.pyt   <module>   s   
