@@ -60,7 +60,10 @@ def html(self):
60
60
# TypeAlias declared here to avoid forward-references which
61
61
# break beartype
62
62
BlockContent : TypeAlias = InlineContent | Block | Sequence [Block ]
63
- DefinitionItem : TypeAlias = tuple [InlineContent , BlockContent ]
63
+ ContentItem : TypeAlias = str | Inline | Block
64
+ DefinitionItem : TypeAlias = tuple [
65
+ InlineContent , ContentItem | Sequence [BlockContent ]
66
+ ]
64
67
65
68
66
69
@dataclass
@@ -97,12 +100,16 @@ def __str__(self):
97
100
return Div_TPL .format (content = content , attr = attr )
98
101
99
102
100
- # Description starts on the 4th column, and subsequent lines will be
103
+ # Definition starts on the 4th column, and subsequent lines will be
101
104
# indented with 4 spaces. This is crucial for proper handling of
102
- # descriptions with more than one block.
105
+ # definition with more than one block.
103
106
DefinitionItem_TPL = """\
104
107
{term}
105
- : {description}
108
+ {definitions}
109
+ """
110
+
111
+ Definition_TPL = """
112
+ : {definition}
106
113
"""
107
114
108
115
@@ -121,18 +128,26 @@ def __str__(self):
121
128
if not self .content :
122
129
return ""
123
130
124
- lst = []
125
- fmt = DefinitionItem_TPL .format
126
- for term , description in self .content :
127
- term = inlinecontent_to_str (term )
128
- description = blockcontent_to_str (description )
131
+ tfmt = DefinitionItem_TPL .format
132
+ dfmt = Definition_TPL .format
133
+ items = []
134
+ for term , definitions in self .content :
135
+ term , defs = inlinecontent_to_str (term ), []
136
+
137
+ # Single Definition
138
+ if isinstance (definitions , (str , Inline , Block )):
139
+ definitions = [definitions ]
140
+
141
+ # Multiple defnitions
142
+ for definition in definitions :
143
+ s = blockcontent_to_str (definition )
144
+ # strip away the indentation on the first line as it
145
+ # is handled by the template
146
+ defs .append (dfmt (definition = indent (s , INDENT ).strip ()))
129
147
130
- # strip away the indentation on the first line as it
131
- # is handled by the template
132
- desc = indent (str (description ).strip (), INDENT ).strip ()
133
- lst .append (fmt (term = term , description = desc ))
148
+ items .append (tfmt (term = term , definitions = "" .join (defs )))
134
149
135
- return join_block_content (lst )
150
+ return join_block_content (items )
136
151
137
152
138
153
@dataclass
0 commit comments