77 Iterable ,
88 List ,
99 Mapping ,
10+ MutableMapping ,
1011 Optional ,
1112 Union ,
1213)
1920from .parser_inline import ParserInline # noqa F401
2021from .rules_core .state_core import StateCore
2122from .renderer import RendererHTML
22- from .utils import AttrDict
23+ from .utils import OptionsDict
2324
2425try :
2526 import linkify_it
@@ -69,7 +70,6 @@ def __init__(
6970 f"options_update should be a mapping: { options_update } "
7071 "\n (Perhaps you intended this to be the renderer_cls?)"
7172 )
72- self .options = AttrDict ()
7373 self .configure (config , options_update = options_update )
7474
7575 def __repr__ (self ) -> str :
@@ -83,15 +83,15 @@ def __getitem__(self, name: str) -> Any:
8383 "renderer" : self .renderer ,
8484 }[name ]
8585
86- def set (self , options : AttrDict ) -> None :
86+ def set (self , options : MutableMapping ) -> None :
8787 """Set parser options (in the same format as in constructor).
8888 Probably, you will never need it, but you can change options after constructor call.
8989
9090 __Note:__ To achieve the best possible performance, don't modify a
9191 `markdown-it` instance options on the fly. If you need multiple configurations
9292 it's best to create multiple instances and initialize each with separate config.
9393 """
94- self .options = options
94+ self .options = OptionsDict ( options )
9595
9696 def configure (
9797 self , presets : Union [str , Mapping ], options_update : Optional [Mapping ] = None
@@ -118,8 +118,7 @@ def configure(
118118 if options_update :
119119 options = {** options , ** options_update }
120120
121- if options :
122- self .set (AttrDict (options ))
121+ self .set (options )
123122
124123 if "components" in config :
125124 for name , component in config ["components" ].items ():
@@ -238,7 +237,7 @@ def func(tokens, idx):
238237 plugin (self , * params , ** options )
239238 return self
240239
241- def parse (self , src : str , env : Optional [AttrDict ] = None ) -> List [Token ]:
240+ def parse (self , src : str , env : Optional [MutableMapping ] = None ) -> List [Token ]:
242241 """Parse the source string to a token stream
243242
244243 :param src: source string
@@ -252,16 +251,16 @@ def parse(self, src: str, env: Optional[AttrDict] = None) -> List[Token]:
252251 inject data in specific cases. Usually, you will be ok to pass `{}`,
253252 and then pass updated object to renderer.
254253 """
255- env = AttrDict () if env is None else env
256- if not isinstance (env , AttrDict ): # type: ignore
257- raise TypeError (f"Input data should be an AttrDict , not { type (env )} " )
254+ env = {} if env is None else env
255+ if not isinstance (env , MutableMapping ):
256+ raise TypeError (f"Input data should be a MutableMapping , not { type (env )} " )
258257 if not isinstance (src , str ):
259258 raise TypeError (f"Input data should be a string, not { type (src )} " )
260259 state = StateCore (src , self , env )
261260 self .core .process (state )
262261 return state .tokens
263262
264- def render (self , src : str , env : Optional [AttrDict ] = None ) -> Any :
263+ def render (self , src : str , env : Optional [MutableMapping ] = None ) -> Any :
265264 """Render markdown string into html. It does all magic for you :).
266265
267266 :param src: source string
@@ -272,11 +271,12 @@ def render(self, src: str, env: Optional[AttrDict] = None) -> Any:
272271 But you will not need it with high probability. See also comment
273272 in [[MarkdownIt.parse]].
274273 """
275- if env is None :
276- env = AttrDict ()
274+ env = {} if env is None else env
277275 return self .renderer .render (self .parse (src , env ), self .options , env )
278276
279- def parseInline (self , src : str , env : Optional [AttrDict ] = None ) -> List [Token ]:
277+ def parseInline (
278+ self , src : str , env : Optional [MutableMapping ] = None
279+ ) -> List [Token ]:
280280 """The same as [[MarkdownIt.parse]] but skip all block rules.
281281
282282 :param src: source string
@@ -286,17 +286,17 @@ def parseInline(self, src: str, env: Optional[AttrDict] = None) -> List[Token]:
286286 block tokens list with the single `inline` element, containing parsed inline
287287 tokens in `children` property. Also updates `env` object.
288288 """
289- env = AttrDict () if env is None else env
290- if not isinstance (env , AttrDict ): # type: ignore
291- raise TypeError (f"Input data should be an AttrDict , not { type (env )} " )
289+ env = {} if env is None else env
290+ if not isinstance (env , MutableMapping ):
291+ raise TypeError (f"Input data should be an MutableMapping , not { type (env )} " )
292292 if not isinstance (src , str ):
293293 raise TypeError (f"Input data should be a string, not { type (src )} " )
294294 state = StateCore (src , self , env )
295295 state .inlineMode = True
296296 self .core .process (state )
297297 return state .tokens
298298
299- def renderInline (self , src : str , env : Optional [AttrDict ] = None ) -> Any :
299+ def renderInline (self , src : str , env : Optional [MutableMapping ] = None ) -> Any :
300300 """Similar to [[MarkdownIt.render]] but for single paragraph content.
301301
302302 :param src: source string
@@ -305,7 +305,7 @@ def renderInline(self, src: str, env: Optional[AttrDict] = None) -> Any:
305305 Similar to [[MarkdownIt.render]] but for single paragraph content. Result
306306 will NOT be wrapped into `<p>` tags.
307307 """
308- env = AttrDict () if env is None else env
308+ env = {} if env is None else env
309309 return self .renderer .render (self .parseInline (src , env ), self .options , env )
310310
311311 # link methods
0 commit comments