def class2md(self, cls, depth=<NUM_LIT:2>):
section = "<STR_LIT:#>" * depth<EOL>subsection = "<STR_LIT:#>" * (depth + <NUM_LIT:2>)<EOL>clsname = cls.__name__<EOL>modname = cls.__module__<EOL>header = clsname<EOL>path = self.get_src_path(cls)<EOL>doc = self.doc2md(cls)<EOL>try:<EOL><INDENT>init = self.func2md(cls.__init__, clsname=clsname)<EOL><DEDENT>except (ValueError, TypeError):<EOL><INDENT>init = "<STR_LIT>"<EOL><DEDENT>variables = []<EOL>for name, obj in getmembers(cls, lambda a: not (inspect.isroutine(a) or inspect.ismethod(a))):<EOL><INDENT>if not name.startswith("<STR_LIT:_>") and type(obj) == property:<EOL><INDENT>comments = self.doc2md(obj) or inspect.getcomments(obj)<EOL>comments = "<STR_LIT>" % comments if comments else "<STR_LIT>"<EOL>variables.append("<STR_LIT>" % (subsection, clsname, name, comments))<EOL><DEDENT><DEDENT>handlers = []<EOL>for name, obj in getmembers(cls, inspect.ismethoddescriptor):<EOL><INDENT>if not name.startswith("<STR_LIT:_>") and hasattr(obj, "<STR_LIT>") and obj.__module__ == modname:<EOL><INDENT>handlers.append("<STR_LIT>" % (subsection, clsname, name))<EOL><DEDENT><DEDENT>methods = []<EOL>for name, obj in getmembers(cls, inspect.ismethod):<EOL><INDENT>if not name.startswith("<STR_LIT:_>") and hasattr(obj,<EOL>"<STR_LIT>") and obj.__module__ == modname and name not in handlers:<EOL><INDENT>methods.append(self.func2md(obj, clsname=clsname, depth=depth + <NUM_LIT:1>))<EOL><DEDENT><DEDENT>string = CLASS_TEMPLATE.format(section=section,<EOL>header=header,<EOL>path=path,<EOL>doc=doc if doc else "<STR_LIT>",<EOL>init=init,<EOL>variables="<STR_LIT>".join(variables),<EOL>handlers="<STR_LIT>".join(handlers),<EOL>methods="<STR_LIT>".join(methods))<EOL>return string<EOL>
Takes a class and creates markdown text to document its methods and variables.