'Describe the current URL map as markdown'

def map_as_markdown(self, prefix=None):

    api_version = self.API_VERSIONS[(-1)]
    text = []
    def cmds(method):
        return sorted([(c.SYNOPSIS[2], c) for c in self._api_commands(method, strict=True)])
    text.extend([('#    Mailpile    URL    map    (autogenerated    by    %s)' % __file__), '', '\n'.join([line.strip() for line in UrlMap.__doc__.strip().splitlines()[2:]]), '', ('##    The    API    paths    (version=%s,    JSON    output)' % api_version), ''])
    api = ('/api/%s' % api_version)
    for method in ('GET', 'POST', 'UPDATE', 'DELETE'):
        commands = [c for c in cmds(method) if ((not prefix) or (c[0] and c[0].startswith(prefix)))]
        if commands:
            text.extend([('###    %s%s' % (method, (((method == 'GET') and '    (also    accept    POST)') or ''))), ''])
        commands.sort()
        for command in commands:
            cls = command[1]
            url = self.canonical_url(cls)
            query_vars = cls.HTTP_QUERY_VARS
            pos_args = ((cls.SYNOPSIS[3] and unicode(cls.SYNOPSIS[3]).replace('    ', '/')) or '')
            padding = ('    ' * (18 - len(command[0])))
            newline = ('\n' + ('    ' * ((len(api) + len(command[0])) + 6)))
            if query_vars:
                qs = ('?' + '&'.join([('%s=[%s]' % (v, query_vars[v])) for v in query_vars]))
            else:
                qs = ''
            if qs:
                qs = ('%s%s' % (padding, qs))
            if pos_args:
                pos_args = ('%s%s/' % (padding, pos_args))
                if qs:
                    qs = (newline + qs)
            text.append(('                %s%s%s' % (url, pos_args, qs)))
            if cls.HTTP_POST_VARS:
                ps = '&'.join([('%s=[%s]' % (v, cls.HTTP_POST_VARS[v])) for v in cls.HTTP_POST_VARS])
                text.append(('                ...    POST    only:    %s' % ps))
        text.append('')
    if (not prefix):
        text.extend(['', '##    Pretty    shortcuts    (HTML    output)', ''])
        for path in sorted(self.MAP_PATHS.keys()):
            doc = self.MAP_PATHS[path].__doc__.strip().split('\n')[0]
            path = ('/%s/' % path).replace('//', '/')
            text.append(('                %s    %s    %s' % (path, ('    ' * (10 - len(path))), doc)))
    text.extend(['', '##    Default    command    URLs    (HTML    output)', '', '*These    accept    the    same    arguments    as    the    API    calls    above.*', ''])
    for command in sorted(list(set((cmds('GET') + cmds('POST'))))):
        if (prefix and (not command[0].startswith(prefix))):
            continue
        text.append(('                /%s/' % (command[0],)))
    text.append('')
    return '\n'.join(text)
