sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

Parse page metadata with `.` in keys as nested dictionaries

Open choldgraf opened this issue 3 years ago • 0 comments

Context

Right now, reStructuredText has fairly basic support for page-level metadata. You supply a key and value, and both are parsed as strings.

However, there are many cases where it is useful to have nested configuration. For example, if you have many configuration options that naturally fall into groups, it is helpful to nest things under top-level categories to keep things simpler.

Many libraries (like TOML) support "dotted" configuration strings. Essentially, dots are parsed into nested congiruation, so key1.key2 = "foo" becomes {"key1": {"key2": "foo"}}. In the context of Sphinx / rST, then configuration like this:

:html_theme.header.remove: true

might get parsed to:

{
  "html_theme": {
  "header": {"remove": "true"},
  }
}

Proposal

Sphinx could parse page-level metadata that had . in keys as "dotted" nested configuration variables. This would allow theme developers to do things like mimic their html_theme_options structure within page-level metadata, to make it easier to use page-level over-rides.

For an example of how this could be implemented using just the stdlib, here's a helpful StackOverflow answer: https://stackoverflow.com/a/57561744/1927102

choldgraf avatar Jul 23 '22 08:07 choldgraf