Skip to content

Commit

Permalink
✨ 新增特殊装饰器提示
Browse files Browse the repository at this point in the history
  • Loading branch information
snowykami committed Aug 31, 2024
1 parent 50655bf commit 4044f35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions litedoc/docstring/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@


def reduction(s: str) -> str:
"""还原特殊字符"""
for k, v in placeholder.items():
s = s.replace(k, v)
return s
Expand Down
12 changes: 11 additions & 1 deletion litedoc/syntax/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,19 @@ def markdown(self, lang: str, indent: int = 0, **kwargs) -> str:

md = ""
# 装饰器部分
# 特殊装饰器
special_decorators = {
"classmethod": "https://docs.python.org/3/library/functions.html#classmethod",
"staticmethod": "https://docs.python.org/3/library/functions.html#staticmethod",
"property": "https://docs.python.org/3/library/functions.html#property",
"abstractmethod": "https://docs.python.org/3/library/abc.html#abc.abstractmethod",
}
if len(self.decorators) > 0:
for decorator in self.decorators:
md += PREFIX + f"`@{decorator}`\n"
if decorator in special_decorators:
md += PREFIX + f"@[`{decorator}`]({special_decorators[decorator]})\n"
else:
md += PREFIX + f"`@{decorator}`\n"

if self.is_async:
md += PREFIX + f"{h} ***async {func_type}*** "
Expand Down

0 comments on commit 4044f35

Please sign in to comment.