<s> import re <EOL> RE_CHECKBOX_IN_HTML = re . compile ( '<STR_LIT>' ) <EOL> RE_CHECKBOX_IN_TEXT = re . compile ( '<STR_LIT>' ) <EOL> CHECKED = '<STR_LIT>' <EOL> UNCHECKED = '<STR_LIT>' <EOL> HTML_CHECKED = '<STR_LIT>' <EOL> HTML_UNCHECKED = '<STR_LIT>' <EOL> def get_checkbox_count ( content ) : <EOL> m = re . findall ( RE_CHECKBOX_IN_TEXT , content ) <EOL> if m : <EOL> checked = filter ( lambda x : x == CHECKED , m ) <EOL> return ( len ( checked ) , len ( m ) ) <EOL> def render_checklist ( content ) : <EOL> i = <NUM_LIT:0> <EOL> while <NUM_LIT:1> : <EOL> m = re . search ( RE_CHECKBOX_IN_HTML , content ) <EOL> if not m : <EOL> break <EOL> t = m . group ( <NUM_LIT:0> ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> source = '<STR_LIT>' % i <EOL> end = lambda type , idx : '<STR_LIT>' + t . lstrip ( type ) . strip ( ) + '<STR_LIT>' + content [ idx + len ( t ) + len ( '<STR_LIT>' ) : ] <EOL> if t . startswith ( CHECKED ) : <EOL> checked_idx = content . find ( HTML_CHECKED ) <EOL> content = content [ : checked_idx ] + source + '<STR_LIT>' + end ( CHECKED , checked_idx ) <EOL> else : <EOL> unchecked_idx = content . find ( HTML_UNCHECKED ) <EOL> content = content [ : unchecked_idx ] + source + end ( UNCHECKED , unchecked_idx ) <EOL> i += <NUM_LIT:1> <EOL> return content </s>
