示例#1
0
    def parameters(self):
        if 'syntax' not in self.item:
            return None

        parameters = self.item['syntax'].get('parameters')
        if parameters is None or len(parameters) == 0:
            return None

        result = 'Parameters\n'
        has_description = any(map(lambda x: 'description' in x, parameters))

        if has_description:
            result += '\n| Type | Name | Description |\n'
            result += '|---|---|---|\n'
            for param in parameters:
                result += '| %s | *%s* | %s |\n' % (
                    self.ident_str(param['type']),
                    text_to_md(param['id']),
                    newline_to_br(html_to_md(param.get('description', ' '))),
                )
        else:
            result += '\n| Type | Name |\n'
            result += '|---|---|\n'
            for param in parameters:
                result += '| %s | *%s* |\n' % (
                    self.ident_str(param['type']),
                    text_to_md(param['id']),
                )

        return result + '\n'
示例#2
0
    def item_header(self, item, header_set=None, class_view=True):
        if header_set is not None:
            if item.type in header_set:
                return None
            header_set.add(item.type)

        if class_view:
            return {
                TYPE_NAMESPACE: '# Namespace %s\n\n' % text_to_md(item.name),
                TYPE_CLASS: '# Class %s\n\n' % text_to_md(item.name),
                TYPE_STRUCT: '# Struct %s\n\n' % text_to_md(item.name),
                TYPE_INTERFACE: '# Interface %s\n\n' % text_to_md(item.name),
                TYPE_ENUM: '# Enum %s\n\n' % text_to_md(item.name),
                TYPE_CONSTRUCTOR: '## Constructors\n\n',
                TYPE_FIELD: '## **Fields**\n\n',
                TYPE_PROPERTY: '## **Properties**\n\n',
                TYPE_METHOD: '## **Methods**\n\n',
            }.get(item.type)

        return ITEM_HEADERS.get(item.type)
示例#3
0
    def namespace_index_md(self):
        markdown = '# Namespaces\n\n'

        for name in sorted(self.namespaces.keys()):
            namespace = self.namespaces[name]
            markdown += '## [%s](%s)\n\n' % (text_to_md(name),
                                             self.get_link(namespace.uid))

            summary = self.namespaces[name].summary()
            if summary is not None:
                markdown += summary
        return markdown
示例#4
0
    def ident_str(self, string, **kwargs):
        try:
            identifier = name_parser.parse(string)
            if identifier is not None:
                return self._ident_str(identifier[0], **kwargs)
        except ValueError:
            pass

        name = replace_strings(string, {
            '{': '',
            '}': '',
        })
        return text_to_md(self.get_ident_name(name, **kwargs))
示例#5
0
    def enum_md(self, items):
        enum_item = items[0]

        md_list = [
            self.item_header(enum_item),
            enum_item.summary(),
            enum_item.inheritance(),
            enum_item.inherited_members(),
            enum_item.namespace(),
            enum_item.assemblies(),
            enum_item.syntax(),
        ]

        result = ''
        idx = 1

        while idx < len(items):
            item = items[idx]
            if item.type != TYPE_FIELD:
                result += item.markdown() + '\n'
                idx += 1
                continue

            result += '| Name | Description |\n'
            result += '|---|---|\n'

            while idx < len(items):
                item = items[idx]
                if item.type != TYPE_FIELD:
                    idx -= 1
                    break

                result += '| %s | %s |\n' % (
                    text_to_md(item.name),
                    newline_to_br(
                        html_to_md(item.item.get('description', '&nbsp;'))))
                idx += 1

            result += '\n'
            idx += 1

        md_list.append(result)
        md_list.append(enum_item.remarks())

        return '\n'.join(filter(lambda x: x is not None, md_list))
示例#6
0
    def markdown(self):
        md_list = []

        if self.is_member():
            md_list.append('### %s\n' % text_to_md(self.name))

        md_list.append(self.summary())

        if self.is_page_view():
            md_list.append(self.inheritance())
            md_list.append(self.inherited_members())
            md_list.append(self.namespace())
            md_list.append(self.assemblies())

        md_list.append(self.syntax())
        md_list.append(self.parameters())
        md_list.append(self.return_())
        md_list.append(self.remarks())

        return '\n'.join(filter(lambda x: x is not None, md_list))
示例#7
0
    def _ident_str(self, ident, **kwargs):
        is_member = kwargs.get('is_member', False)
        make_links = kwargs.get('make_links', True)

        if is_member:
            member = ident[-1]
            ident = ident[:-1]

        if not make_links:
            result = name_parser.tostring(
                ident,
                prepare_sub_ident=lambda x, y: self.get_ident_name(x, **kwargs)
            )
            if is_member:
                result += '.' + self.get_ident_name(member, **kwargs)
            return result

        result = name_parser.tostring(ident, include_containers=False)
        link = self.docfx_md.get_link(result)
        if link is not None:
            result = name_parser.tostring(
                ident,
                prepare_sub_ident=lambda x, y: self.get_ident_name(x, **kwargs)
            )
            if is_member:
                member_str = self._ident_str([member], make_links=False)
                result += '.' + member_str
                link += '#' + self.escape_fragment(member_str)
            return '[%s](%s)' % (text_to_md(self.get_ident_name(result, **kwargs)), link)

        args = kwargs.copy()
        args['is_member'] = False
        result = name_parser.tostring(
            ident,
            prepare_sub_ident=lambda x, y: self._ident_str(y, **args)
        )

        if is_member:
            result += '.' + self._ident_str([member], make_links=False)

        return self.get_ident_name(result, **kwargs)
示例#8
0
    def inheritance(self):
        result = ''
        inherit_depth = 0

        inheritance = self.item.get('inheritance')
        if inheritance is not None:
            result += 'Inheritance\n'
            for inherit in inheritance:
                result += '%s- %s\n' % ('  ' * inherit_depth, self.ident_str(inherit))
                inherit_depth += 2
            result += '%s- %s\n' % ('  ' * inherit_depth, text_to_md(self.item['name']))

        derived_classes = self.item.get('derivedClasses')
        if derived_classes is not None:
            if inherit_depth != 0:
                inherit_depth += 2
            for classname in derived_classes:
                result += '%s- %s\n' % ('  ' * inherit_depth, self.ident_str(classname))
            result += '\n'

        return result if len(result) != 0 else None
示例#9
0
    def namespace_md(self, namespace):
        item = ItemMd(self, namespace['items'][0])
        result = self.item_header(item)

        references = []
        ref_str = []

        for ref in namespace['references']:
            if ref['uid'] in self.items:
                references.append(self.items[ref['uid']])
            else:
                ref_str.append(ref['uid'])

        type_headers = set()
        references.sort()

        for ref in references:
            if ref.type == TYPE_NAMESPACE:
                continue

            header = self.item_header(ref, type_headers, class_view=False)
            if header is not None:
                result += header

            link = ref.uid + '.md' if self.link_extensions else ref.uid

            result += '### [%s](%s)\n\n' % (text_to_md(
                ref.get_ident_name(ref.name)), self.sanitize_link(link))
            summary = ref.summary()
            if summary is not None:
                result += summary

        if len(ref_str) != 0:
            result += '\n---\n'

        for ref in ref_str:
            result += '### %s\n\n' % ref

        return result
示例#10
0
 def assemblies(self):
     assemblies = self.item.get('assemblies')
     if assemblies is None:
         return None
     return '**Assembly**: %s\n' % text_to_md(','.join(assemblies))