<s> """<STR_LIT>""" <EOL> from docutils import nodes <EOL> import docutils . parsers . rst . directives as directives <EOL> from sphinx . util . compat import Directive <EOL> from sphinx import addnodes <EOL> class subfig ( nodes . General , nodes . Element ) : <EOL> pass <EOL> def skip_visit ( self , node ) : <EOL> raise nodes . SkipNode <EOL> def visit_subfig_tex ( self , node ) : <EOL> self . __body = self . body <EOL> self . body = [ ] <EOL> def depart_subfig_tex ( self , node ) : <EOL> figoutput = '<STR_LIT>' . join ( self . body ) <EOL> figoutput = figoutput . replace ( '<STR_LIT>' , '<STR_LIT>' % node [ '<STR_LIT:width>' ] ) <EOL> figoutput = figoutput . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . body = self . __body <EOL> self . body . append ( figoutput ) <EOL> def visit_subfig_html ( self , node ) : <EOL> self . __body = self . body <EOL> self . body = [ ] <EOL> def depart_subfig_html ( self , node ) : <EOL> figoutput = '<STR_LIT>' . join ( self . body ) <EOL> figoutput = figoutput . replace ( '<STR_LIT>' , '<STR_LIT>' % ( float ( node [ '<STR_LIT:width>' ] ) * <NUM_LIT:100> ) ) <EOL> self . body = self . __body <EOL> self . body . append ( figoutput ) <EOL> class subfigstart ( nodes . General , nodes . Element ) : <EOL> pass <EOL> def visit_subfigstart_tex ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def depart_subfigstart_tex ( self , node ) : <EOL> pass <EOL> def visit_subfigstart_html ( self , node ) : <EOL> atts = { '<STR_LIT:class>' : '<STR_LIT>' } <EOL> self . body . append ( self . starttag ( node [ '<STR_LIT>' ] , '<STR_LIT>' , ** atts ) ) <EOL> def depart_subfigstart_html ( self , node ) : <EOL> pass <EOL> class subfigend ( nodes . General , nodes . Element ) : <EOL> pass <EOL> def visit_subfigend_tex ( self , node ) : <EOL> pass <EOL> def depart_subfigend_tex ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> def visit_subfigend_html ( self , node ) : <EOL> pass <EOL> def depart_subfigend_html ( self , node ) : <EOL> self . body . append ( '<STR_LIT>' ) <EOL> class SubFigEndDirective ( Directive ) : <EOL> has_content = True <EOL> optional_arguments = <NUM_LIT:3> <EOL> final_argument_whitespace = True <EOL> option_spec = { '<STR_LIT:label>' : directives . uri , <EOL> '<STR_LIT>' : directives . unchanged , <EOL> '<STR_LIT:width>' : directives . unchanged_required } <EOL> def run ( self ) : <EOL> label = self . options . get ( '<STR_LIT:label>' , None ) <EOL> width = self . options . get ( '<STR_LIT:width>' , None ) <EOL> alt = self . options . get ( '<STR_LIT>' , None ) <EOL> node = subfigend ( '<STR_LIT>' , ids = [ label ] if label is not None else [ ] ) <EOL> if width is not None : <EOL> node [ '<STR_LIT:width>' ] = width <EOL> if alt is not None : <EOL> node [ '<STR_LIT>' ] = alt <EOL> if self . content : <EOL> anon = nodes . Element ( ) <EOL> self . state . nested_parse ( self . content , self . content_offset , anon ) <EOL> first_node = anon [ <NUM_LIT:0> ] <EOL> if isinstance ( first_node , nodes . paragraph ) : <EOL> caption = nodes . caption ( first_node . rawsource , '<STR_LIT>' , <EOL> * first_node . children ) <EOL> node += caption <EOL> if label is not None : <EOL> targetnode = nodes . target ( '<STR_LIT>' , '<STR_LIT>' , ids = [ label ] ) <EOL> node . append ( targetnode ) <EOL> return [ node ] <EOL> class SubFigStartDirective ( Directive ) : <EOL> has_content = False <EOL> optional_arguments = <NUM_LIT:0> <EOL> def run ( self ) : <EOL> node = subfigstart ( ) <EOL> return [ node ] <EOL> def doctree_read ( app , doctree ) : <EOL> secnums = app . builder . env . toc_secnumbers <EOL> for node in doctree . traverse ( subfigstart ) : <EOL> parentloc = node . parent . children . index ( node ) <EOL> subfigendloc = parentloc <EOL> while subfigendloc < len ( node . parent . children ) : <EOL> n = node . parent . children [ subfigendloc ] <EOL> if isinstance ( n , subfigend ) : <EOL> break <EOL> subfigendloc += <NUM_LIT:1> <EOL> if subfigendloc == len ( node . parent . children ) : <EOL> return <EOL> between_nodes = node . parent . children [ parentloc : subfigendloc ] <EOL> subfigend_node = node . parent . children [ subfigendloc ] <EOL> node [ '<STR_LIT>' ] = subfigend_node <EOL> for i , n in enumerate ( between_nodes ) : <EOL> if isinstance ( n , nodes . figure ) : <EOL> children = [ n ] <EOL> prevnode = between_nodes [ i - <NUM_LIT:1> ] <EOL> if isinstance ( prevnode , nodes . target ) : <EOL> node . parent . children . remove ( prevnode ) <EOL> children . insert ( <NUM_LIT:0> , prevnode ) <EOL> nodeloc = node . parent . children . index ( n ) <EOL> node . parent . children [ nodeloc ] = subfig ( '<STR_LIT>' , * children ) <EOL> node . parent . children [ nodeloc ] [ '<STR_LIT:width>' ] = subfigend_node [ '<STR_LIT:width>' ] <EOL> node . parent . children [ nodeloc ] [ '<STR_LIT>' ] = subfigend_node [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> def setup ( app ) : <EOL> app . add_node ( subfigstart , <EOL> html = ( visit_subfigstart_html , depart_subfigstart_html ) , <EOL> singlehtml = ( visit_subfigstart_html , depart_subfigstart_html ) , <EOL> text = ( skip_visit , None ) , <EOL> latex = ( visit_subfigstart_tex , depart_subfigstart_tex ) ) <EOL> app . add_node ( subfig , <EOL> html = ( visit_subfig_html , depart_subfig_html ) , <EOL> singlehtml = ( visit_subfig_html , depart_subfig_html ) , <EOL> text = ( skip_visit , None ) , <EOL> latex = ( visit_subfig_tex , depart_subfig_tex ) ) <EOL> app . add_node ( subfigend , <EOL> html = ( visit_subfigend_html , depart_subfigend_html ) , <EOL> singlehtml = ( visit_subfigend_html , depart_subfigend_html ) , <EOL> text = ( skip_visit , None ) , <EOL> latex = ( visit_subfigend_tex , depart_subfigend_tex ) ) <EOL> app . add_directive ( '<STR_LIT>' , SubFigStartDirective ) <EOL> app . add_directive ( '<STR_LIT>' , SubFigEndDirective ) <EOL> app . connect ( '<STR_LIT>' , doctree_read ) </s>
