getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.6k stars 445 forks source link

MARKDOWN_EXTENSION_CONFIGS doesn't work as expected #3647

Closed liffiton closed 1 year ago

liffiton commented 1 year ago

Environment

Python Version: 3.8.10

Nikola Version: 8.2.3

Operating System: Ubuntu 20.04

Description:

I wanted to configure the table of contents Markdown extension, so I wrote in conf.py:

# Options to be passed to markdown extensions (See https://python-markdown.github.io/reference/)
# Default is {} (no config at all)
MARKDOWN_EXTENSION_CONFIGS = {
    'markdown.extensions.toc': { 'toc_depth': 1 }
}

This follows the specification in the linked reference, as far as I can tell.

But that didn't work, and when looking at the relevant code in nikola/plugins/compile/markdown/__init__.py, it looked like this would:

# Options to be passed to markdown extensions (See https://python-markdown.github.io/reference/)
# Default is {} (no config at all)
MARKDOWN_EXTENSION_CONFIGS = {
    'junk': {   # This appears to work around a bug / confusion in the code that handles MARKDOWN_EXTENSION_CONFIGS
        'markdown.extensions.toc': { 'toc_depth': 1 }
    }
}

And indeed that does work.

I'm not sure if the code that handles MARKDOWN_EXTENSION_CONFIGS is incorrect or if the documentation in the default conf.py needs to be updated to be clearer on what is expected there.

Kwpolska commented 1 year ago

The documentation in conf.py was incorrect. MARKDOWN_EXTENSION_CONFIGS is a translatable setting, i.e. you can specify different configs for different languages. Translatable settings which are strings can be converted automatically by us, but for dicts, you need to be explicit and specify the language. The translatability of MARKDOWN_EXTENSION_CONFIGS was not documented, and the example wasn’t appropriate, so I updated it, and you should replace 'junk' with DEFAULT_LANG.

liffiton commented 1 year ago

Got it. Thanks!