-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
313 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
h1, h2, h3 { | ||
margin-bottom: 10px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Release Notes | ||
|
||
## Version 1.0.0 (2020-06-16) | ||
|
||
### Additions to Version 1.0.0 | ||
|
||
* Add support for NumPy docstring style ([#1](https://github.com/daizutabi/mkapi/issues/1)). | ||
* Document only a specifc method from a class ([#5](https://github.com/daizutabi/mkapi/issues/5)). | ||
* Add support for magic/dunder methods ([#7](https://github.com/daizutabi/mkapi/issues/7)). | ||
* Include methods defined in different file ([#9](https://github.com/daizutabi/mkapi/issues/9)). | ||
* Display inheritance of class ([#10](https://github.com/daizutabi/mkapi/issues/10)). | ||
* Add `on_config` option to allow users to run custom script ([#11](https://github.com/daizutabi/mkapi/issues/11)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from dataclasses import dataclass | ||
|
||
from mkapi.core.base import Type | ||
|
||
|
||
@dataclass | ||
class Base: | ||
"""Base class.""" | ||
|
||
name: str #: Object name. | ||
type: Type #: Object type. | ||
|
||
def set_name(self, name: str): | ||
"""Sets name. | ||
Args: | ||
name: A New name. | ||
""" | ||
self.name = name | ||
|
||
|
||
@dataclass | ||
class Item(Base): | ||
"""Item class.""" | ||
|
||
markdown: str #: Object Markdown. | ||
|
||
def set_name(self, name: str): | ||
"""Sets name in upper case.""" | ||
self.name = name.upper() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import re | ||
from dataclasses import dataclass, field | ||
from typing import List | ||
|
||
import markdown | ||
|
||
from mkapi.core.base import Base | ||
from mkapi.core.module import Module, get_module | ||
|
||
|
||
@dataclass(repr=False) | ||
class Block(Base): | ||
def __post_init__(self): | ||
self.markdown = f"~~~python\n{self.markdown}\n~~~\n" | ||
|
||
def __iter__(self): | ||
yield | ||
|
||
|
||
@dataclass | ||
class Code: | ||
module: Module | ||
markdown: str = field(default="", init=False) | ||
html: str = field(default="", init=False) | ||
level: int = field(default=1, init=False) | ||
|
||
def __post_init__(self): | ||
sourcefile = self.module.sourcefile | ||
with open(sourcefile, "r") as f: | ||
source = f.read() | ||
if not source: | ||
return | ||
|
||
nodes = [] | ||
linenos = [] | ||
for node in self.module.node.walk(): | ||
if node.sourcefile == sourcefile: | ||
if node.lineno > 0 and node.lineno not in linenos: | ||
nodes.append(node) | ||
linenos.append(node.lineno) | ||
module_id = self.module.object.id | ||
i = 0 | ||
lines = [] | ||
for k, line in enumerate(source.split("\n")): | ||
if i < len(linenos) and k == linenos[i]: | ||
object_id = nodes[i].object.id | ||
lines.append(f" # __mkapi__:{module_id}:{object_id}") | ||
i += 1 | ||
lines.append(" " + line) | ||
source = "\n".join(lines) | ||
self.markdown = f" :::python\n{source}\n" | ||
html = markdown.markdown(self.markdown, extensions=["codehilite"]) | ||
self.html = replace(html) | ||
|
||
def __repr__(self): | ||
class_name = self.__class__.__name__ | ||
return f"{class_name}({self.module.object.id!r}, num_objects={len(self.nodes)})" | ||
|
||
def get_markdown(self, level: int = 1) -> str: | ||
"""Returns a Markdown source for docstring of this object.""" | ||
self.level = level | ||
return f"# {self.module.object.id}" | ||
|
||
def set_html(self, html: str): | ||
pass | ||
|
||
def get_html(self, filters: List[str] = None) -> str: | ||
"""Renders and returns HTML.""" | ||
from mkapi.core.renderer import renderer | ||
|
||
return renderer.render_code(self, filters) # type:ignore | ||
|
||
|
||
COMMENT_PATTERN = re.compile(r'\n<span class="c1"># __mkapi__:(.*?):(.*?)</span>') | ||
|
||
|
||
def replace(html): | ||
def func(match): | ||
module, object = match.groups() | ||
link = f'<span id="{object}"></span>' | ||
link += f'<a class="mkapi-docs-link"' | ||
link += f'href="../../{module}#{object}">DOCS</a>' | ||
return link | ||
|
||
return COMMENT_PATTERN.sub(func, html) | ||
|
||
|
||
def get_code(name: str) -> Code: | ||
module = get_module(name) | ||
return Code(module) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.