Ejemplo n.º 1
0
Archivo: page.py Proyecto: Ahrak/mkapi
 def split(self, source: str) -> Iterator[str]:
     cursor = 0
     callback = self.resolve_link_from_base
     for index, match in enumerate(MKAPI_PATTERN.finditer(source)):
         start, end = match.start(), match.end()
         if cursor < start:
             markdown = source[cursor:start].strip()
             if markdown:
                 yield self.resolve_link(markdown)
         heading, name = match.groups()
         level = len(heading)
         name, filters = utils.split_filters(name)
         if "code" in filters:
             code = get_code(name)
             self.nodes.append(code)
             markdown = code.get_markdown(level)
         else:
             node = get_node(name)
             inherit(node)
             postprocess.transform(node, filters)
             self.nodes.append(node)
             markdown = node.get_markdown(level, callback=callback)
         yield node_markdown(index, markdown, filters)
         cursor = end
     if cursor < len(source):
         markdown = source[cursor:].strip()
         if markdown:
             yield self.resolve_link(markdown)
Ejemplo n.º 2
0
def test_link_from_toc():
    from examples.google_style import ExampleClass

    node = Node(ExampleClass)
    assert len(node.docstring.sections) == 4
    P.transform(node)
    assert len(node.docstring.sections) == 5
    assert "Methods" in node.docstring
    section = node.docstring['Methods']
    html = section.items[0].html
    assert '<a href="#examples.google_style.ExampleClass.message">' in html
Ejemplo n.º 3
0
def test_transform_module(module):
    node = Node(module)
    P.transform(node, ["link"])
    q = module.__name__
    section = node.docstring["Functions"]
    assert "add" in section
    item = section["add"]
    item.markdown.startswith("Returns")
    item.html.startswith(f'<a href="#{q}.add">add</a>')
    assert "gen" in section
    section = node.docstring["Classes"]
    assert "ExampleClass" in section
    assert "ExampleDataClass" in section
Ejemplo n.º 4
0
def test_transform_class(node):
    P.transform(node)
    section = node.docstring["Methods"]
    q = A.__qualname__
    for name in "fgab":
        assert name in section
        item = section[name]
        item.markdown = name * 3
        item.html.startswith(f'<a href="#{q}.{name}">{name}</a>')
    section = node.docstring["Classes"]
    assert "B" in section
    item = section["B"].markdown == "BBB"
    node = Node(A.B)
    P.transform_class(node)
Ejemplo n.º 5
0
 def split(self, source: str) -> Iterator[str]:
     cursor = 0
     callback = self.resolve_link_from_base
     index = 0
     for match in MKAPI_PATTERN.finditer(source):
         start, end = match.start(), match.end()
         if cursor < start:
             markdown = source[cursor:start].strip()
             if markdown:
                 yield self.resolve_link(markdown)
         cursor = end
         heading, name = match.groups()
         level = len(heading)
         name, filters = utils.split_filters(name)
         if not name:
             self.filters = filters
             continue
         filters = utils.update_filters(self.filters, filters)
         if "code" in filters:
             code = get_code(name)
             self.nodes.append(code)
             markdown = code.get_markdown(level)
         else:
             node = get_node(name)
             inherit(node)
             postprocess.transform(node, filters)
             self.nodes.append(node)
             markdown = node.get_markdown(level, callback=callback)
             if level:
                 self.headings.append((level, node.object.id))
         yield node_markdown(index, markdown, filters)
         index += 1
     if cursor < len(source):
         markdown = source[cursor:].strip()
         if markdown:
             yield self.resolve_link(markdown)