lepture/mistune

Unexpected Keyword Argument in Documentation Renderer Example

TheConcolor opened this issue · 1 comments

I was trying to run the code example for a customized renderer (https://mistune.lepture.com/en/latest/guide.html#customize-renderer), and ran into an unexpected keyword argument error.

I created a Python3 virtual environment to run the code and below are details on my environment:

$ python --version
Python 3.8.10

$ pip freeze
mistune==3.0.0rc1
Pygments==2.13.0

This is the code copied directly from the documentation (I added the shebang):

#!/usr/bin/env python3

import mistune
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import html

class HighlightRenderer(mistune.HTMLRenderer):
    def block_code(self, code, lang=None):
        if lang:
            lexer = get_lexer_by_name(lang, stripall=True)
            formatter = html.HtmlFormatter()
            return highlight(code, lexer, formatter)
        return '<pre><code>' + mistune.escape(code) + '</code></pre>'

markdown = mistune.create_markdown(renderer=HighlightRenderer())

This is the output I receive upon execution:

$ ./main.py
Traceback (most recent call last):
  File "./main.py", line 19, in <module>
    print(markdown('```python\nassert 1 == 1\n```'))
  File "/code/md/venv/lib/python3.8/site-packages/mistune/markdown.py", line 88, in __call__
    return self.parse(s)[0]
  File "/code/md/venv/lib/python3.8/site-packages/mistune/markdown.py", line 68, in parse
    result = self.block.render(state, self.inline)
  File "/code/md/venv/lib/python3.8/site-packages/mistune/block_parser.py", line 447, in render
    return self._call_render(state.tokens, state, inline)
  File "/code/md/venv/lib/python3.8/site-packages/mistune/block_parser.py", line 452, in _call_render
    return inline.renderer(data)
  File "/code/md/venv/lib/python3.8/site-packages/mistune/core.py", line 216, in __call__
    return ''.join(self._iter_tokens(tokens))
  File "/code/md/venv/lib/python3.8/site-packages/mistune/core.py", line 211, in _iter_tokens
    yield func(children, **attrs)
TypeError: block_code() got an unexpected keyword argument 'info'

I am extremely new to mistune, so if there are other helpful details I am missing, let me know and I will do my best to track those down.

documentation updated, it should be info instead of lang in parameter.