Skip to content

Wrong example for !relative option #3453

@Andre601

Description

@Andre601

The Configuration page lists an example using pymdownx.snippets for the !relative YAML tag.

The issue with this example is, that the base_path option of snippets is expecting a list and not a single String, which breaks the configuration itself.
In fact, the relative option cannot be used by snippets at all it seems.

This error in the documentation should be fixed, as it will otherwise give people the idea, that it can be used with snippets like that...
Or IF it can be used, there should be more clarification on this.

Below is a collection of stacktraces thrown by MkDocs when using !relative in different setups:

markdown_extensions:
  # ...
  - pymdownx.snippets:
      base_path: !relative
Stacktrace

ERROR   -  Config value 'markdown_extensions': Failed to load extension 'pymdownx.snippets'.
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\config\config_options.py", line 1021, in run_validation
    md.registerExtensions((ext,), self.configdata)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\markdown\core.py", line 115, in registerExtensions
    ext.extendMarkdown(self)
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymdownx\snippets.py", line 402, in extendMarkdown
    snippet = SnippetPreprocessor(config, md)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\pymdownx\snippets.py", line 85, in __init__
    self.base_path = [os.path.abspath(b) for b in base]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'RelativeDirPlaceholder' object is not iterable
Aborted with 1 configuration errors!
ERROR   -  [21:51:48] An error happened during the rebuild. The server will appear stuck until build errors are resolved.

markdown_extensions:
  # ...
  - pymdownx.snippets:
      base_path:
        - !relative
Stacktrace

ERROR   -  Config value 'markdown_extensions': Failed to load extension 'pymdownx.snippets'.
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\utils\yaml.py", line 52, in __fspath__
    return os.path.join(self.value(), self.suffix)
                        ^^^^^^^^^^^^
  File "C:\Users\Andreas\AppData\Local\Programs\Python\Python311\Lib\site-packages\mkdocs\utils\yaml.py", line 98, in value
    raise exceptions.ConfigurationError(
ConfigurationError: The current file is not set for the '!relative' tag. It cannot be used in this context; the intended usage is within `markdown_extensions`.
Aborted with 1 configuration errors!
ERROR   -  [21:52:36] An error happened during the rebuild. The server will appear stuck until build errors are resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions