From 4044f351b691941e000448a375cd4350412b11a2 Mon Sep 17 00:00:00 2001 From: snowykami Date: Sat, 31 Aug 2024 08:58:20 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E6=96=B0=E5=A2=9E=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E8=A3=85=E9=A5=B0=E5=99=A8=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- litedoc/docstring/parser.py | 1 + litedoc/syntax/node.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/litedoc/docstring/parser.py b/litedoc/docstring/parser.py index fee7230..1e6044d 100644 --- a/litedoc/docstring/parser.py +++ b/litedoc/docstring/parser.py @@ -12,6 +12,7 @@ def reduction(s: str) -> str: + """还原特殊字符""" for k, v in placeholder.items(): s = s.replace(k, v) return s diff --git a/litedoc/syntax/node.py b/litedoc/syntax/node.py index b4384ce..31ca7bc 100644 --- a/litedoc/syntax/node.py +++ b/litedoc/syntax/node.py @@ -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}*** "