<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> __docformat__ = '<STR_LIT>' <EOL> import re <EOL> import sys <EOL> from docutils import nodes , writers , frontend <EOL> from docutils . transforms import Transform <EOL> try : <EOL> from collections import OrderedDict <EOL> except ImportError : <EOL> from ordereddict import OrderedDict <EOL> try : <EOL> from docutils . utils . math import pick_math_environment <EOL> except ImportError : <EOL> from docutils . math import pick_math_environment <EOL> from genshi . builder import tag <EOL> from genshi . output import XHTMLSerializer <EOL> from genshi . core import Markup <EOL> if sys . version [ <NUM_LIT:0> ] == '<STR_LIT:3>' : <EOL> unicode = str <EOL> class FooterToBottom ( Transform ) : <EOL> '''<STR_LIT>''' <EOL> default_priority = <NUM_LIT> <EOL> def apply ( self ) : <EOL> for child in self . document . children : <EOL> if isinstance ( child , nodes . decoration ) : <EOL> for footer in child : <EOL> if isinstance ( footer , nodes . footer ) : <EOL> child . remove ( footer ) <EOL> self . document . append ( footer ) <EOL> break <EOL> def _script_callback_option_parser ( option , opt_str , value , parser ) : <EOL> '''<STR_LIT>''' <EOL> attr = '<STR_LIT>' in opt_str and '<STR_LIT>' or '<STR_LIT>' in opt_str and '<STR_LIT>' or None <EOL> parser . values . script = parser . values . script or [ ] <EOL> parser . values . script . append ( ( value , attr ) ) <EOL> return <EOL> class HTML5Writer ( writers . Writer ) : <EOL> supported = ( '<STR_LIT:html>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> config_section = '<STR_LIT>' <EOL> config_section_dependencies = ( '<STR_LIT>' ) <EOL> settings_spec = ( <EOL> '<STR_LIT>' , <EOL> None , ( <EOL> ( "<STR_LIT>" , [ '<STR_LIT>' ] , <EOL> { '<STR_LIT:default>' : <NUM_LIT:1> , '<STR_LIT:action>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:default>' : None , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:default>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _script_callback_option_parser , } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _script_callback_option_parser , } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : _script_callback_option_parser , } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:default>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:action>' : '<STR_LIT>' , } ) , <EOL> ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT:default>' : None , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : '<STR_LIT:string>' , <EOL> '<STR_LIT:action>' : '<STR_LIT:store>' , } ) , <EOL> ) <EOL> ) <EOL> settings_defaults = { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> } <EOL> def __init__ ( self ) : <EOL> writers . Writer . __init__ ( self ) <EOL> self . translator_class = HTML5Translator <EOL> return <EOL> def translate ( self ) : <EOL> visitor = self . translator_class ( self . document ) <EOL> self . document . walkabout ( visitor ) <EOL> self . output = visitor . output <EOL> self . head = visitor . head <EOL> self . body = visitor . body <EOL> self . title = visitor . title <EOL> self . docinfo = visitor . docinfo <EOL> return <EOL> def assemble_parts ( self ) : <EOL> writers . Writer . assemble_parts ( self ) <EOL> self . parts [ '<STR_LIT>' ] = self . head <EOL> self . parts [ '<STR_LIT:body>' ] = self . body <EOL> self . parts [ '<STR_LIT:title>' ] = self . title <EOL> self . parts [ '<STR_LIT>' ] = self . docinfo <EOL> return <EOL> def get_transforms ( self ) : <EOL> return writers . Writer . get_transforms ( self ) + [ FooterToBottom ] <EOL> class ElemStack ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , settings ) : <EOL> self . stack = [ ] <EOL> self . indent_level = <NUM_LIT:0> <EOL> self . indent_output = settings . indent_output <EOL> self . indent_width = settings . tab_width <EOL> def _indent_elem ( self , element , indent ) : <EOL> result = [ ] <EOL> if self . indent_output and indent : <EOL> indentation = '<STR_LIT:\n>' + self . indent_width * self . indent_level * '<STR_LIT:U+0020>' <EOL> result . append ( indentation ) <EOL> result . append ( element ) <EOL> if self . indent_output and indent : <EOL> indentation = '<STR_LIT:\n>' + self . indent_width * ( self . indent_level - <NUM_LIT:1> ) * '<STR_LIT:U+0020>' <EOL> result . append ( indentation ) <EOL> return result <EOL> def append ( self , element , indent = True ) : <EOL> '''<STR_LIT>''' <EOL> self . stack [ - <NUM_LIT:1> ] . append ( self . _indent_elem ( element , indent ) ) <EOL> return <EOL> def begin_elem ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . stack . append ( [ ] ) <EOL> self . indent_level += <NUM_LIT:1> <EOL> return <EOL> def commit_elem ( self , elem , indent = True ) : <EOL> '''<STR_LIT>''' <EOL> pop = self . stack . pop ( ) <EOL> elem ( * pop ) <EOL> self . indent_level -= <NUM_LIT:1> <EOL> self . append ( elem , indent ) <EOL> return <EOL> def pop ( self ) : <EOL> return self . pop_elements ( <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> def pop_elements ( self , num_elements ) : <EOL> assert num_elements > <NUM_LIT:0> <EOL> parent_stack = self . stack [ - <NUM_LIT:1> ] <EOL> result = [ ] <EOL> for x in range ( num_elements ) : <EOL> pop = parent_stack . pop ( ) <EOL> elem = pop [ <NUM_LIT:0> if len ( pop ) == <NUM_LIT:1> else self . indent_output ] <EOL> result . append ( elem ) <EOL> result . reverse ( ) <EOL> return result <EOL> dv = '<STR_LIT>' <EOL> dp = '<STR_LIT>' <EOL> pass_ = '<STR_LIT>' <EOL> class HTML5Translator ( nodes . NodeVisitor ) : <EOL> rst_terms = { <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( None , dv , dp ) , <EOL> '<STR_LIT:address>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:p>' , dv , dp , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:a>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , True , False ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , pass_ , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT:date>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT:description>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False , False ) , <EOL> '<STR_LIT>' : ( None , dv , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , '<STR_LIT>' ) , <EOL> '<STR_LIT:error>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , dp ) , <EOL> '<STR_LIT>' : ( None , dv , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , True , False ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT:image>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False , False ) , <EOL> '<STR_LIT:label>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , True ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:code>' , '<STR_LIT>' , '<STR_LIT>' , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , dp , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , dp , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:p>' , '<STR_LIT>' , dp ) , <EOL> '<STR_LIT>' : ( None , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , True , False ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , False , False ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT:p>' , dv , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT:status>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , dv , dp , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False , False ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT:target>' : ( '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT>' , False , False ) , <EOL> '<STR_LIT>' : ( None , dv , dp ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( None , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT:title>' : ( None , dv , '<STR_LIT>' ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp , False , False ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , dv , dp ) , <EOL> '<STR_LIT:version>' : ( None , '<STR_LIT>' , None ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , True ) , <EOL> } <EOL> default_template = '<STR_LIT>' '<STR_LIT>' <EOL> def _map_terms_to_functions ( self ) : <EOL> '''<STR_LIT>''' <EOL> for term , spec in self . rst_terms . items ( ) : <EOL> visit_func = spec [ <NUM_LIT:1> ] and getattr ( self , spec [ <NUM_LIT:1> ] , self . unknown_visit ) <EOL> depart_func = spec [ <NUM_LIT:2> ] and getattr ( self , spec [ <NUM_LIT:2> ] , self . unknown_departure ) <EOL> if visit_func : <EOL> setattr ( self , '<STR_LIT>' + term , visit_func ) <EOL> if depart_func : <EOL> setattr ( self , '<STR_LIT>' + term , depart_func ) <EOL> return <EOL> def _get_template ( self , document ) : <EOL> template = document . settings . template <EOL> if not template : <EOL> return self . default_template <EOL> import os <EOL> if os . path . isfile ( template ) : <EOL> from io import open <EOL> with open ( template , '<STR_LIT:r>' , encoding = '<STR_LIT:utf-8>' ) as template_file : <EOL> return template_file . read ( ) <EOL> else : <EOL> return template <EOL> def __init__ ( self , document ) : <EOL> nodes . NodeVisitor . __init__ ( self , document ) <EOL> self . heading_level = int ( getattr ( self . document . settings , '<STR_LIT>' , <NUM_LIT:0> ) ) <EOL> self . context = ElemStack ( document . settings ) <EOL> self . template = self . _get_template ( document ) <EOL> self . docinfo = OrderedDict ( ) <EOL> self . _parse_params ( ) <EOL> self . _map_terms_to_functions ( ) <EOL> return <EOL> def _parse_params ( self ) : <EOL> self . metatags = [ tag . meta ( charset = self . document . settings . output_encoding ) ] <EOL> self . stylesheets = [ ] <EOL> stylesheets = self . document . settings . stylesheet or [ ] <EOL> for href in stylesheets : <EOL> self . stylesheets . append ( tag . link ( rel = '<STR_LIT>' , href = href ) ) <EOL> self . scripts = [ ] <EOL> scripts = self . document . settings . script or [ ] <EOL> for src , attributes in scripts : <EOL> script = tag . script ( src = src ) <EOL> if attributes : <EOL> script = script ( ** { attributes : attributes } ) <EOL> self . scripts . append ( script ) <EOL> return <EOL> def indent_head ( self ) : <EOL> if self . document . settings . indent_output : <EOL> indent = '<STR_LIT:\n>' + '<STR_LIT:U+0020>' * self . document . settings . tab_width <EOL> result = [ ] <EOL> for f in self . head : <EOL> result . append ( tag ( indent , f ) ) <EOL> result . append ( '<STR_LIT:\n>' ) <EOL> self . head = result <EOL> return <EOL> def _get_template_values ( self ) : <EOL> html_attrs = self . document . settings . html_tag_attr <EOL> html_attrs = html_attrs and '<STR_LIT:U+0020>' + '<STR_LIT:U+0020>' . join ( html_attrs ) or '<STR_LIT>' <EOL> self . head = self . metatags + self . stylesheets + self . scripts <EOL> for key , value in self . docinfo . items ( ) : <EOL> self . head . append ( tag . meta ( name = key , content = value ) ) <EOL> self . indent_head ( ) <EOL> self . head = '<STR_LIT>' . join ( XHTMLSerializer ( ) ( tag ( * self . head ) ) ) <EOL> self . body = '<STR_LIT>' . join ( XHTMLSerializer ( ) ( tag ( * self . context . stack ) ) ) <EOL> values = { } <EOL> values [ '<STR_LIT>' ] = html_attrs <EOL> values [ '<STR_LIT>' ] = self . head <EOL> values [ '<STR_LIT:body>' ] = self . body <EOL> return values <EOL> @ property <EOL> def output ( self ) : <EOL> values = self . _get_template_values ( ) <EOL> return self . template . format ( ** values ) <EOL> def set_next_elem_attr ( self , name , value ) : <EOL> '''<STR_LIT>''' <EOL> self . next_elem_attr = { name : value } <EOL> def parse ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> node_class_name = node . __class__ . __name__ <EOL> spec = self . rst_terms [ node_class_name ] <EOL> tag_name = spec [ <NUM_LIT:0> ] or node_class_name <EOL> use_name_in_class = len ( spec ) > <NUM_LIT:3> and spec [ <NUM_LIT:3> ] <EOL> indent = spec [ <NUM_LIT:4> ] if len ( spec ) > <NUM_LIT:4> else True <EOL> if use_name_in_class : <EOL> node [ '<STR_LIT>' ] . insert ( <NUM_LIT:0> , node_class_name ) <EOL> attributes = { } <EOL> replacements = { <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:src>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT:class>' , <EOL> '<STR_LIT>' : '<STR_LIT:id>' , <EOL> } <EOL> ignores = ( <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ) <EOL> for k , v in node . attributes . items ( ) : <EOL> if k in ignores or not v : <EOL> continue <EOL> if k in replacements : <EOL> k = replacements [ k ] <EOL> if isinstance ( v , list ) : <EOL> v = '<STR_LIT:U+0020>' . join ( v ) <EOL> attributes [ k ] = v <EOL> if getattr ( self , '<STR_LIT>' , None ) : <EOL> attributes . update ( self . next_elem_attr ) <EOL> del self . next_elem_attr <EOL> return tag_name , indent , attributes <EOL> def once_attr ( self , name , default = None ) : <EOL> '''<STR_LIT>''' <EOL> if hasattr ( self , name ) : <EOL> result = getattr ( self , name ) <EOL> delattr ( self , name ) <EOL> return result <EOL> else : <EOL> return default <EOL> def default_visit ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in node and self . once_attr ( '<STR_LIT>' , default = True ) : <EOL> for id in node [ '<STR_LIT>' ] [ <NUM_LIT:1> : ] : <EOL> self . context . begin_elem ( ) <EOL> self . context . commit_elem ( tag . a ( id = id ) ) <EOL> node . attributes [ '<STR_LIT>' ] = node . attributes [ '<STR_LIT>' ] [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> self . context . begin_elem ( ) <EOL> return <EOL> def default_departure ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> tag_name , indent , attributes = self . parse ( node ) <EOL> elem = getattr ( tag , tag_name ) ( ** attributes ) <EOL> self . context . commit_elem ( elem , indent ) <EOL> return <EOL> def _compacted_paragraph ( self , node ) : <EOL> """<STR_LIT>""" <EOL> if ( ( isinstance ( node . parent , ( nodes . document , nodes . compound , <EOL> nodes . block_quote , nodes . system_message , ) ) or <EOL> node [ '<STR_LIT>' ] or '<STR_LIT>' != node . __class__ . __name__ ) ) : <EOL> return False <EOL> first = isinstance ( node . parent [ <NUM_LIT:0> ] , nodes . label ) <EOL> for child in node . parent . children [ first : ] : <EOL> if isinstance ( child , nodes . Invisible ) : <EOL> continue <EOL> if child is node : <EOL> break <EOL> return False <EOL> parent_length = len ( [ n for n in node . parent if not isinstance ( <EOL> n , ( nodes . Invisible , nodes . label ) ) ] ) <EOL> return parent_length == <NUM_LIT:1> <EOL> def visit_paragraph ( self , node ) : <EOL> if self . _compacted_paragraph ( node ) : <EOL> raise nodes . SkipDeparture <EOL> self . default_visit ( node ) <EOL> def _strip_spaces ( self , text ) : <EOL> return re . sub ( r'<STR_LIT>' , '<STR_LIT:U+0020>' , text ) <EOL> def visit_Text ( self , node ) : <EOL> text = node . astext ( ) <EOL> if not getattr ( self , '<STR_LIT>' , None ) : <EOL> text = self . _strip_spaces ( text ) <EOL> self . context . append ( text , indent = False ) <EOL> raise nodes . SkipDeparture <EOL> def visit_section ( self , node ) : <EOL> self . heading_level += <NUM_LIT:1> <EOL> self . default_visit ( node ) <EOL> def depart_section ( self , node ) : <EOL> self . heading_level -= <NUM_LIT:1> <EOL> self . default_departure ( node ) <EOL> def depart_title ( self , node ) : <EOL> spec , indent , attr = self . parse ( node ) <EOL> if isinstance ( node . parent , nodes . table ) : <EOL> elem = tag . caption ( ** attr ) <EOL> else : <EOL> assert self . heading_level >= <NUM_LIT:0> <EOL> if self . heading_level == <NUM_LIT:0> : <EOL> self . heading_level = <NUM_LIT:1> <EOL> if '<STR_LIT>' in attr : <EOL> del attr [ '<STR_LIT>' ] <EOL> elem = getattr ( tag , '<STR_LIT:h>' + unicode ( self . heading_level ) ) ( ** attr ) <EOL> self . context . commit_elem ( elem , indent ) <EOL> def depart_subtitle ( self , node ) : <EOL> subheading_level = getattr ( tag , '<STR_LIT:h>' + unicode ( self . heading_level + <NUM_LIT:1> ) ) <EOL> self . context . commit_elem ( subheading_level ) <EOL> self . heading_level -= <NUM_LIT:1> <EOL> def depart_enumerated_list ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in node : <EOL> enumtypes = { <EOL> '<STR_LIT>' : '<STR_LIT:1>' , <EOL> '<STR_LIT>' : '<STR_LIT:a>' , <EOL> '<STR_LIT>' : '<STR_LIT:A>' , <EOL> '<STR_LIT>' : '<STR_LIT:i>' , <EOL> '<STR_LIT>' : '<STR_LIT:I>' <EOL> } <EOL> node [ '<STR_LIT:type>' ] = enumtypes . get ( node [ '<STR_LIT>' ] , '<STR_LIT:1>' ) <EOL> if node . get ( '<STR_LIT>' ) == '<STR_LIT:.>' and '<STR_LIT>' not in node : <EOL> del node [ '<STR_LIT>' ] <EOL> self . default_departure ( node ) <EOL> def skip_node ( self , node ) : <EOL> """<STR_LIT>""" <EOL> raise nodes . SkipNode <EOL> def no_op ( self , node ) : <EOL> pass <EOL> def do_nothing ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> raise nodes . SkipDeparture <EOL> def visit_classifier ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> term = self . context . pop ( ) <EOL> term ( '<STR_LIT:U+0020>' , tag . span ( '<STR_LIT::>' , class_ = '<STR_LIT>' ) , '<STR_LIT:U+0020>' , <EOL> tag . span ( node . astext ( ) , class_ = '<STR_LIT>' ) ) <EOL> self . context . append ( term ) <EOL> raise nodes . SkipNode <EOL> def visit_table ( self , node ) : <EOL> self . th_required = <NUM_LIT:0> <EOL> self . in_thead = False <EOL> self . default_visit ( node ) <EOL> def depart_table ( self , node ) : <EOL> del self . th_required <EOL> del self . in_thead <EOL> self . default_departure ( node ) <EOL> def depart_colspec ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> if '<STR_LIT>' in node : <EOL> self . th_required += <NUM_LIT:1> <EOL> return <EOL> def visit_thead ( self , node ) : <EOL> self . in_thead = True <EOL> self . default_visit ( node ) <EOL> def depart_thead ( self , node ) : <EOL> self . in_thead = False <EOL> self . default_departure ( node ) <EOL> def visit_row ( self , node ) : <EOL> self . th_available = self . th_required <EOL> self . default_visit ( node ) <EOL> def depart_row ( self , node ) : <EOL> del self . th_available <EOL> self . default_departure ( node ) <EOL> def depart_entry ( self , node ) : <EOL> if self . in_thead or self . th_available : <EOL> name = '<STR_LIT>' <EOL> self . th_available -= <NUM_LIT:1> <EOL> else : <EOL> name = '<STR_LIT>' <EOL> if '<STR_LIT>' in node : <EOL> node [ '<STR_LIT>' ] = node [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> if '<STR_LIT>' in node : <EOL> node [ '<STR_LIT>' ] = node [ '<STR_LIT>' ] + <NUM_LIT:1> <EOL> waste , indent , attr = self . parse ( node ) <EOL> self . context . commit_elem ( getattr ( tag , name ) ( ** attr ) ) <EOL> def visit_reference ( self , node ) : <EOL> if '<STR_LIT>' in node : <EOL> del node . attributes [ '<STR_LIT>' ] <EOL> self . default_visit ( node ) <EOL> return <EOL> def depart_reference ( self , node ) : <EOL> if '<STR_LIT:name>' in node : <EOL> del node [ '<STR_LIT:name>' ] <EOL> if '<STR_LIT>' in node : <EOL> node [ '<STR_LIT>' ] = '<STR_LIT:#>' + node [ '<STR_LIT>' ] <EOL> self . default_departure ( node ) <EOL> return <EOL> def visit_target ( self , node ) : <EOL> if not node . astext ( ) : <EOL> raise nodes . SkipNode <EOL> self . expand_id_to_anchor = False <EOL> self . default_visit ( node ) <EOL> def visit_literal ( self , node ) : <EOL> self . preserve_space = getattr ( self , '<STR_LIT>' , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> self . default_visit ( node ) <EOL> return <EOL> def depart_literal ( self , node ) : <EOL> self . preserve_space -= <NUM_LIT:1> <EOL> if self . preserve_space == <NUM_LIT:0> : <EOL> del self . preserve_space <EOL> if node [ '<STR_LIT>' ] : <EOL> node [ '<STR_LIT>' ] = node [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] <EOL> self . default_departure ( node ) <EOL> return <EOL> def visit_literal_block ( self , node ) : <EOL> if '<STR_LIT:code>' in node [ '<STR_LIT>' ] : <EOL> self . context . begin_elem ( ) <EOL> self . preserve_space = <NUM_LIT:1> <EOL> self . default_visit ( node ) <EOL> return <EOL> def depart_literal_block ( self , node ) : <EOL> del self . preserve_space <EOL> if '<STR_LIT:code>' in node [ '<STR_LIT>' ] : <EOL> code = node [ '<STR_LIT>' ] . index ( '<STR_LIT:code>' ) <EOL> node [ '<STR_LIT>' ] . pop ( code ) <EOL> code = tag . code ( class_ = '<STR_LIT:U+0020>' . join ( node [ '<STR_LIT>' ] ) ) <EOL> self . context . commit_elem ( code , indent = False ) <EOL> del node [ '<STR_LIT>' ] <EOL> self . default_departure ( node ) <EOL> return <EOL> def visit_math_block ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> math_code = node . astext ( ) <EOL> math_env = pick_math_environment ( math_code ) <EOL> if '<STR_LIT>' in math_env : <EOL> template = '<STR_LIT>' % ( math_env , math_code , math_env ) <EOL> elem = tag . div ( template ) <EOL> else : <EOL> template = '<STR_LIT>' % math_code <EOL> elem = tag . span ( template ) <EOL> elem ( class_ = '<STR_LIT>' ) <EOL> self . context . append ( elem ) <EOL> if not getattr ( self , '<STR_LIT>' , None ) : <EOL> src = "<STR_LIT>" <EOL> self . scripts . append ( tag . script ( src = src ) ) <EOL> self . already_has_math_script = True <EOL> raise nodes . SkipNode <EOL> def visit_document ( self , node ) : <EOL> if '<STR_LIT:title>' in node : <EOL> self . metatags . insert ( <NUM_LIT:0> , tag . title ( node [ '<STR_LIT:title>' ] ) ) <EOL> self . title = node [ '<STR_LIT:title>' ] <EOL> else : <EOL> self . title = '<STR_LIT>' <EOL> self . expand_id_to_anchor = False <EOL> self . default_visit ( node ) <EOL> def depart_document ( self , node ) : <EOL> self . context . stack = self . context . stack [ <NUM_LIT:0> ] <EOL> return <EOL> def visit_raw ( self , node ) : <EOL> if '<STR_LIT:html>' in node . get ( '<STR_LIT>' , '<STR_LIT>' ) . split ( ) : <EOL> for line in node . astext ( ) . splitlines ( ) : <EOL> self . context . append ( Markup ( line ) ) <EOL> raise nodes . SkipNode <EOL> def visit_aside ( self , node ) : <EOL> self . save_heading_level = self . heading_level <EOL> self . heading_level = <NUM_LIT:1> <EOL> self . default_visit ( node ) <EOL> def depart_aside ( self , node ) : <EOL> self . heading_level = self . save_heading_level <EOL> del self . save_heading_level <EOL> if node [ '<STR_LIT>' ] and node [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . startswith ( '<STR_LIT>' ) : <EOL> del node [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . default_departure ( node ) <EOL> def depart_rubric ( self , node ) : <EOL> node [ '<STR_LIT>' ] = [ ] <EOL> self . default_departure ( node ) <EOL> def visit_field ( self , node ) : <EOL> self . docinfo [ node . children [ <NUM_LIT:0> ] . astext ( ) ] = self . _strip_spaces ( node . children [ <NUM_LIT:1> ] . astext ( ) ) <EOL> raise nodes . SkipNode <EOL> def visit_bibliographic_field ( self , node ) : <EOL> self . docinfo [ node . __class__ . __name__ ] = self . _strip_spaces ( node . astext ( ) ) <EOL> raise nodes . SkipNode <EOL> def visit_address ( self , node ) : <EOL> self . docinfo [ node . __class__ . __name__ ] = '<STR_LIT:U+002CU+0020>' . join ( node . astext ( ) . split ( '<STR_LIT:\n>' ) ) <EOL> raise nodes . SkipNode <EOL> def visit_authors ( self , node ) : <EOL> self . docinfo [ node . __class__ . __name__ ] = '<STR_LIT>' . join ( node . astext ( ) . split ( ) ) <EOL> raise nodes . SkipNode <EOL> def visit_option_list ( self , node ) : <EOL> self . context . begin_elem ( ) <EOL> self . context . begin_elem ( ) <EOL> def depart_option_list ( self , node ) : <EOL> self . context . commit_elem ( tag . tbody ) <EOL> waste , waste_ , attr = self . parse ( node ) <EOL> self . context . commit_elem ( tag . table ( ** attr ) ) <EOL> def visit_citation ( self , node ) : <EOL> self . visit_option_list ( node ) <EOL> self . context . begin_elem ( ) <EOL> def depart_citation ( self , node ) : <EOL> self . context . commit_elem ( tag . td ) <EOL> self . context . commit_elem ( tag . tr ) <EOL> self . depart_option_list ( node ) <EOL> def visit_option_group ( self , node ) : <EOL> self . option_level = <NUM_LIT:0> <EOL> self . default_visit ( node ) <EOL> def depart_option_group ( self , node ) : <EOL> if self . document . settings . option_limit and len ( node . astext ( ) ) > self . document . settings . option_limit : <EOL> node [ '<STR_LIT>' ] = <NUM_LIT:2> <EOL> self . default_departure ( node ) <EOL> self . context . commit_elem ( tag . tr ) <EOL> self . context . begin_elem ( ) <EOL> self . context . append ( tag . td ) <EOL> else : <EOL> self . default_departure ( node ) <EOL> def visit_option ( self , node ) : <EOL> if self . option_level : <EOL> self . context . append ( '<STR_LIT:U+002CU+0020>' , indent = False ) <EOL> self . option_level += <NUM_LIT:1> <EOL> self . default_visit ( node ) <EOL> def visit_option_argument ( self , node ) : <EOL> if '<STR_LIT>' in node : <EOL> self . context . append ( node [ '<STR_LIT>' ] , indent = False ) <EOL> del node . attributes [ '<STR_LIT>' ] <EOL> self . default_visit ( node ) <EOL> def visit_citation_reference ( self , node ) : <EOL> """<STR_LIT>""" <EOL> self . expand_id_to_anchor = False <EOL> self . default_visit ( node ) <EOL> def depart_label ( self , node ) : <EOL> self . default_departure ( node ) <EOL> self . context . begin_elem ( ) <EOL> def visit_line ( self , node ) : <EOL> self . line_level = getattr ( self , '<STR_LIT>' , - <NUM_LIT:1> ) + <NUM_LIT:1> <EOL> if self . line_level : <EOL> tab_width = self . document . settings . tab_width <EOL> separator = '<STR_LIT:\n>' + '<STR_LIT:U+0020>' * tab_width * ( self . line_block_level - <NUM_LIT:1> ) <EOL> self . context . append ( separator , indent = False ) <EOL> raise nodes . SkipDeparture <EOL> def visit_line_block ( self , node ) : <EOL> '''<STR_LIT>''' <EOL> self . line_block_level = getattr ( self , '<STR_LIT>' , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> if self . line_block_level == <NUM_LIT:1> : <EOL> self . default_visit ( node ) <EOL> def depart_line_block ( self , node ) : <EOL> self . line_block_level -= <NUM_LIT:1> <EOL> if self . line_block_level == <NUM_LIT:0> : <EOL> del self . line_block_level <EOL> del self . line_level <EOL> self . default_departure ( node ) <EOL> def visit_meta ( self , node ) : <EOL> waste , waste_ , attr = self . parse ( node ) <EOL> self . metatags . append ( tag . meta ( ** attr ) ) <EOL> raise nodes . SkipNode <EOL> def visit_problematic ( self , node ) : <EOL> self . expand_id_to_anchor = False <EOL> if len ( node [ '<STR_LIT>' ] ) > <NUM_LIT:1> : <EOL> node [ '<STR_LIT>' ] = node [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . default_visit ( node ) <EOL> return <EOL> def visit_system_message ( self , node ) : <EOL> self . default_visit ( node ) <EOL> self . context . begin_elem ( ) <EOL> backrefs = [ tag ( '<STR_LIT:U+0020>' , tag . a ( v , href = "<STR_LIT:#>" + v ) ) for v in node [ '<STR_LIT>' ] ] <EOL> node . attributes . setdefault ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> text = '<STR_LIT>' '<STR_LIT>' . format ( ** node . attributes ) <EOL> h1 = tag . h1 ( text , * backrefs ) <EOL> self . context . commit_elem ( h1 ) <EOL> node . attributes = { '<STR_LIT>' : [ ] , '<STR_LIT>' : node . attributes [ '<STR_LIT>' ] } <EOL> return <EOL> def visit_figure ( self , node ) : <EOL> for child in node : <EOL> if isinstance ( child , nodes . image ) and '<STR_LIT>' in child : <EOL> node [ '<STR_LIT>' ] . extend ( child [ '<STR_LIT>' ] ) <EOL> child [ '<STR_LIT>' ] = [ ] <EOL> self . default_visit ( node ) <EOL> def main ( ) : <EOL> from docutils . core import publish_cmdline , default_description <EOL> description = '<STR_LIT>' '<STR_LIT>' + default_description <EOL> publish_cmdline ( writer = HTML5Writer ( ) , description = description ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
