Skip to content

Commit 1c29f80

Browse files
Merge pull request #237 from adamtheturtle/more-admonitions
Support all non-generic admonition types
2 parents cd5de51 + 2ef31f3 commit 1c29f80

File tree

4 files changed

+205
-1
lines changed

4 files changed

+205
-1
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ The following syntax is supported:
8080
- Code blocks
8181
- Table of contents
8282
- Block quotes
83-
- Note, warning, and tip admonitions
83+
- All standard admonitions (note, warning, tip, attention, caution, danger, error, hint, important)
8484
- Collapsible sections (using sphinx-toolbox collapse directive)
8585
- Images (with URLs or local paths)
8686
- Videos (with URLs or local paths)

sample/index.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,30 @@ This text has :strike:`strike` formatting and :del:`deleted text` as well.
7979

8080
This is a helpful tip that demonstrates the tip admonition support.
8181

82+
.. attention::
83+
84+
This is an attention admonition that requires your attention.
85+
86+
.. caution::
87+
88+
This is a caution admonition that warns about potential issues.
89+
90+
.. danger::
91+
92+
This is a danger admonition that indicates a dangerous situation.
93+
94+
.. error::
95+
96+
This is an error admonition that shows error information.
97+
98+
.. hint::
99+
100+
This is a hint admonition that provides helpful hints.
101+
102+
.. important::
103+
104+
This is an important admonition that highlights important information.
105+
82106
.. collapse:: Click to expand this section
83107

84108
This content is hidden by default and can be expanded by clicking the toggle.

src/sphinx_notion/__init__.py

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,108 @@ def _(
739739
)
740740

741741

