2

I'm trying to add an option to my custom markdown extension in python3. Unfortuantely I'm getting the following error:

  File "pymodules/docmarkdown.py", line 232, in get_leaflang_markdown
    MyFencedCodeExtension(deflang = "leaf"),
  File "pymodules/docmarkdown.py", line 61, in __init__
    super(MyFencedCodeExtension,self).__init__(**kwargs)
TypeError: __init__() got an unexpected keyword argument 'deflang'

The constructor code of the extension is below. It follows the pattern provided by the docs.

class MyFencedCodeExtension(markdown.extensions.Extension):

    def __init__(self, **kwargs):
        self.config = { 'deflang' : [ None, "language if not specified" ] }

        super(MyFencedCodeExtension,self).__init__(**kwargs)

I'm referencing the extension when constructing the Markdown instance:

return markdown.Markdown(
    safe_mode = 'escape',
    extensions = [
        'meta',
        'toc',
        MyFencedCodeExtension(deflang = "leaf"),
        CenterExtension({}),
    ]
Vinícius Figueiredo
  • 6,300
  • 3
  • 25
  • 44
edA-qa mort-ora-y
  • 30,295
  • 39
  • 137
  • 267

1 Answers1

0

This error message is happening on your super() call.

The superclass of MyFencedCodeExtension is markdown.extensions.Extension.

According to the error message, the superclass constructor is not expecting the keyword argument deflang.

Look at the signature of markdown.extensions.Extension.__init__ to work out what it is expecting.

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • Yes, I understand specifically what the error means. My question is how to do this correctly for an extension. This setup comes directly from the docs -- I was assuming it was doing something tricky with `config`, but it may indeed just be a mistake in the docs. – edA-qa mort-ora-y Jul 24 '17 at 13:04
  • That is why I suggested you go and look at the constructor signature. If you follow a recipe exactly and you get that sort of exception thrown, then the problem is probably with the recipe. My guess is spelling or capitalization. – BoarGules Jul 24 '17 at 13:08