<s> from acrylamid import log <EOL> from acrylamid . filters import Filter <EOL> from acrylamid . lib . html import HTMLParser , HTMLParseError <EOL> class Text ( HTMLParser ) : <EOL> """<STR_LIT>""" <EOL> handle_comment = handle_startendtag = lambda * x , ** z : None <EOL> def __init__ ( self , html , args ) : <EOL> self . ignored = args <EOL> super ( Text , self ) . __init__ ( html ) <EOL> def handle_starttag ( self , tag , attrs ) : <EOL> self . stack . append ( tag ) <EOL> def handle_endtag ( self , tag ) : <EOL> try : <EOL> self . stack . pop ( ) <EOL> except IndexError : <EOL> pass <EOL> if tag in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:p>' ) : <EOL> self . result . append ( '<STR_LIT:\n>' ) <EOL> def handle_data ( self , data ) : <EOL> if not any ( tag for tag in self . ignored if tag in self . stack ) : <EOL> super ( Text , self ) . handle_data ( data ) <EOL> def handle_entityref ( self , name ) : <EOL> if name == '<STR_LIT>' : <EOL> return <EOL> self . handle_data ( self . unescape ( '<STR_LIT:&>' + name + '<STR_LIT:;>' ) ) <EOL> def handle_charref ( self , char ) : <EOL> self . handle_data ( self . unescape ( '<STR_LIT>' + char + '<STR_LIT:;>' ) ) <EOL> class Strip ( Filter ) : <EOL> match = [ '<STR_LIT>' ] <EOL> version = <NUM_LIT:1> <EOL> priority = <NUM_LIT:0.0> <EOL> def transform ( self , content , entry , * args ) : <EOL> try : <EOL> return '<STR_LIT>' . join ( Text ( content , args ) . result ) <EOL> except HTMLParseError : <EOL> log . exception ( '<STR_LIT>' + entry . filename ) <EOL> return content </s>