742+
@_process_node_to_blocks.register
743+
def _(
744+
node: nodes.attention,
745+
*,
746+
section_level: int,
747+
) -> list[Block]:
748+
"""
749+
Process attention admonition nodes by creating Notion Callout blocks.
750+
"""
751+
del section_level
752+
return _create_admonition_callout(
753+
node=node,
754+
emoji="👀",
755+
background_color=BGColor.YELLOW,
756+
)
757+
758+
759+
@_process_node_to_blocks.register
760+
def _(
761+
node: nodes.caution,
762+
*,
763+
section_level: int,
764+
) -> list[Block]:
765+
"""
766+
Process caution admonition nodes by creating Notion Callout blocks.
767+
"""
768+
del section_level
769+
return _create_admonition_callout(
770+
node=node,
771+
emoji="⚠️",
772+
background_color=BGColor.YELLOW,
773+
)
774+
775+
776+
@_process_node_to_blocks.register
777+
def _(
778+
node: nodes.danger,
779+
*,
780+
section_level: int,
781+
) -> list[Block]:
782+
"""
783+
Process danger admonition nodes by creating Notion Callout blocks.
784+
"""
785+
del section_level
786+
return _create_admonition_callout(
787+
node=node,
788+
emoji="🚨",
789+
background_color=BGColor.RED,
790+
)
791+
792+
793+
@_process_node_to_blocks.register
794+
def _(
795+
node: nodes.error,
796+
*,
797+
section_level: int,
798+
) -> list[Block]:
799+
"""
800+
Process error admonition nodes by creating Notion Callout blocks.
801+
"""
802+
del section_level
803+
return _create_admonition_callout(
804+
node=node,
805+
emoji="❌",
806+
background_color=BGColor.RED,
807+
)
808+
809+
810+
@_process_node_to_blocks.register
811+
def _(
812+
node: nodes.hint,
813+
*,
814+
section_level: int,
815+
) -> list[Block]:
816+
"""
817+
Process hint admonition nodes by creating Notion Callout blocks.
818+
"""
819+
del section_level
820+
return _create_admonition_callout(
821+
node=node,
822+
emoji="💡",
823+
background_color=BGColor.GREEN,
824+
)
825+
826+
827+
@_process_node_to_blocks.register
828+
def _(
829+
node: nodes.important,
830+
*,
831+
section_level: int,
832+
) -> list[Block]:
833+
"""
834+
Process important admonition nodes by creating Notion Callout blocks.
835+
"""
836+
del section_level
837+
return _create_admonition_callout(
838+
node=node,
839+
emoji="❗",
840+
background_color=BGColor.RED,
841+
)
842+
843+
742844
@_process_node_to_blocks.register
743845
def _(
744846
node: CollapseNode,
@@ -1057,6 +1159,78 @@ def visit_tip(self, node: nodes.Element) -> None:
10571159

10581160
raise nodes.SkipNode
10591161

1162+
def visit_attention(self, node: nodes.Element) -> None:
1163+
"""
1164+
Handle attention admonition nodes by creating Notion Callout blocks.
1165+
"""
1166+
blocks = _process_node_to_blocks(
1167+
node,
1168+
section_level=self._section_level,
1169+
)
1170+
self._blocks.extend(blocks)
1171+
1172+
raise nodes.SkipNode
1173+
1174+
def visit_caution(self, node: nodes.Element) -> None:
1175+
"""
1176+
Handle caution admonition nodes by creating Notion Callout blocks.
1177+
"""
1178+
blocks = _process_node_to_blocks(
1179+
node,
1180+
section_level=self._section_level,
1181+
)
1182+
self._blocks.extend(blocks)
1183+
1184+
raise nodes.SkipNode
1185+
1186+
def visit_danger(self, node: nodes.Element) -> None:
1187+
"""
1188+
Handle danger admonition nodes by creating Notion Callout blocks.
1189+
"""
1190+
blocks = _process_node_to_blocks(
1191+
node,
1192+
section_level=self._section_level,
1193+
)
1194+
self._blocks.extend(blocks)
1195+
1196+
raise nodes.SkipNode
1197+
1198+
def visit_error(self, node: nodes.Element) -> None:
1199+
"""
1200+
Handle error admonition nodes by creating Notion Callout blocks.
1201+
"""
1202+
blocks = _process_node_to_blocks(
1203+
node,
1204+
section_level=self._section_level,
1205+
)
1206+
self._blocks.extend(blocks)
1207+
1208+
raise nodes.SkipNode
1209+
1210+
def visit_hint(self, node: nodes.Element) -> None:
1211+
"""
1212+
Handle hint admonition nodes by creating Notion Callout blocks.
1213+
"""
1214+
blocks = _process_node_to_blocks(
1215+
node,
1216+
section_level=self._section_level,
1217+
)
1218+
self._blocks.extend(blocks)
1219+
1220+
raise nodes.SkipNode
1221+
1222+
def visit_important(self, node: nodes.Element) -> None:
1223+
"""
1224+
Handle important admonition nodes by creating Notion Callout blocks.
1225+
"""
1226+
blocks = _process_node_to_blocks(
1227+
node,
1228+
section_level=self._section_level,
1229+
)
1230+
self._blocks.extend(blocks)
1231+
1232+
raise nodes.SkipNode
1233+
10601234
def visit_table(self, node: nodes.Element) -> None:
10611235
"""
10621236
Handle table nodes by creating Notion Table blocks.

tests/test_integration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,12 @@ def test_bullet_list_with_inline_formatting(
744744
("note", "📝", BGColor.BLUE, "This is an important note."),
745745
("warning", "⚠️", BGColor.YELLOW, "This is a warning message."),
746746
("tip", "💡", BGColor.GREEN, "This is a helpful tip."),
747+
("attention", "👀", BGColor.YELLOW, "This requires your attention."),
748+
("caution", "⚠️", BGColor.YELLOW, "This is a caution message."),
749+
("danger", "🚨", BGColor.RED, "This is a danger message."),
750+
("error", "❌", BGColor.RED, "This is an error message."),
751+
("hint", "💡", BGColor.GREEN, "This is a helpful hint."),
752+
("important", "❗", BGColor.RED, "This is important information."),
747753
],
748754
)
749755
def test_admonition_single_line(

0 commit comments

Comments
 (0)