88from pathlib import Path
99from typing import Any
1010
11- import sphinxnotes .strike
11+ # Wait for ``sphinxnotes-strike`` to release a version with type stubs.
12+ import sphinxnotes .strike # pyright: ignore[reportMissingTypeStubs]
1213from beartype import beartype
1314from docutils import nodes
1415from docutils .nodes import NodeVisitor
16+ from docutils .parsers .rst .states import Inliner
17+ from docutils .utils import unescape
1518from sphinx .application import Sphinx
1619from sphinx .builders .text import TextBuilder
1720from sphinx .util .typing import ExtensionMetadata
1821from sphinx_toolbox .collapse import CollapseNode
1922from sphinxcontrib .video import ( # pyright: ignore[reportMissingTypeStubs]
2023 video_node ,
2124)
22- from sphinxnotes .strike import strike_node
25+
26+ # Wait for ``sphinxnotes-strike`` to release a version with type stubs.
27+ from sphinxnotes .strike import ( # pyright: ignore[reportMissingTypeStubs]
28+ strike_node ,
29+ )
2330from ultimate_notion import Emoji
2431from ultimate_notion .blocks import Block , ChildrenMixin
2532from ultimate_notion .blocks import BulletedItem as UnoBulletedItem
@@ -1128,6 +1135,31 @@ def _depart_video_node_notion(
11281135 del node
11291136
11301137
1138+ @beartype
1139+ def _override_strike_role ( # pylint: disable=too-many-positional-arguments
1140+ typ : str ,
1141+ rawtext : str ,
1142+ text : str , # pylint: disable=redefined-outer-name
1143+ lineno : int ,
1144+ inliner : Inliner ,
1145+ options : dict [Any , Any ] | None = None ,
1146+ content : list [str ] | None = None ,
1147+ ) -> tuple [list [nodes .Node ], list [nodes .system_message ]]:
1148+ """The ``sphinxnotes-strike`` extension's ``strike_role`` is overridden to
1149+ process strike nodes into Notion blocks.
1150+
1151+ This will not be needed after ``sphinxnotes-strike`` 1.3 is released.
1152+ """
1153+ del typ
1154+ del lineno
1155+ del options
1156+ del content
1157+ env = inliner .document .settings .env
1158+ node = strike_node (rawtext , unescape (text = text ))
1159+ node ["docname" ] = env .docname
1160+ return [node ], []
1161+
1162+
11311163@beartype
11321164def setup (app : Sphinx ) -> ExtensionMetadata :
11331165 """
@@ -1141,5 +1173,10 @@ def setup(app: Sphinx) -> ExtensionMetadata:
11411173 notion = (_visit_video_node_notion , _depart_video_node_notion ),
11421174 override = True ,
11431175 )
1144- sphinxnotes .strike .SUPPORTED_BUILDERS .append (NotionBuilder )
1176+
1177+ # After ``sphinxnotes-strike`` is updated to have a ``SUPPORTED_BUILDERS``
1178+ # attribute, we can remove this and use the default ``strike_role``,
1179+ # and append ``NotionBuilder`` to ``SUPPORTED_BUILDERS``.
1180+ sphinxnotes .strike .strike_role = _override_strike_role
1181+ assert sphinxnotes .strike .strike_role is not None
11451182 return {"parallel_read_safe" : True }
0 commit comments