Skip to content

Commit 5dfd097

Browse files
committed
Recursively process BlockContent
This reduces the cases were Blocks is needed.
1 parent 32f2588 commit 5dfd097

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

quartodoc/pandoc/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def join_block_content(content: Sequence[BlockContent]) -> str:
309309
"""
310310
# Ensure that there are exactly two newlines (i.e. one empty line)
311311
# between any items.
312-
return f"{SEP}{SEP}".join(str(c).rstrip(SEP) for c in content if c)
312+
return f"{SEP}{SEP}".join(blockcontent_to_str(c) for c in content if c)
313313

314314

315315
def blockcontent_to_str(content: Optional[BlockContent]) -> str:
@@ -323,7 +323,7 @@ def blockcontent_to_str(content: Optional[BlockContent]) -> str:
323323
if not content:
324324
return ""
325325
elif isinstance(content, (str, Inline, Block)):
326-
return str(content)
326+
return str(content).rstrip(SEP)
327327
elif isinstance(content, abc.Sequence):
328328
return join_block_content(content)
329329
else:

quartodoc/tests/pandoc/test_blocks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ def test_blocks():
6262
:::
6363
""".strip()
6464

65+
b = Blocks([Div("a"), Div("b"), [Div("c"), Div("d")]])
66+
assert str(b) == """
67+
::: {}
68+
a
69+
:::
70+
71+
::: {}
72+
b
73+
:::
74+
75+
::: {}
76+
c
77+
:::
78+
79+
::: {}
80+
d
81+
:::
82+
""".strip()
83+
6584

6685
def test_bulletlist():
6786
b = BulletList(["a", "b", "c"])

0 commit comments

Comments
 (0)