Skip to content

Commit c238306

Browse files
authored
👌 IMPROVE: Type annotate renderer's token stream immutable (#104)
1 parent 2bde191 commit c238306

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

markdown_it/renderer.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class Renderer
66
rules if you create plugin and adds new token types.
77
"""
88
import inspect
9-
from typing import List
9+
from typing import Sequence
1010

1111
from .common.utils import unescapeAll, escapeHtml
1212
from .token import Token
@@ -51,7 +51,7 @@ def __init__(self, parser=None):
5151
if not (k.startswith("render") or k.startswith("_"))
5252
}
5353

54-
def render(self, tokens: List[Token], options, env) -> str:
54+
def render(self, tokens: Sequence[Token], options, env) -> str:
5555
"""Takes token stream and generates HTML.
5656
5757
:param tokens: list on block tokens to render
@@ -73,7 +73,7 @@ def render(self, tokens: List[Token], options, env) -> str:
7373

7474
return result
7575

76-
def renderInline(self, tokens: List[Token], options, env) -> str:
76+
def renderInline(self, tokens: Sequence[Token], options, env) -> str:
7777
"""The same as ``render``, but for single token of `inline` type.
7878
7979
:param tokens: list on block tokens to render
@@ -91,7 +91,7 @@ def renderInline(self, tokens: List[Token], options, env) -> str:
9191
return result
9292

9393
def renderToken(
94-
self, tokens: List[Token], idx: int, options: dict, env: dict
94+
self, tokens: Sequence[Token], idx: int, options: dict, env: dict
9595
) -> str:
9696
"""Default token renderer.
9797
@@ -169,7 +169,7 @@ def renderAttrs(token):
169169

170170
return result
171171

172-
def renderInlineAsText(self, tokens: List[Token], options, env) -> str:
172+
def renderInlineAsText(self, tokens: Sequence[Token], options, env) -> str:
173173
"""Special kludge for image `alt` attributes to conform CommonMark spec.
174174
175175
Don't try to use it! Spec requires to show `alt` content with stripped markup,
@@ -192,7 +192,7 @@ def renderInlineAsText(self, tokens: List[Token], options, env) -> str:
192192

193193
###################################################
194194

195-
def code_inline(self, tokens, idx, options, env):
195+
def code_inline(self, tokens: Sequence[Token], idx, options, env):
196196
token = tokens[idx]
197197
return (
198198
"<code"
@@ -202,7 +202,7 @@ def code_inline(self, tokens, idx, options, env):
202202
+ "</code>"
203203
)
204204

205-
def code_block(self, tokens, idx, options, env):
205+
def code_block(self, tokens: Sequence[Token], idx, options, env):
206206
token = tokens[idx]
207207

208208
return (
@@ -213,7 +213,7 @@ def code_block(self, tokens, idx, options, env):
213213
+ "</code></pre>\n"
214214
)
215215

216-
def fence(self, tokens, idx, options, env):
216+
def fence(self, tokens: Sequence[Token], idx, options, env):
217217
token = tokens[idx]
218218
info = unescapeAll(token.info).strip() if token.info else ""
219219
langName = ""
@@ -262,7 +262,7 @@ def fence(self, tokens, idx, options, env):
262262
+ "</code></pre>\n"
263263
)
264264

265-
def image(self, tokens, idx, options, env):
265+
def image(self, tokens: Sequence[Token], idx, options, env):
266266
token = tokens[idx]
267267

268268
# "alt" attr MUST be set, even if empty. Because it's mandatory and
@@ -276,19 +276,19 @@ def image(self, tokens, idx, options, env):
276276

277277
return self.renderToken(tokens, idx, options, env)
278278

279-
def hardbreak(self, tokens, idx, options, *args):
279+
def hardbreak(self, tokens: Sequence[Token], idx, options, *args):
280280
return "<br />\n" if options.xhtmlOut else "<br>\n"
281281

282-
def softbreak(self, tokens, idx, options, *args):
282+
def softbreak(self, tokens: Sequence[Token], idx, options, *args):
283283
return (
284284
("<br />\n" if options.xhtmlOut else "<br>\n") if options.breaks else "\n"
285285
)
286286

287-
def text(self, tokens, idx, *args):
287+
def text(self, tokens: Sequence[Token], idx, *args):
288288
return escapeHtml(tokens[idx].content)
289289

290-
def html_block(self, tokens, idx, *args):
290+
def html_block(self, tokens: Sequence[Token], idx, *args):
291291
return tokens[idx].content
292292

293-
def html_inline(self, tokens, idx, *args):
293+
def html_inline(self, tokens: Sequence[Token], idx, *args):
294294
return tokens[idx].content

0 commit comments

Comments
 (0)