1
1
import re
2
- from dataclasses import dataclass
3
- from typing import Optional
4
2
5
3
from plum import dispatch
6
4
7
- from quartodoc .pandoc .inlines import Link
8
-
9
- @dataclass
10
- class InterLink (Link ):
11
- """
12
- Link with target enclosed in colons
13
-
14
- These targets of these links are interlink references
15
- that are finally resolved by the interlinks filter.
16
- """
17
- def __post_init__ (self ):
18
- self .target = f":{ self .target } :"
19
5
20
6
# utils -----------------------------------------------------------------------
21
7
@@ -44,52 +30,6 @@ def convert_rst_link_to_md(rst):
44
30
return re .sub (expr , r"[](\1)" , rst , flags = re .MULTILINE )
45
31
46
32
47
- def interlink_ref_to_link (interlink_ref : tuple [str | None , str ]) -> InterLink :
48
- """
49
- Convert an rst reference to a quoted link
50
-
51
- The interlink has been parsed into a tuple form.
52
-
53
- e.g.
54
-
55
- 1. Written as - ":meth:`class.some_method`:"
56
- Parsed value - ("class.some_method", "meth")
57
- Return value is a link with target - "`:meth:class.some_method`"
58
-
59
- 2. Written as - "class.some_method"
60
- Parsed value - ("class.some_method", None)
61
- Return value is a link with target - "`class.some_method`"
62
-
63
- This method creates a link that can be represented in
64
- markdown and that is later processed by the lua interlinks
65
- filter into its final form.
66
- """
67
- name , role = interlink_ref
68
- target = f":{ role } :{ name } :" if role else f"{ name } "
69
- return InterLink (content = name , target = target )
70
-
71
-
72
- def build_parameter (name : str , annotation : Optional [str ], default : Optional [str ]) -> str :
73
- """
74
- Create code snippet that defines a parameter
75
- """
76
- if not name and annotation :
77
- # e.g. Return values may not have a name
78
- return f"{ annotation } "
79
-
80
- if default is None :
81
- if annotation :
82
- param = f"{ name } : { annotation } "
83
- else :
84
- param = f"{ name } "
85
- else :
86
- if annotation :
87
- param = f"{ name } : { annotation } = { default } "
88
- else :
89
- param = f"{ name } ={ default } "
90
-
91
- return param
92
-
93
33
# render -----------------------------------------------------------------------
94
34
95
35
@@ -100,10 +40,8 @@ class Renderer:
100
40
def __init_subclass__ (cls , ** kwargs ):
101
41
super ().__init_subclass__ (** kwargs )
102
42
103
- # NOTE: Commented out temporarily to make it easit to reload
104
- # modules during dev
105
- # if cls.style in cls._registry:
106
- # raise KeyError(f"A builder for style {cls.style} already exists")
43
+ if cls .style in cls ._registry :
44
+ raise KeyError (f"A builder for style { cls .style } already exists" )
107
45
108
46
cls ._registry [cls .style ] = cls
109
47
0 commit comments