lepture/mistune

AttributeError: No renderer "''"

hellocode808 opened this issue · 1 comments

I'm trying to write a plugin that makes it easy to define new inline shortcodes, so I just have to define the render_shortcode function.

I get the error

../venv/lib/python3.10/site-packages/mistune/core.py", line 193, in _get_method
    raise AttributeError('No renderer "{!r}"'.format(name))
AttributeError: No renderer "''

Using Mistune v3.0.0rc5. What am I missing? Or is this faulty behavior?

Below my code.

SHORTCODE_PATTERN = '\{\<(?P<shortcode_name>.*?) (?P<arg1>.*?)\>\}'

shortcodes_list = ('video', 'embed')


def parse_shortcodes(block, m, state):
    name = m.group("shortcode_name")
    arg1 = m.group("arg1")
    print("name:", name, arg1)
    state.append_token({'type': name, 'raw': arg1})

    return m.end()

def render_video(renderer, name):
    return 'VIDEO'


def render_embed(renderer, name):
    return 'EMBED'

def shortcodes(md):

    md.inline.register(
        'shortcode', SHORTCODE_PATTERN, parse_shortcodes)
    if md.renderer and md.renderer.NAME == 'html':
        for shortcode in shortcodes_list:
            f_name = "render_" + shortcode
            md.renderer.register(shortcode, globals()[f_name])

calling it with

{< video url.mp4 >}

This can be closed. Error was on my side. the m.group("shortcode_name") didn't match (missing whitespace).