Skip to content

Commit 4c91ff4

Browse files
Merge pull request #147 from adamtheturtle/prepare-text
Set rich text in a cleaner way and consistently in tests
2 parents 6d2bda6 + f9a95a1 commit 4c91ff4

File tree

2 files changed

+119
-112
lines changed

2 files changed

+119
-112
lines changed

src/sphinx_notion/__init__.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,7 @@ def _process_list_item_recursively(
308308
paragraph = node.children[0]
309309
assert isinstance(paragraph, nodes.paragraph)
310310
rich_text = _create_rich_text_from_children(node=paragraph)
311-
block = UnoBulletedItem(text="placeholder")
312-
block.rich_text = rich_text
311+
block = UnoBulletedItem(text=rich_text)
313312
self._add_block_to_tree(
314313
block=block,
315314
parent_path=parent_path,
@@ -402,8 +401,7 @@ def _(
402401
"""
403402
del section_level
404403
rich_text = _create_rich_text_from_children(node=node)
405-
paragraph_block = UnoParagraph(text="")
406-
paragraph_block.rich_text = rich_text
404+
paragraph_block = UnoParagraph(text=rich_text)
407405
self._add_block_to_tree(block=paragraph_block, parent_path=parent_path)
408406

409407
@_process_node_to_blocks.register
@@ -419,8 +417,7 @@ def _(
419417
"""
420418
del section_level
421419
rich_text = _create_rich_text_from_children(node=node)
422-
quote_block = UnoQuote(text="")
423-
quote_block.rich_text = rich_text
420+
quote_block = UnoQuote(text=rich_text)
424421
self._add_block_to_tree(block=quote_block, parent_path=parent_path)
425422

426423
@_process_node_to_blocks.register
@@ -527,9 +524,7 @@ def _(
527524
3: UnoHeading3,
528525
}
529526
heading_cls = heading_levels[section_level]
530-
block = heading_cls(text="")
531-
532-
block.rich_text = rich_text
527+
block = heading_cls(text=rich_text)
533528
self._add_block_to_tree(block=block, parent_path=parent_path)
534529

535530
@beartype
@@ -547,24 +542,25 @@ def _create_admonition_callout(
547542
text, and any remaining children become nested blocks within the
548543
callout.
549544
"""
550-
block = UnoCallout(
551-
text="", icon=Emoji(emoji=emoji), color=background_color
552-
)
553-
554-
self._add_block_to_tree(block=block, parent_path=parent_path)
555545
# Use the first child as the callout text
556546
first_child = node.children[0]
557547
if isinstance(first_child, nodes.paragraph):
558548
rich_text = _create_rich_text_from_children(node=first_child)
559-
block.rich_text = rich_text
560549
# Process remaining children as nested blocks
561550
children_to_process = node.children[1:]
562551
else:
563552
# If first child is not a paragraph, use empty text
564-
block.rich_text = Text.from_plain_text(text="")
553+
rich_text = Text.from_plain_text(text="")
565554
# Process all children as nested blocks (including the first)
566555
children_to_process = node.children
567556

557+
block = UnoCallout(
558+
text=rich_text,
559+
icon=Emoji(emoji=emoji),
560+
color=background_color,
561+
)
562+
563+
self._add_block_to_tree(block=block, parent_path=parent_path)
568564
# Process children as nested blocks
569565
for child in children_to_process:
570566
self._process_node_to_blocks(
@@ -644,7 +640,7 @@ def _(
644640
del section_level
645641

646642
title_text = node.attributes["label"]
647-
toggle_block = UnoToggleItem(text=title_text)
643+
toggle_block = UnoToggleItem(text=text(text=title_text))
648644
self._add_block_to_tree(block=toggle_block, parent_path=parent_path)
649645

650646
for child in node.children:

0 commit comments

Comments
 (0)