Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: handle empty config items for plugins #3055

Open
RichardForshaw opened this issue Dec 1, 2022 · 1 comment
Open

Request: handle empty config items for plugins #3055

RichardForshaw opened this issue Dec 1, 2022 · 1 comment
Assignees
Labels

Comments

@RichardForshaw
Copy link

Explanation:

I am writing a plugin which generates additional content to documents. However some of this content is very simple and the only config item that is needed is to declare that it is present. But for others (of the same common type), some config will be needed. Think: buttons which only differ by appearance.

Current situation:

My plugin config has defaults that can either be inherited or customised, and looks like this:

plugins:
  myplugin:
    default_string: "A default"
    item1:
      present: true
      custom_string: "Customised"
    item2:
      present: true
    # User chooses not to include item3 in their pages

As you can see, because item2 uses the defaults, there is really no need for any config to be listed except to say that the user wants it included. However because the sub-items are all defined as SubConfig, they must have fields defined. I think this looks clunky and too verbose.

Current alternative

The alternative I use is to use the yaml {}:

plugins:
  myplugin:
    default_string: "A default"
    item1:
      custom_string: "Customised"
    item2: {}

This works but just looks a bit ugly.

Proposed solutions:

  1. If a SubConfig is empty, instead of throwing an exception (that it is expecting a dict but got None), that it instead returns an empty dict. Then I can declare:
plugins:
  myplugin:
    default_string: "A default"
    item1:
      custom_string: "Customised"
    item2:
      # empty

I realise that this might also look a bit odd, so...

  1. That a SubConfig can have two types, so it can be declared: e.g. item2 = config_options.SubConfig([CommonConfig, bool]) or similar. Then I can declare:
plugins:
  myplugin:
    default_string: "A default"
    item1:
      custom_string: "Customised"
    item2: true

This avoids the awkwardness of (1) and conveys the intent.

  1. There is a way of using MKDocs and YAML that I am not aware of :)
@pawamoy pawamoy self-assigned this Apr 17, 2024
@pawamoy
Copy link
Sponsor Contributor

pawamoy commented Apr 17, 2024

I'll run some tests to see what is currently possible to do with MkDocs config API. In the meantime we recommend you use the "ugly" syntax 😄 Please ping me if I forget about this 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants