sphinx-design icon indicating copy to clipboard operation
sphinx-design copied to clipboard

Per-page default option values for directives

Open choldgraf opened this issue 3 years ago • 1 comments

Context

There are many times where you want to populate a single page with many Sphinx Design items that all share the same configuration. For example, "I want a list of 10 cards, each of which has a specific margin, padding, outline, or CSS class".

In these cases, there is a lot of toil and boilerplate duplication when adding them, since you have to manually edit the options for each one. It would be helpful if there were a way to define the default configuration of each item once and then re-use it throughout the page.

Proposal

Make it possible to define the default configuration of Sphinx Design components on a per-page level (or at the site-level). There are two ways I could think of to do this:

  1. Use page-level configuration. For example:

    sphinx_design:
       defaults:
          link-button:
     	    :color: primary
     		:outline:
    

    However I don't know that this would be doable in rST...

  2. Set page-level defaults with a directive. For example, perhaps there was a sd-default directive. Inside that directive you could define any arbitrary Sphinx Design objects. It would render them as normal, but would also then set the configuration of each object to be the default for any subsequent objects on the page. e.g.:

    ````{sd-default}
    ```{button-link} foo
    :color: primary
    :outline:
    ```
    ````
    

Tasks and updates

No response

choldgraf avatar Jul 20 '22 07:07 choldgraf

I think actually this would be more general, and actually easier, to implement this in myst-parser! Obviously, this would only then be supported in Markdown/MyST-NB documents, but then well, people should use those 😄

chrisjsewell avatar Aug 22 '22 20:08 chrisjsewell