def mod2md(module, title, title_api_section, toc=True, maxdepth=<NUM_LIT:0>):
docstr = module.__doc__<EOL>text = doctrim(docstr)<EOL>lines = text.split('<STR_LIT:\n>')<EOL>sections = find_sections(lines)<EOL>if sections:<EOL><INDENT>level = min(n for n,t in sections) - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>level = <NUM_LIT:1><EOL><DEDENT>api_md = []<EOL>api_sec = []<EOL>if title_api_section and module.__all__:<EOL><INDENT>sections.append((level+<NUM_LIT:1>, title_api_section))<EOL>for name in module.__all__:<EOL><INDENT>api_sec.append((level+<NUM_LIT:2>, "<STR_LIT>" + name + "<STR_LIT>"))<EOL>api_md += ['<STR_LIT>', '<STR_LIT>']<EOL>entry = module.__dict__[name]<EOL>if entry.__doc__:<EOL><INDENT>md, sec = doc2md(entry.__doc__, "<STR_LIT>" + name + "<STR_LIT>",<EOL>min_level=level+<NUM_LIT:2>, more_info=True, toc=False)<EOL>api_sec += sec<EOL>api_md += md<EOL><DEDENT><DEDENT><DEDENT>sections += api_sec<EOL>head = next((i for i, l in enumerate(lines) if is_heading(l)), <NUM_LIT:0>)<EOL>md = [<EOL>make_heading(level, title),<EOL>"<STR_LIT>",<EOL>] + lines[:head]<EOL>if toc:<EOL><INDENT>md += make_toc(sections, maxdepth)<EOL>md += ['<STR_LIT>']<EOL><DEDENT>md += _doc2md(lines[head:])<EOL>md += [<EOL>'<STR_LIT>',<EOL>'<STR_LIT>',<EOL>make_heading(level+<NUM_LIT:1>, title_api_section),<EOL>]<EOL>if toc:<EOL><INDENT>md += ['<STR_LIT>']<EOL>md += make_toc(api_sec, <NUM_LIT:1>)<EOL><DEDENT>md += api_md<EOL>return "<STR_LIT:\n>".join(md)<EOL>
Generate markdown document from module, including API section.