<s> from docutils . nodes import Body , Element <EOL> from docutils . parsers . rst import directives <EOL> class only_base ( Body , Element ) : <EOL> def dont_traverse ( self , * args , ** kwargs ) : <EOL> return [ ] <EOL> class html_only ( only_base ) : <EOL> pass <EOL> class latex_only ( only_base ) : <EOL> pass <EOL> def run ( content , node_class , state , content_offset ) : <EOL> text = '<STR_LIT:\n>' . join ( content ) <EOL> node = node_class ( text ) <EOL> state . nested_parse ( content , content_offset , node ) <EOL> return [ node ] <EOL> def html_only_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> return run ( content , html_only , state , content_offset ) <EOL> def latex_only_directive ( name , arguments , options , content , lineno , <EOL> content_offset , block_text , state , state_machine ) : <EOL> return run ( content , latex_only , state , content_offset ) <EOL> def builder_inited ( app ) : <EOL> if app . builder . name == '<STR_LIT:html>' : <EOL> latex_only . traverse = only_base . dont_traverse <EOL> else : <EOL> html_only . traverse = only_base . dont_traverse <EOL> def setup ( app ) : <EOL> app . add_directive ( '<STR_LIT>' , html_only_directive , True , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> app . add_directive ( '<STR_LIT>' , latex_only_directive , True , ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> app . add_node ( html_only ) <EOL> app . add_node ( latex_only ) <EOL> def visit_perform ( self , node ) : <EOL> pass <EOL> def depart_perform ( self , node ) : <EOL> pass <EOL> def visit_ignore ( self , node ) : <EOL> node . children = [ ] <EOL> def depart_ignore ( self , node ) : <EOL> node . children = [ ] <EOL> app . add_node ( html_only , html = ( visit_perform , depart_perform ) ) <EOL> app . add_node ( html_only , latex = ( visit_ignore , depart_ignore ) ) <EOL> app . add_node ( latex_only , latex = ( visit_perform , depart_perform ) ) <EOL> app . add_node ( latex_only , html = ( visit_ignore , depart_ignore ) ) </s>
