Skip to content

Commit 12350c0

Browse files
committed
Make definition lists handle multiple definitions
1 parent 2820efe commit 12350c0

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

quartodoc/pandoc/blocks.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def html(self):
6060
# TypeAlias declared here to avoid forward-references which
6161
# break beartype
6262
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+
]
6467

6568

6669
@dataclass
@@ -97,12 +100,16 @@ def __str__(self):
97100
return Div_TPL.format(content=content, attr=attr)
98101

99102

100-
# Description starts on the 4th column, and subsequent lines will be
103+
# Definition starts on the 4th column, and subsequent lines will be
101104
# 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.
103106
DefinitionItem_TPL = """\
104107
{term}
105-
: {description}
108+
{definitions}
109+
"""
110+
111+
Definition_TPL = """
112+
: {definition}
106113
"""
107114

108115

@@ -121,18 +128,26 @@ def __str__(self):
121128
if not self.content:
122129
return ""
123130

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()))
129147

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)))
134149

135-
return join_block_content(lst)
150+
return join_block_content(items)
136151

137152

138153
@dataclass

0 commit comments

Comments
 (0)