backstage / mkdocs-techdocs-core

The core MkDocs plugin used by Backstage's TechDocs as a wrapper around multiple MkDocs plugins and Python Markdown extensions
Apache License 2.0
83 stars 61 forks source link

Support PymDown Snippets #103

Closed marct83 closed 1 year ago

marct83 commented 1 year ago

I'm not 100% if Snippets is supported or not. It's not in the list of Pymdown extensions in the Readme. I have tried it but it seems to fail on the url_download option. Can support be added? This is a supper useful extension.

   - pymdownx.snippets:
          check_paths: true
          url_download: true
          url_request_headers: [{ Authorization: "Bearer xxxxxxxxxxxxxxxx"}]
verbose: [docker/mkdocs] ERROR    -  Config value 'markdown_extensions': Failed to load extension 'pymdownx.snippets'.
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/mkdocs/config/config_options.py", line 896, in run_validation
verbose: [docker/mkdocs]     md.registerExtensions((ext,), self.configdata)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown/core.py", line 123, in registerExtensions
verbose: [docker/mkdocs]     ext = self.build_extension(ext, configs.get(ext, {}))
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown/core.py", line 177, in build_extension
verbose: [docker/mkdocs]     return module.makeExtension(**configs)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/pymdownx/snippets.py", line 198, in makeExtension
verbose: [docker/mkdocs]     return SnippetExtension(*args, **kwargs)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/pymdownx/snippets.py", line 183, in __init__
verbose: [docker/mkdocs]     super(SnippetExtension, self).__init__(*args, **kwargs)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown/extensions/__init__.py", line 40, in __init__
verbose: [docker/mkdocs]     self.setConfigs(kwargs)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown/extensions/__init__.py", line 71, in setConfigs
verbose: [docker/mkdocs]     self.setConfig(key, value)
verbose: [docker/mkdocs]   File "/usr/local/lib/python3.8/site-packages/markdown/extensions/__init__.py", line 59, in setConfig
verbose: [docker/mkdocs]     if isinstance(self.config[key][0], bool):
verbose: [docker/mkdocs] KeyError: 'url_download'
verbose: [docker/mkdocs] Aborted with 1 Configuration Errors!
andrewthauer commented 1 year ago

Snippets do work, but I'm not sure what exactly the auth part is doing which is likely the culprit. We do something like this and it works fine:

  - pymdownx.snippets:
      base_path: 
        - 'docs'
        - 'docs/mkdocs_includes'
      auto_append:
        - 'mkdocs_includes/appendix.md'
marct83 commented 1 year ago

The url_download and url_request_headers allow you to download from an external source. The auth part is just an authorization header. It works fine locally, which is why I'm wondering why it fails in the container.

Ewande commented 1 year ago

the issue could be that URL snippets were introduced in 9.5 and pymdown-extensions is pinned to 9.3 for this package

marct83 commented 1 year ago

That's exactly what it was.