better markdown
This commit is contained in:
parent
82c1bcb269
commit
b61c8fcb68
@ -12,6 +12,9 @@ class Func:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}{self.signature}\n\t{self.desc}"
|
return f"{self.name}{self.signature}\n\t{self.desc}"
|
||||||
|
|
||||||
|
def as_markdown(self):
|
||||||
|
return f"### {self.name}\n\n```python\n{self.name}{self.signature}\n```\n\n{self.desc}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
return "F"
|
return "F"
|
||||||
@ -26,6 +29,9 @@ class Class:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name}{self.signature}\n\t{self.desc}"
|
return f"{self.name}{self.signature}\n\t{self.desc}"
|
||||||
|
|
||||||
|
def as_markdown(self):
|
||||||
|
return f"### {self.name}\n\n{self.desc}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
return "C"
|
return "C"
|
||||||
@ -41,6 +47,9 @@ class Datum:
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name} = {self.value} ({self.type_name})\n\t{self.desc}"
|
return f"{self.name} = {self.value} ({self.type_name})\n\t{self.desc}"
|
||||||
|
|
||||||
|
def as_markdown(self):
|
||||||
|
return f"### {self.name}\n{self.value} ({self.type_name})\n\n{self.desc}"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
return "G"
|
return "G"
|
||||||
@ -54,6 +63,9 @@ class Mod:
|
|||||||
classes: list[Class] = field(default_factory=list)
|
classes: list[Class] = field(default_factory=list)
|
||||||
data: list[Datum] = field(default_factory=list)
|
data: list[Datum] = field(default_factory=list)
|
||||||
|
|
||||||
|
def as_markdown(self):
|
||||||
|
return f"# {self.name}\n{self.desc}\n\n## Functions\n\n"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def icon(self):
|
def icon(self):
|
||||||
return "M"
|
return "M"
|
||||||
@ -79,11 +91,13 @@ def parse_module(mod):
|
|||||||
info = Mod(mod.__name__, mod.__doc__)
|
info = Mod(mod.__name__, mod.__doc__)
|
||||||
|
|
||||||
for name, member in inspect.getmembers(mod):
|
for name, member in inspect.getmembers(mod):
|
||||||
|
if name.startswith("_"):
|
||||||
|
continue
|
||||||
if inspect.isclass(member):
|
if inspect.isclass(member):
|
||||||
info.classes.append(parse_class(member))
|
info.classes.append(parse_class(member))
|
||||||
elif inspect.isroutine(member):
|
elif inspect.isroutine(member):
|
||||||
info.functions.append(parse_function(member))
|
info.functions.append(parse_function(member))
|
||||||
elif not name.startswith("__"):
|
else:
|
||||||
info.data.append(Datum(name, member.__doc__, member, type(member).__name__))
|
info.data.append(Datum(name, member.__doc__, member, type(member).__name__))
|
||||||
|
|
||||||
return info
|
return info
|
||||||
|
@ -1,24 +1,14 @@
|
|||||||
import importlib
|
import importlib
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.reactive import reactive
|
|
||||||
from textual.widgets import (
|
from textual.widgets import (
|
||||||
Static,
|
|
||||||
Header,
|
Header,
|
||||||
ListView,
|
ListView,
|
||||||
ListItem,
|
ListItem,
|
||||||
Label,
|
Label,
|
||||||
MarkdownViewer,
|
|
||||||
Markdown,
|
Markdown,
|
||||||
)
|
)
|
||||||
from .parse_mod import parse_module
|
from .parse_mod import parse_module
|
||||||
|
|
||||||
TEXT = """\
|
|
||||||
Docking a widget removes it from the layout and fixes its position, aligned to either the top, right, bottom, or left edges of a container.
|
|
||||||
|
|
||||||
Docked widgets will not scroll out of view, making them ideal for sticky headers, footers, and sidebars.
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class MemberListView(ListView):
|
class MemberListView(ListView):
|
||||||
def __init__(self, mod_list):
|
def __init__(self, mod_list):
|
||||||
@ -62,7 +52,9 @@ class WudTui(App):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
_mod = importlib.import_module(modname)
|
_mod = importlib.import_module(modname)
|
||||||
self.mod = parse_module(_mod)
|
self.mod = parse_module(_mod)
|
||||||
self.mod_list = [self.mod] + self.mod.functions + self.mod.data
|
self.mod_list = (
|
||||||
|
[self.mod] + self.mod.functions + self.mod.classes + self.mod.data
|
||||||
|
)
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Header()
|
||||||
@ -76,7 +68,7 @@ class WudTui(App):
|
|||||||
def on_list_view_highlighted(self, _):
|
def on_list_view_highlighted(self, _):
|
||||||
lv = self.query_one("#sidebar", MemberListView)
|
lv = self.query_one("#sidebar", MemberListView)
|
||||||
md = self.query_one("#docview", Markdown)
|
md = self.query_one("#docview", Markdown)
|
||||||
md.update(markdown=f"{self.mod_list[lv.index]}")
|
md.update(markdown=f"{self.mod_list[lv.index].as_markdown()}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user