<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> import copy <EOL> import docutils <EOL> from docutils . parsers import rst <EOL> import jinja2 <EOL> import json <EOL> import nbconvert <EOL> import nbformat <EOL> import os <EOL> import re <EOL> import sphinx <EOL> import subprocess <EOL> try : <EOL> from urllib . parse import unquote <EOL> except ImportError : <EOL> from urllib2 import unquote <EOL> _ipynbversion = <NUM_LIT:4> <EOL> RST_TEMPLATE = """<STR_LIT>""" <EOL> LATEX_PREAMBLE = r"""<STR_LIT>""" <EOL> CSS_STRING = """<STR_LIT>""" <EOL> CSS_STRING_READTHEDOCS = """<STR_LIT>""" <EOL> class Exporter ( nbconvert . RSTExporter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , allow_errors = False , timeout = <NUM_LIT:30> , codecell_lexer = '<STR_LIT:none>' ) : <EOL> """<STR_LIT>""" <EOL> self . _allow_errors = allow_errors <EOL> self . _timeout = timeout <EOL> self . _codecell_lexer = codecell_lexer <EOL> loader = jinja2 . DictLoader ( { '<STR_LIT>' : RST_TEMPLATE } ) <EOL> super ( Exporter , self ) . __init__ ( <EOL> template_file = '<STR_LIT>' , extra_loaders = [ loader ] , <EOL> filters = { <EOL> '<STR_LIT>' : markdown2rst , <EOL> '<STR_LIT>' : _get_empty_lines , <EOL> '<STR_LIT>' : _extract_toctree , <EOL> } ) <EOL> def from_notebook_node ( self , nb , resources = None , ** kw ) : <EOL> nb = copy . deepcopy ( nb ) <EOL> if resources is None : <EOL> resources = { } <EOL> else : <EOL> resources = copy . deepcopy ( resources ) <EOL> resources [ '<STR_LIT>' ] = self . _codecell_lexer <EOL> nbsphinx_metadata = nb . metadata . get ( '<STR_LIT>' , { } ) <EOL> if ( any ( c . source for c in nb . cells if c . cell_type == '<STR_LIT:code>' ) and <EOL> not any ( c . outputs for c in nb . cells if '<STR_LIT>' in c ) ) : <EOL> allow_errors = nbsphinx_metadata . get ( <EOL> '<STR_LIT>' , self . _allow_errors ) <EOL> timeout = nbsphinx_metadata . get ( '<STR_LIT>' , self . _timeout ) <EOL> pp = nbconvert . preprocessors . ExecutePreprocessor ( <EOL> allow_errors = allow_errors , timeout = timeout ) <EOL> nb , resources = pp . preprocess ( nb , resources ) <EOL> rststr , resources = super ( Exporter , self ) . from_notebook_node ( <EOL> nb , resources , ** kw ) <EOL> orphan = nbsphinx_metadata . get ( '<STR_LIT>' , False ) <EOL> if orphan is True : <EOL> rststr = '<STR_LIT>' + rststr <EOL> elif orphan is not False : <EOL> raise NotebookError ( '<STR_LIT>' . format ( orphan ) ) <EOL> return rststr , resources <EOL> class NotebookParser ( rst . Parser ) : <EOL> """<STR_LIT>""" <EOL> def get_transforms ( self ) : <EOL> """<STR_LIT>""" <EOL> return rst . Parser . get_transforms ( self ) + [ <EOL> ProcessLocalLinks , CreateSectionLabels , ReplaceAlertDivs ] <EOL> def parse ( self , inputstring , document ) : <EOL> """<STR_LIT>""" <EOL> nb = nbformat . reads ( inputstring , as_version = _ipynbversion ) <EOL> env = document . settings . env <EOL> srcdir = os . path . dirname ( env . doc2path ( env . docname ) ) <EOL> auxdir = os . path . join ( env . doctreedir , '<STR_LIT>' ) <EOL> sphinx . util . ensuredir ( auxdir ) <EOL> resources = { } <EOL> resources [ '<STR_LIT>' ] = { '<STR_LIT:path>' : srcdir } <EOL> resources [ '<STR_LIT>' ] = os . path . relpath ( auxdir , srcdir ) <EOL> resources [ '<STR_LIT>' ] = env . docname . replace ( '<STR_LIT:/>' , '<STR_LIT:_>' ) <EOL> exporter = Exporter ( allow_errors = env . config . nbsphinx_allow_errors , <EOL> timeout = env . config . nbsphinx_timeout , <EOL> codecell_lexer = env . config . nbsphinx_codecell_lexer ) <EOL> try : <EOL> rststring , resources = exporter . from_notebook_node ( nb , resources ) <EOL> except NotebookError as e : <EOL> env . warn ( env . docname , str ( e ) ) <EOL> return <EOL> for filename , data in resources . get ( '<STR_LIT>' , { } ) . items ( ) : <EOL> dest = os . path . normpath ( os . path . join ( srcdir , filename ) ) <EOL> with open ( dest , '<STR_LIT:wb>' ) as f : <EOL> f . write ( data ) <EOL> rst . Parser . parse ( self , rststring , document ) <EOL> class NotebookError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> class CodeNode ( docutils . nodes . Element ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def create ( cls , text , language = '<STR_LIT:none>' ) : <EOL> """<STR_LIT>""" <EOL> node = docutils . nodes . literal_block ( text , text , language = language ) <EOL> return cls ( text , node ) <EOL> class AdmonitionNode ( docutils . nodes . Element ) : <EOL> """<STR_LIT>""" <EOL> class NbInput ( rst . Directive ) : <EOL> """<STR_LIT>""" <EOL> required_arguments = <NUM_LIT:0> <EOL> optional_arguments = <NUM_LIT:1> <EOL> final_argument_whitespace = False <EOL> option_spec = { <EOL> '<STR_LIT>' : rst . directives . positive_int , <EOL> '<STR_LIT>' : rst . directives . nonnegative_int , <EOL> '<STR_LIT>' : rst . directives . nonnegative_int , <EOL> '<STR_LIT>' : rst . directives . flag , <EOL> } <EOL> has_content = True <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> execution_count = self . options . get ( '<STR_LIT>' ) <EOL> classes = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in self . options : <EOL> classes . append ( '<STR_LIT>' ) <EOL> container = docutils . nodes . container ( classes = classes ) <EOL> text = '<STR_LIT>' . format ( execution_count if execution_count else '<STR_LIT:U+0020>' ) <EOL> container += CodeNode . create ( text ) <EOL> latex_prompt = text + '<STR_LIT:U+0020>' <EOL> text = '<STR_LIT:\n>' . join ( self . content . data ) <EOL> node = CodeNode . create ( <EOL> text , language = self . arguments [ <NUM_LIT:0> ] if self . arguments else '<STR_LIT:none>' ) <EOL> _set_empty_lines ( node , self . options ) <EOL> node . attributes [ '<STR_LIT>' ] = latex_prompt <EOL> container += node <EOL> self . state . document [ '<STR_LIT>' ] = True <EOL> return [ container ] <EOL> class NbOutput ( rst . Directive ) : <EOL> """<STR_LIT>""" <EOL> required_arguments = <NUM_LIT:0> <EOL> optional_arguments = <NUM_LIT:1> <EOL> final_argument_whitespace = False <EOL> option_spec = { <EOL> '<STR_LIT>' : rst . directives . positive_int , <EOL> '<STR_LIT>' : rst . directives . flag , <EOL> '<STR_LIT>' : rst . directives . nonnegative_int , <EOL> '<STR_LIT>' : rst . directives . nonnegative_int , <EOL> '<STR_LIT:class>' : rst . directives . unchanged , <EOL> } <EOL> has_content = True <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> outputtype = self . arguments [ <NUM_LIT:0> ] if self . arguments else '<STR_LIT>' <EOL> execution_count = self . options . get ( '<STR_LIT>' ) <EOL> classes = [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in self . options : <EOL> classes . append ( '<STR_LIT>' ) <EOL> container = docutils . nodes . container ( classes = classes ) <EOL> if execution_count : <EOL> text = '<STR_LIT>' . format ( execution_count ) <EOL> container += CodeNode . create ( text ) <EOL> latex_prompt = text + '<STR_LIT:U+0020>' <EOL> else : <EOL> container += rst . nodes . container ( ) <EOL> latex_prompt = '<STR_LIT>' <EOL> if outputtype == '<STR_LIT>' : <EOL> classes = [ self . options . get ( '<STR_LIT:class>' , '<STR_LIT>' ) ] <EOL> output_area = docutils . nodes . container ( classes = classes ) <EOL> self . state . nested_parse ( self . content , self . content_offset , <EOL> output_area ) <EOL> container += output_area <EOL> else : <EOL> text = '<STR_LIT:\n>' . join ( self . content . data ) <EOL> node = CodeNode . create ( text ) <EOL> _set_empty_lines ( node , self . options ) <EOL> node . attributes [ '<STR_LIT>' ] = latex_prompt <EOL> container += node <EOL> self . state . document [ '<STR_LIT>' ] = True <EOL> return [ container ] <EOL> class _NbAdmonition ( rst . Directive ) : <EOL> """<STR_LIT>""" <EOL> required_arguments = <NUM_LIT:0> <EOL> optional_arguments = <NUM_LIT:0> <EOL> option_spec = { } <EOL> has_content = True <EOL> def run ( self ) : <EOL> """<STR_LIT>""" <EOL> node = AdmonitionNode ( classes = [ '<STR_LIT>' , self . _class ] ) <EOL> self . state . nested_parse ( self . content , self . content_offset , node ) <EOL> return [ node ] <EOL> class NbInfo ( _NbAdmonition ) : <EOL> """<STR_LIT>""" <EOL> _class = '<STR_LIT>' <EOL> class NbWarning ( _NbAdmonition ) : <EOL> """<STR_LIT>""" <EOL> _class = '<STR_LIT>' <EOL> def markdown2rst ( text ) : <EOL> """<STR_LIT>""" <EOL> def rawlatex2math_hook ( obj ) : <EOL> if obj . get ( '<STR_LIT:t>' ) == '<STR_LIT>' and obj [ '<STR_LIT:c>' ] [ <NUM_LIT:0> ] == '<STR_LIT>' : <EOL> obj [ '<STR_LIT:t>' ] = '<STR_LIT>' <EOL> obj [ '<STR_LIT:c>' ] = [ { <EOL> '<STR_LIT:t>' : '<STR_LIT>' , <EOL> '<STR_LIT:c>' : [ <EOL> { '<STR_LIT:t>' : '<STR_LIT>' , '<STR_LIT:c>' : [ ] } , <EOL> obj [ '<STR_LIT:c>' ] [ <NUM_LIT:1> ] , <EOL> ] <EOL> } ] <EOL> return obj <EOL> def rawlatex2math ( text ) : <EOL> json_data = json . loads ( text , object_hook = rawlatex2math_hook ) <EOL> return json . dumps ( json_data ) <EOL> rststring = pandoc ( text , '<STR_LIT>' , '<STR_LIT>' , filter_func = rawlatex2math ) <EOL> return re . sub ( r'<STR_LIT>' , <EOL> r'<STR_LIT>' , <EOL> rststring , <EOL> flags = re . MULTILINE ) <EOL> def pandoc ( source , fmt , to , filter_func = None ) : <EOL> """<STR_LIT>""" <EOL> def encode ( text ) : <EOL> return text if isinstance ( text , bytes ) else text . encode ( '<STR_LIT:utf-8>' ) <EOL> def decode ( data ) : <EOL> return data . decode ( '<STR_LIT:utf-8>' ) if isinstance ( data , bytes ) else data <EOL> cmd1 = [ '<STR_LIT>' , '<STR_LIT>' , fmt , '<STR_LIT>' , '<STR_LIT>' ] <EOL> cmd2 = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , to ] <EOL> nbconvert . utils . pandoc . check_pandoc_version ( ) <EOL> p = subprocess . Popen ( cmd1 , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> json_data , _ = p . communicate ( encode ( source ) ) <EOL> if filter_func : <EOL> json_data = encode ( filter_func ( decode ( json_data ) ) ) <EOL> p = subprocess . Popen ( cmd2 , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) <EOL> out , _ = p . communicate ( json_data ) <EOL> return decode ( out ) . rstrip ( '<STR_LIT:\n>' ) <EOL> def _extract_toctree ( cell ) : <EOL> """<STR_LIT>""" <EOL> lines = [ '<STR_LIT>' ] <EOL> options = cell . metadata [ '<STR_LIT>' ] <EOL> try : <EOL> for option , value in options . items ( ) : <EOL> if value is True : <EOL> lines . append ( '<STR_LIT>' . format ( option ) ) <EOL> elif value is False : <EOL> pass <EOL> else : <EOL> lines . append ( '<STR_LIT>' . format ( option , value ) ) <EOL> except AttributeError : <EOL> raise NotebookError ( <EOL> '<STR_LIT>' . format ( options ) ) <EOL> text = nbconvert . filters . markdown2rst ( cell . source ) <EOL> settings = docutils . frontend . OptionParser ( <EOL> components = ( rst . Parser , ) ) . get_default_values ( ) <EOL> toctree_node = docutils . utils . new_document ( '<STR_LIT>' , settings ) <EOL> parser = rst . Parser ( ) <EOL> parser . parse ( text , toctree_node ) <EOL> if '<STR_LIT>' not in options : <EOL> for sec in toctree_node . traverse ( docutils . nodes . section ) : <EOL> assert sec . children <EOL> assert isinstance ( sec . children [ <NUM_LIT:0> ] , docutils . nodes . title ) <EOL> title = sec . children [ <NUM_LIT:0> ] . astext ( ) <EOL> lines . append ( '<STR_LIT>' + title ) <EOL> break <EOL> lines . append ( '<STR_LIT>' ) <EOL> for ref in toctree_node . traverse ( docutils . nodes . reference ) : <EOL> lines . append ( ref . astext ( ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) + <EOL> '<STR_LIT>' + unquote ( ref . get ( '<STR_LIT>' ) ) + '<STR_LIT:>>' ) <EOL> return '<STR_LIT>' . join ( lines ) <EOL> def _get_empty_lines ( text ) : <EOL> """<STR_LIT>""" <EOL> before = len ( text ) - len ( text . lstrip ( '<STR_LIT:\n>' ) ) <EOL> after = len ( text ) - len ( text . strip ( '<STR_LIT:\n>' ) ) - before <EOL> return before , after <EOL> def _set_empty_lines ( node , options ) : <EOL> """<STR_LIT>""" <EOL> for attr in '<STR_LIT>' , '<STR_LIT>' : <EOL> value = options . get ( attr , <NUM_LIT:0> ) <EOL> if value : <EOL> node . attributes [ attr ] = value <EOL> class ProcessLocalLinks ( docutils . transforms . Transform ) : <EOL> """<STR_LIT>""" <EOL> default_priority = <NUM_LIT> <EOL> def apply ( self ) : <EOL> env = self . document . settings . env <EOL> for node in self . document . traverse ( docutils . nodes . reference ) : <EOL> uri = node . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not uri : <EOL> continue <EOL> elif '<STR_LIT>' in uri : <EOL> continue <EOL> elif uri . startswith ( '<STR_LIT:#>' ) or uri . startswith ( '<STR_LIT>' ) : <EOL> continue <EOL> for suffix in env . config . source_suffix : <EOL> if uri . lower ( ) . endswith ( suffix . lower ( ) ) : <EOL> target = uri [ : - len ( suffix ) ] <EOL> break <EOL> else : <EOL> target = '<STR_LIT>' <EOL> if target : <EOL> target_ext = '<STR_LIT>' <EOL> reftype = '<STR_LIT>' <EOL> refdomain = None <EOL> elif '<STR_LIT>' in uri . lower ( ) : <EOL> idx = uri . lower ( ) . find ( '<STR_LIT>' ) <EOL> target = uri [ : idx ] <EOL> target_ext = uri [ idx : ] <EOL> reftype = '<STR_LIT>' <EOL> refdomain = '<STR_LIT>' <EOL> else : <EOL> file = os . path . normpath ( <EOL> os . path . join ( os . path . dirname ( env . docname ) , uri ) ) <EOL> if not os . path . isfile ( os . path . join ( env . srcdir , file ) ) : <EOL> env . app . warn ( '<STR_LIT>' . format ( file ) , <EOL> env . doc2path ( env . docname ) ) <EOL> continue <EOL> elif file . startswith ( '<STR_LIT:..>' ) : <EOL> env . app . warn ( <EOL> '<STR_LIT>' . format ( file ) , <EOL> env . doc2path ( env . docname ) ) <EOL> continue <EOL> if not hasattr ( env , '<STR_LIT>' ) : <EOL> env . nbsphinx_files = { } <EOL> env . nbsphinx_files . setdefault ( env . docname , [ ] ) . append ( file ) <EOL> continue <EOL> target_docname = os . path . normpath ( <EOL> os . path . join ( os . path . dirname ( env . docname ) , target ) ) <EOL> if target_docname in env . found_docs : <EOL> if target_ext : <EOL> target = target_docname + target_ext <EOL> target = target . lower ( ) <EOL> linktext = node . astext ( ) <EOL> xref = sphinx . addnodes . pending_xref ( <EOL> reftype = reftype , reftarget = target , refdomain = refdomain , <EOL> refwarn = True , refexplicit = True , refdoc = env . docname ) <EOL> xref += docutils . nodes . Text ( linktext , linktext ) <EOL> node . replace_self ( xref ) <EOL> class CreateSectionLabels ( docutils . transforms . Transform ) : <EOL> """<STR_LIT>""" <EOL> default_priority = <NUM_LIT> <EOL> def apply ( self ) : <EOL> env = self . document . settings . env <EOL> i_still_have_to_create_the_notebook_label = True <EOL> for section in self . document . traverse ( docutils . nodes . section ) : <EOL> assert section . children <EOL> assert isinstance ( section . children [ <NUM_LIT:0> ] , docutils . nodes . title ) <EOL> title = section . children [ <NUM_LIT:0> ] . astext ( ) <EOL> link_id = title . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:->' ) <EOL> section [ '<STR_LIT>' ] = [ link_id ] <EOL> label = env . docname + '<STR_LIT>' + link_id <EOL> label = label . lower ( ) <EOL> env . domaindata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ label ] = ( <EOL> env . docname , link_id , title ) <EOL> env . domaindata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ label ] = ( <EOL> env . docname , link_id ) <EOL> if i_still_have_to_create_the_notebook_label : <EOL> label = env . docname . lower ( ) + '<STR_LIT>' <EOL> env . domaindata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ label ] = ( <EOL> env . docname , '<STR_LIT>' , title ) <EOL> env . domaindata [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ label ] = ( <EOL> env . docname , '<STR_LIT>' ) <EOL> i_still_have_to_create_the_notebook_label = False <EOL> class ReplaceAlertDivs ( docutils . transforms . Transform ) : <EOL> """<STR_LIT>""" <EOL> default_priority = <NUM_LIT> <EOL> _start_re = re . compile ( <EOL> r'<STR_LIT>' , <EOL> flags = re . IGNORECASE ) <EOL> _class_re = re . compile ( r'<STR_LIT>' ) <EOL> _end_re = re . compile ( r'<STR_LIT>' , flags = re . IGNORECASE ) <EOL> def apply ( self ) : <EOL> start_tags = [ ] <EOL> for node in self . document . traverse ( docutils . nodes . raw ) : <EOL> if node [ '<STR_LIT>' ] != '<STR_LIT:html>' : <EOL> continue <EOL> start_match = self . _start_re . match ( node . astext ( ) ) <EOL> if not start_match : <EOL> continue <EOL> class_match = self . _class_re . match ( start_match . group ( <NUM_LIT:2> ) ) <EOL> if not class_match : <EOL> continue <EOL> admonition_class = class_match . group ( <NUM_LIT:1> ) <EOL> if admonition_class == '<STR_LIT:info>' : <EOL> admonition_class = '<STR_LIT>' <EOL> start_tags . append ( ( node , admonition_class ) ) <EOL> for node , admonition_class in reversed ( start_tags ) : <EOL> content = [ ] <EOL> for sibling in node . traverse ( include_self = False , descend = False , <EOL> siblings = True , ascend = False ) : <EOL> end_tag = ( isinstance ( sibling , docutils . nodes . raw ) and <EOL> sibling [ '<STR_LIT>' ] == '<STR_LIT:html>' and <EOL> self . _end_re . match ( sibling . astext ( ) ) ) <EOL> if end_tag : <EOL> admonition_node = AdmonitionNode ( <EOL> classes = [ '<STR_LIT>' , admonition_class ] ) <EOL> admonition_node . extend ( content ) <EOL> parent = node . parent <EOL> parent . replace ( node , admonition_node ) <EOL> for n in content : <EOL> parent . remove ( n ) <EOL> parent . remove ( sibling ) <EOL> break <EOL> else : <EOL> content . append ( sibling ) <EOL> def builder_inited ( app ) : <EOL> """<STR_LIT>""" <EOL> latex_elements = app . builder . config . latex_elements <EOL> latex_elements [ '<STR_LIT>' ] = '<STR_LIT:\n>' . join ( [ <EOL> LATEX_PREAMBLE , <EOL> latex_elements . get ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> def html_page_context ( app , pagename , templatename , context , doctree ) : <EOL> """<STR_LIT>""" <EOL> style = '<STR_LIT>' <EOL> if doctree and doctree . get ( '<STR_LIT>' ) : <EOL> style += CSS_STRING <EOL> if doctree and app . config . html_theme == '<STR_LIT>' : <EOL> style += CSS_STRING_READTHEDOCS <EOL> if style : <EOL> context [ '<STR_LIT:body>' ] = '<STR_LIT>' + style + '<STR_LIT>' + context [ '<STR_LIT:body>' ] <EOL> def html_collect_pages ( app ) : <EOL> """<STR_LIT>""" <EOL> files = set ( ) <EOL> for file_list in getattr ( app . env , '<STR_LIT>' , { } ) . values ( ) : <EOL> files . update ( file_list ) <EOL> for file in app . status_iterator ( files , '<STR_LIT>' , <EOL> sphinx . util . console . brown , len ( files ) ) : <EOL> target = os . path . join ( app . builder . outdir , file ) <EOL> sphinx . util . ensuredir ( os . path . dirname ( target ) ) <EOL> try : <EOL> sphinx . util . copyfile ( os . path . join ( app . env . srcdir , file ) , target ) <EOL> except OSError as err : <EOL> app . warn ( '<STR_LIT>' . format ( file , err ) ) <EOL> return [ ] <EOL> def env_purge_doc ( app , env , docname ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> del env . nbsphinx_files [ docname ] <EOL> except ( AttributeError , KeyError ) : <EOL> pass <EOL> def depart_code_html ( self , node ) : <EOL> """<STR_LIT>""" <EOL> text = self . body [ - <NUM_LIT:1> ] <EOL> text = text . replace ( '<STR_LIT>' , <EOL> '<STR_LIT>' + '<STR_LIT:\n>' * node . get ( '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> text = text . replace ( '<STR_LIT>' , <EOL> '<STR_LIT:\n>' * node . get ( '<STR_LIT>' , <NUM_LIT:0> ) + '<STR_LIT>' ) <EOL> self . body [ - <NUM_LIT:1> ] = text <EOL> def visit_code_latex ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in node . attributes : <EOL> raise docutils . nodes . SkipNode ( ) <EOL> def depart_code_latex ( self , node ) : <EOL> """<STR_LIT>""" <EOL> lines = self . body [ - <NUM_LIT:1> ] . split ( '<STR_LIT:\n>' ) <EOL> out = [ ] <EOL> assert lines [ <NUM_LIT:0> ] == '<STR_LIT>' <EOL> out . append ( lines [ <NUM_LIT:0> ] ) <EOL> assert lines [ <NUM_LIT:1> ] . startswith ( r'<STR_LIT>' ) <EOL> out . append ( lines [ <NUM_LIT:1> ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> code_lines = ( <EOL> [ '<STR_LIT>' ] * node . get ( '<STR_LIT>' , <NUM_LIT:0> ) + <EOL> lines [ <NUM_LIT:2> : - <NUM_LIT:2> ] + <EOL> [ '<STR_LIT>' ] * node . get ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> ) <EOL> prompt = node . get ( '<STR_LIT>' ) <EOL> color = '<STR_LIT>' if prompt . startswith ( '<STR_LIT>' ) else '<STR_LIT>' <EOL> prefix = r'<STR_LIT>' + color + '<STR_LIT>' + prompt + '<STR_LIT:}>' if prompt else '<STR_LIT>' <EOL> for line in code_lines [ : <NUM_LIT:1> ] : <EOL> out . append ( prefix + line ) <EOL> prefix = '<STR_LIT:U+0020>' * len ( prompt ) <EOL> for line in code_lines [ <NUM_LIT:1> : ] : <EOL> out . append ( prefix + line ) <EOL> assert lines [ - <NUM_LIT:2> ] . startswith ( r'<STR_LIT>' ) <EOL> out . append ( lines [ - <NUM_LIT:2> ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert lines [ - <NUM_LIT:1> ] == '<STR_LIT>' <EOL> out . append ( lines [ - <NUM_LIT:1> ] ) <EOL> self . body [ - <NUM_LIT:1> ] = '<STR_LIT:\n>' . join ( out ) <EOL> def visit_admonition_html ( self , node ) : <EOL> self . body . append ( self . starttag ( node , '<STR_LIT>' ) ) <EOL> self . set_first_last ( node ) <EOL> if self . settings . env . config . html_theme == '<STR_LIT>' : <EOL> if node . children : <EOL> classes = node . children [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in classes : <EOL> classes . extend ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def depart_admonition_html ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def visit_admonition_latex ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' + node [ '<STR_LIT>' ] [ <NUM_LIT:1> ] + '<STR_LIT>' ) <EOL> def depart_admonition_latex ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def do_nothing ( self , node ) : <EOL> pass <EOL> def _add_notebook_parser ( app ) : <EOL> """<STR_LIT>""" <EOL> source_suffix = app . config . _raw_config . get ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> if isinstance ( source_suffix , sphinx . config . string_types ) : <EOL> source_suffix = [ source_suffix ] <EOL> if '<STR_LIT>' not in source_suffix : <EOL> source_suffix . append ( '<STR_LIT>' ) <EOL> app . config . _raw_config [ '<STR_LIT>' ] = source_suffix <EOL> source_parsers = app . config . _raw_config . get ( '<STR_LIT>' , { } ) <EOL> if '<STR_LIT>' not in source_parsers and '<STR_LIT>' not in source_parsers : <EOL> source_parsers [ '<STR_LIT>' ] = NotebookParser <EOL> app . config . _raw_config [ '<STR_LIT>' ] = source_parsers <EOL> def setup ( app ) : <EOL> """<STR_LIT>""" <EOL> _add_notebook_parser ( app ) <EOL> app . add_config_value ( '<STR_LIT>' , False , rebuild = '<STR_LIT>' ) <EOL> app . add_config_value ( '<STR_LIT>' , <NUM_LIT:30> , rebuild = '<STR_LIT>' ) <EOL> app . add_config_value ( '<STR_LIT>' , '<STR_LIT:none>' , rebuild = '<STR_LIT>' ) <EOL> app . add_directive ( '<STR_LIT>' , NbInput ) <EOL> app . add_directive ( '<STR_LIT>' , NbOutput ) <EOL> app . add_directive ( '<STR_LIT>' , NbInfo ) <EOL> app . add_directive ( '<STR_LIT>' , NbWarning ) <EOL> app . add_node ( CodeNode , <EOL> html = ( do_nothing , depart_code_html ) , <EOL> latex = ( visit_code_latex , depart_code_latex ) ) <EOL> app . add_node ( AdmonitionNode , <EOL> html = ( visit_admonition_html , depart_admonition_html ) , <EOL> latex = ( visit_admonition_latex , depart_admonition_latex ) ) <EOL> app . connect ( '<STR_LIT>' , builder_inited ) <EOL> app . connect ( '<STR_LIT>' , html_page_context ) <EOL> app . connect ( '<STR_LIT>' , html_collect_pages ) <EOL> app . connect ( '<STR_LIT>' , env_purge_doc ) <EOL> rst . directives . register_directive ( '<STR_LIT:code>' , sphinx . directives . code . CodeBlock ) <EOL> return { '<STR_LIT:version>' : __version__ , '<STR_LIT>' : True } </s>
