Skip to content

Commit b1cbf2d

Browse files
committed
feat: Support link inline tags and cross-references
Issue-mkdocstrings/typescript#5: mkdocstrings/typescript#5
1 parent 78bd842 commit b1cbf2d

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

src/griffe_typedoc/dataclasses.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def from_int(cls, value: int):
6161
0x100000: cls.SET_SIGNATURE,
6262
0x200000: cls.TYPE_ALIAS,
6363
0x400000: cls.REFERENCE,
64-
}.get(value)
64+
}[value]
6565

6666
def to_int(self):
6767
return {
@@ -88,11 +88,10 @@ def to_int(self):
8888
self.SET_SIGNATURE: 0x100000,
8989
self.TYPE_ALIAS: 0x200000,
9090
self.REFERENCE: 0x400000,
91-
}.get(self)
91+
}[self]
9292

9393

9494
# https://typedoc.org/guides/tags/
95-
# We might need to extract {@tags} as "inline tags".
9695
class BlockTagKind(Enum):
9796
ALPHA: str = "@alpha"
9897
BETA: str = "@beta"
@@ -107,11 +106,8 @@ class BlockTagKind(Enum):
107106
GROUP: str = "@group"
108107
HIDDEN: str = "@hidden"
109108
IGNORE: str = "@ignore"
110-
INHERIT_DOC: str = "{@inheritDoc}"
111109
INTERFACE: str = "@interface"
112110
INTERNAL: str = "@internal"
113-
LABEL: str = "{@label}"
114-
LINK: str = "{@link}"
115111
MODULE: str = "@module"
116112
NAMESPACE: str = "@namespace"
117113
OVERLOAD: str = "@overload"
@@ -138,6 +134,8 @@ class BlockTagKind(Enum):
138134
class BlockTagContentKind(Enum):
139135
TEXT: str = "text"
140136
CODE: str = "code"
137+
INLINE_TAG = "inline-tag"
138+
141139

142140

143141
@dataclass(kw_only=True)
@@ -150,13 +148,18 @@ class FileRegistry:
150148
class BlockTagContent:
151149
kind: BlockTagContentKind
152150
text: str
151+
target: int | str | None = None
152+
ts_link_text: str | None = None
153153

154154
def __str__(self) -> str:
155-
return self.text
155+
return self.markdown()
156156

157-
@property
158-
def markdown(self) -> str:
159-
return str(self)
157+
def markdown(self, symbol_map: dict[int, Reflection] | None = None) -> str:
158+
if self.target:
159+
if isinstance(self.target, int) and symbol_map:
160+
return f'<autoref identifier="{symbol_map[self.target].path}">{self.text}</autoref>'
161+
return f"[{self.text}]({self.target})"
162+
return self.text
160163

161164

162165
@dataclass(kw_only=True)
@@ -167,9 +170,8 @@ class BlockTag:
167170
def __str__(self) -> str:
168171
return "".join(str(block) for block in self.content)
169172

170-
@property
171-
def markdown(self) -> str:
172-
return str(self)
173+
def markdown(self, **kwargs) -> str:
174+
return "".join(block.markdown(**kwargs) for block in self.summary)
173175

174176

175177
@dataclass(kw_only=True)
@@ -181,9 +183,8 @@ class Comment:
181183
def __str__(self) -> str:
182184
return "".join(str(block) for block in self.summary)
183185

184-
@property
185-
def markdown(self) -> str:
186-
return str(self)
186+
def markdown(self, **kwargs) -> str:
187+
return "".join(block.markdown(**kwargs) for block in self.summary)
187188

188189

189190
@dataclass(kw_only=True)

src/griffe_typedoc/decoder.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,12 @@ def _load_block_tag_content_code(obj_dict: dict) -> BlockTagContent:
404404
return BlockTagContent(kind=BlockTagContentKind.CODE, text=obj_dict["text"])
405405

406406

407+
@_loader
408+
def _load_block_tag_content_inline_tag(obj_dict: dict) -> BlockTagContent:
409+
obj_dict.pop("tag")
410+
return BlockTagContent(kind=BlockTagContentKind.INLINE_TAG, **obj_dict)
411+
412+
407413
@_loader
408414
def _load_comment(obj_dict: dict) -> Comment:
409415
return Comment(**obj_dict)
@@ -472,11 +478,8 @@ def _load_group(obj_dict: dict) -> Group:
472478
BlockTagKind.GROUP: _load_block_tag_group,
473479
BlockTagKind.HIDDEN: _load_block_tag_hidden,
474480
BlockTagKind.IGNORE: _load_block_tag_ignore,
475-
BlockTagKind.INHERIT_DOC: _load_block_tag_inherit_doc,
476481
BlockTagKind.INTERFACE: _load_block_tag_interface,
477482
BlockTagKind.INTERNAL: _load_block_tag_internal,
478-
BlockTagKind.LABEL: _load_block_tag_label,
479-
BlockTagKind.LINK: _load_block_tag_link,
480483
BlockTagKind.MODULE: _load_block_tag_module,
481484
BlockTagKind.NAMESPACE: _load_block_tag_namespace,
482485
BlockTagKind.OVERLOAD: _load_block_tag_overload,
@@ -500,6 +503,7 @@ def _load_group(obj_dict: dict) -> Group:
500503
BlockTagKind.VIRTUAL: _load_block_tag_virtual,
501504
BlockTagContentKind.TEXT: _load_block_tag_content_text,
502505
BlockTagContentKind.CODE: _load_block_tag_content_code,
506+
BlockTagContentKind.INLINE_TAG: _load_block_tag_content_inline_tag,
503507
}
504508

505509

0 commit comments

Comments
 (0)