3333from markdown .extensions import Extension
3434from markdown .util import AtomicString
3535from mkdocs .utils import log
36+ from typing import Union
3637
3738from .handlers import CollectionError , get_handler
3839
3940
40- def atomic_brute_cast (tree : Element ) -> None :
41+ def atomic_brute_cast (tree : Element ) -> Union [ Element , None ] :
4142 """
4243 Cast every node's text into an atomic string to prevent further processing on it.
4344
@@ -91,27 +92,28 @@ def __init__(self, parser, md: Markdown, config: dict) -> None:
9192
9293 def test (self , parent : Element , block : Element ) -> bool :
9394 sibling = self .lastChild (parent )
94- bool1 = self .RE .search (block )
95+ bool1 = self .RE .search (str ( block ) )
9596 bool2 = (
96- block .startswith (" " * self .tab_length )
97+ str ( block ) .startswith (" " * self .tab_length )
9798 and sibling is not None
9899 and sibling .get ("class" , "" ).find (self .CLASSNAME ) != - 1
99100 )
100101 return bool (bool1 or bool2 )
101102
102103 def run (self , parent : Element , blocks : Element ) -> None :
103104 block = blocks .pop (0 )
104- m = self .RE .search (block )
105+ m = self .RE .search (str ( block ) )
105106
106107 if m :
107- block = block [m .end () :] # removes the first line
108+ # removes the first line
109+ block = block [m .end () :] # type: ignore
108110
109111 block , the_rest = self .detab (block )
110112
111113 if m :
112114 identifier = m .group (1 )
113115 log .debug (f"mkdocstrings.extension: Matched '::: { identifier } '" )
114- config = yaml .safe_load (block ) or {}
116+ config = yaml .safe_load (str ( block ) ) or {}
115117
116118 handler_name = self .get_handler_name (config )
117119 log .debug (f"mkdocstrings.extension: Using handler '{ handler_name } '" )
@@ -138,9 +140,11 @@ def run(self, parent: Element, blocks: Element) -> None:
138140 except ParseError as error :
139141 message = f"mkdocstrings.extension: { error } "
140142 if "mismatched tag" in str (error ):
141- lineno , columnno = str (error ).split (":" )[- 1 ].split (", " )
142- lineno = int (lineno .split (" " )[- 1 ])
143- columnno = int (columnno .split (" " )[- 1 ])
143+ line , column = str (error ).split (":" )[- 1 ].split (", " )
144+
145+ lineno = int (line .split (" " )[- 1 ])
146+ columnno = int (column .split (" " )[- 1 ])
147+
144148 line = rendered .split ("\n " )[lineno - 1 ]
145149 character = line [columnno ]
146150 message += (
@@ -151,7 +155,7 @@ def run(self, parent: Element, blocks: Element) -> None:
151155 log .error (message )
152156 return
153157
154- as_xml = atomic_brute_cast (as_xml )
158+ as_xml = atomic_brute_cast (as_xml ) # type: ignore
155159 parent .append (as_xml )
156160
157161 if the_rest :
@@ -225,6 +229,9 @@ def __init__(self, config: dict, **kwargs) -> None:
225229 kwargs: Keyword arguments used by `markdown.extensions.Extension`.
226230 """
227231 super ().__init__ (** kwargs )
232+ if config == {}:
233+ # fake init, cancel early
234+ return
228235 self ._config = config
229236
230237 def extendMarkdown (self , md : Markdown ) -> None :
0 commit comments