Skip to content

Commit

Permalink
Add source as an hyperlink html tag to the right of the function name
Browse files Browse the repository at this point in the history
  • Loading branch information
OvidiuCode committed Mar 14, 2024
1 parent ab6e17f commit 6620a1c
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/lazydocs/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,22 @@

_IGNORE_GENERATION_INSTRUCTION = "lazydocs: ignore"

_SOURCE_BADGE_TEMPLATE = '<a href="{path}"><img align="right" src="https://img.shields.io/badge/-source-cccccc?style=flat-square" /></a>'

# String templates

_SEPARATOR = """
---
"""

_FUNC_TEMPLATE = """
{section} {func_type} `{header}`
{source}
```python
{funcdef}
```
{section} {func_type} `{header}` {source}
{doc}
"""

_CLASS_TEMPLATE = """
{section} {kind} `{header}`
{source}
{section} {kind} `{header}` {source}
{doc}
{init}
{variables}
Expand All @@ -64,8 +60,7 @@
"""

_MODULE_TEMPLATE = """
{section} module `{header}`
{source}
{section} module `{header}` {source}
{doc}
{global_vars}
{functions}
Expand Down Expand Up @@ -595,7 +590,7 @@ def func2md(self, func: Callable, clsname: str = "", depth: int = 3) -> str:
markdown = _FUNC_TEMPLATE.format(
section=section,
header=header,
source=_to_source_link(path) if path else "",
source=_SOURCE_BADGE_TEMPLATE.format(path=path) if path else "",
funcdef=funcdef,
func_type=func_type,
doc=doc if doc else "*No documentation found.*",
Expand Down Expand Up @@ -712,7 +707,7 @@ def class2md(self, cls: Any, depth: int = 2) -> str:
kind=kind,
section=section,
header=header,
source=_to_source_link(path) if path else "",
source=_SOURCE_BADGE_TEMPLATE.format(path=path) if path else "",
doc=doc if doc else "",
init=init,
variables="".join(variables),
Expand Down Expand Up @@ -837,7 +832,7 @@ def module2md(self, module: types.ModuleType, depth: int = 1) -> str:
markdown = _MODULE_TEMPLATE.format(
section="#" * depth,
header=modname,
source=_to_source_link(path) if path else "",
source=_SOURCE_BADGE_TEMPLATE.format(path=path) if path else "",
doc=doc,
global_vars=variables_section,
functions="\n".join(functions) if functions else "",
Expand Down

0 comments on commit 6620a1c

Please sign in to comment.