Skip to content

Commit 056fc94

Browse files
Merge pull request #91 from adamtheturtle/admonition-colours
Give admonitions background colours
2 parents ce49258 + 2b47cfb commit 056fc94

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

β€Žsrc/sphinx_notion/__init__.pyβ€Ž

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
)
4343
from ultimate_notion.core import NotionObject
4444
from ultimate_notion.obj_api.core import GenericObject
45-
from ultimate_notion.obj_api.enums import CodeLang, Color
45+
from ultimate_notion.obj_api.enums import BGColor, CodeLang
4646
from ultimate_notion.rich_text import Text, text
4747

4848

@@ -321,14 +321,16 @@ def _create_admonition_callout(
321321
node: nodes.Element,
322322
*,
323323
emoji: str,
324-
color: Color,
324+
background_color: BGColor,
325325
) -> list[NotionObject[Any]]:
326326
"""Create a Notion Callout block for admonition nodes.
327327
328328
The first child (typically a paragraph) becomes the callout text,
329329
and any remaining children become nested blocks within the callout.
330330
"""
331-
block = UnoCallout(text="", icon=Emoji(emoji=emoji), color=color)
331+
block = UnoCallout(
332+
text="", icon=Emoji(emoji=emoji), color=background_color
333+
)
332334

333335
# Use the first child as the callout text
334336
first_child = node.children[0]
@@ -365,7 +367,11 @@ def _(node: nodes.note, *, section_level: int) -> list[NotionObject[Any]]:
365367
Process note admonition nodes by creating Notion Callout blocks.
366368
"""
367369
del section_level
368-
return _create_admonition_callout(node=node, emoji="πŸ“", color=Color.BLUE)
370+
return _create_admonition_callout(
371+
node=node,
372+
emoji="πŸ“",
373+
background_color=BGColor.BLUE,
374+
)
369375

370376

371377
@_process_node_to_blocks.register
@@ -374,7 +380,11 @@ def _(node: nodes.warning, *, section_level: int) -> list[NotionObject[Any]]:
374380
Process warning admonition nodes by creating Notion Callout blocks.
375381
"""
376382
del section_level
377-
return _create_admonition_callout(node=node, emoji="⚠️", color=Color.YELLOW)
383+
return _create_admonition_callout(
384+
node=node,
385+
emoji="⚠️",
386+
background_color=BGColor.YELLOW,
387+
)
378388

379389

380390
@_process_node_to_blocks.register
@@ -383,7 +393,11 @@ def _(node: nodes.tip, *, section_level: int) -> list[NotionObject[Any]]:
383393
Process tip admonition nodes by creating Notion Callout blocks.
384394
"""
385395
del section_level
386-
return _create_admonition_callout(node=node, emoji="πŸ’‘", color=Color.GREEN)
396+
return _create_admonition_callout(
397+
node=node,
398+
emoji="πŸ’‘",
399+
background_color=BGColor.GREEN,
400+
)
387401

388402

389403
@_process_node_to_blocks.register

β€Žtests/test_integration.pyβ€Ž

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
)
3939
from ultimate_notion.core import NotionObject
4040
from ultimate_notion.obj_api.core import GenericObject
41-
from ultimate_notion.obj_api.enums import CodeLang, Color
41+
from ultimate_notion.obj_api.enums import BGColor, CodeLang
4242
from ultimate_notion.rich_text import text
4343

4444

@@ -741,18 +741,18 @@ def test_bullet_list_with_inline_formatting(
741741

742742

743743
@pytest.mark.parametrize(
744-
argnames=("admonition_type", "emoji", "color", "message"),
744+
argnames=("admonition_type", "emoji", "background_color", "message"),
745745
argvalues=[
746-
("note", "πŸ“", Color.BLUE, "This is an important note."),
747-
("warning", "⚠️", Color.YELLOW, "This is a warning message."),
748-
("tip", "πŸ’‘", Color.GREEN, "This is a helpful tip."),
746+
("note", "πŸ“", BGColor.BLUE, "This is an important note."),
747+
("warning", "⚠️", BGColor.YELLOW, "This is a warning message."),
748+
("tip", "πŸ’‘", BGColor.GREEN, "This is a helpful tip."),
749749
],
750750
)
751751
def test_admonition_single_line(
752752
*,
753753
admonition_type: str,
754754
emoji: str,
755-
color: Color,
755+
background_color: BGColor,
756756
message: str,
757757
make_app: Callable[..., SphinxTestApp],
758758
tmp_path: Path,
@@ -771,7 +771,7 @@ def test_admonition_single_line(
771771
callout = UnoCallout(
772772
text=message,
773773
icon=Emoji(emoji=emoji),
774-
color=color,
774+
color=background_color,
775775
)
776776

777777
expected_objects: list[NotionObject[Any]] = [
@@ -788,17 +788,17 @@ def test_admonition_single_line(
788788

789789

790790
@pytest.mark.parametrize(
791-
argnames=("admonition_type", "emoji", "color"),
791+
argnames=("admonition_type", "emoji", "background_color"),
792792
argvalues=[
793-
("note", "πŸ“", Color.BLUE),
794-
("warning", "⚠️", Color.YELLOW),
795-
("tip", "πŸ’‘", Color.GREEN),
793+
("note", "πŸ“", BGColor.BLUE),
794+
("warning", "⚠️", BGColor.YELLOW),
795+
("tip", "πŸ’‘", BGColor.GREEN),
796796
],
797797
)
798798
def test_admonition_multiline(
799799
admonition_type: str,
800800
emoji: str,
801-
color: Color,
801+
background_color: BGColor,
802802
make_app: Callable[..., SphinxTestApp],
803803
tmp_path: Path,
804804
) -> None:
@@ -813,7 +813,11 @@ def test_admonition_multiline(
813813
814814
This is the second paragraph that should be nested.
815815
"""
816-
callout = UnoCallout(text="", icon=Emoji(emoji=emoji), color=color)
816+
callout = UnoCallout(
817+
text="",
818+
icon=Emoji(emoji=emoji),
819+
color=background_color,
820+
)
817821
callout.rich_text = text(
818822
text=f"This is the first paragraph of the {admonition_type}."
819823
)
@@ -854,7 +858,7 @@ def hello():
854858
The code above demonstrates a simple function.
855859
"""
856860

857-
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=Color.BLUE)
861+
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=BGColor.BLUE)
858862
callout.rich_text = text(text="This note contains a code example.")
859863

860864
nested_code_block = _create_code_block_without_annotations(
@@ -898,7 +902,7 @@ def hello():
898902
This paragraph comes after the code block.
899903
"""
900904

901-
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=Color.BLUE)
905+
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=BGColor.BLUE)
902906
callout.rich_text = text(text="")
903907

904908
nested_code_block = _create_code_block_without_annotations(
@@ -938,7 +942,7 @@ def test_admonition_with_bullet_points(
938942
* B
939943
"""
940944

941-
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=Color.BLUE)
945+
callout = UnoCallout(text="", icon=Emoji(emoji="πŸ“"), color=BGColor.BLUE)
942946
callout.rich_text = text(
943947
text="This is an important note that demonstrates the note "
944948
"admonition\nsupport."

0 commit comments

Comments
Β (0)