def _reformat_docstring(doc, format_fn, code_newline="<STR_LIT>"):
out = []<EOL>status = {"<STR_LIT>": False, "<STR_LIT>": False, "<STR_LIT>": False}<EOL>code = False<EOL>for line in doc:<EOL><INDENT>if status["<STR_LIT>"]:<EOL><INDENT>out.append("<STR_LIT:\n>")<EOL><DEDENT>status["<STR_LIT>"] = False<EOL>if status["<STR_LIT>"]:<EOL><INDENT>status["<STR_LIT>"] = False<EOL>if line.strip() == "<STR_LIT>":<EOL><INDENT>continue<EOL><DEDENT><DEDENT>if line.strip() == "<STR_LIT>":<EOL><INDENT>code = not code<EOL>out.append(line + code_newline)<EOL>continue<EOL><DEDENT>if not code:<EOL><INDENT>if line.rstrip() == "<STR_LIT>":<EOL><INDENT>status["<STR_LIT>"] = False<EOL><DEDENT>line = format_fn(line, status)<EOL>if re_listing.match(line):<EOL><INDENT>status["<STR_LIT>"] = True<EOL><DEDENT><DEDENT>out.append(line.rstrip() + "<STR_LIT:\n>")<EOL><DEDENT>return out<EOL>
Go through lines of file and reformat using format_fn