MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / fence

Method fence

markdown_it/renderer.py:261–311  ·  view source on GitHub ↗
(
        self,
        tokens: Sequence[Token],
        idx: int,
        options: OptionsDict,
        env: EnvType,
    )

Source from the content-addressed store, hash-verified

259 )
260
261 def fence(
262 self,
263 tokens: Sequence[Token],
264 idx: int,
265 options: OptionsDict,
266 env: EnvType,
267 ) -> str:
268 token = tokens[idx]
269 info = unescapeAll(token.info).strip() if token.info else ""
270 langName = ""
271 langAttrs = ""
272
273 if info:
274 arr = info.split(maxsplit=1)
275 langName = arr[0]
276 if len(arr) == 2:
277 langAttrs = arr[1]
278
279 if options.highlight:
280 highlighted = options.highlight(
281 token.content, langName, langAttrs
282 ) or escapeHtml(token.content)
283 else:
284 highlighted = escapeHtml(token.content)
285
286 if highlighted.startswith("<pre"):
287 return highlighted + "\n"
288
289 # If language exists, inject class gently, without modifying original token.
290 # May be, one day we will add .deepClone() for token and simplify this part, but
291 # now we prefer to keep things local.
292 if info:
293 # Fake token just to render attributes
294 tmpToken = Token(type="", tag="", nesting=0, attrs=token.attrs.copy())
295 tmpToken.attrJoin("class", options.langPrefix + langName)
296
297 return (
298 "<pre><code"
299 + self.renderAttrs(tmpToken)
300 + ">"
301 + highlighted
302 + "</code></pre>\n"
303 )
304
305 return (
306 "<pre><code"
307 + self.renderAttrs(token)
308 + ">"
309 + highlighted
310 + "</code></pre>\n"
311 )
312
313 def image(
314 self,

Callers

nothing calls this directly

Calls 7

attrJoinMethod · 0.95
renderAttrsMethod · 0.95
unescapeAllFunction · 0.85
escapeHtmlFunction · 0.85
TokenClass · 0.85
highlightMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected