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

Fix page metadata also for gallery examples #101

Open
smarie opened this issue Sep 4, 2024 · 3 comments
Open

Fix page metadata also for gallery examples #101

smarie opened this issue Sep 4, 2024 · 3 comments

Comments

@smarie
Copy link
Owner

smarie commented Sep 4, 2024

          Thanks @smarie! Just to say that `feature/96_97_issues` fixes the issue with the `README.md`!

I do have a follow up question/problem though: I'd like to use the same page setup in my examples.

examples/plot_00_test.py

"""
---
hide:
    - toc
---

Plotting Overview
=================
"""
...

generated/gallery/plot_00_test.md

<!--
 DO NOT EDIT.
 THIS FILE WAS AUTOMATICALLY GENERATED BY mkdocs-gallery.
 TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
 "docs/examples/1_plotting/plot_00_plotting_intro.py"
 LINE NUMBERS ARE GIVEN BELOW.
-->

!!! note

    Click [here](#download_links)
    to download the full example code


---
hide:
    - toc
---

Plotting Overview
=================
....

Unsurprisingly mkdocs renders this incorrectly:
Screenshot 2024-09-04 at 14 31 13

Is there any chance you could pass through headers in the example files too?

Originally posted by @schlegelp in #96 (comment)

@smarie
Copy link
Owner Author

smarie commented Sep 4, 2024

The problem here @schlegelp is that the currently inserted header is quite useful : as you can see in the EXAMPLE_HEADER variable used in the below piece of code, it contains a note with the download link to the example code and optionally binder page. So we can not fix this the same way that I did for the README.md

EXAMPLE_HEADER = """

md_before = EXAMPLE_HEADER.format(pyfile_to_edit=src_relative, opt_binder_text=binder_text)

I see three possibilities:

  • ask the mkdocs-material project to support placing the metadata anywhere in the page (not only at the top)
  • ask mkdocs-material to provide an API to extract the metadata headers from a page
  • try to code the above item ourselves - with no guarantee that the format of the metadata headers will not change in the future. This is why I dont like this idea much, but it can be temporary.

I let you decide which path you prefer, and try ? If you managed to clone the project and "pip install ." works for you, then you are almost set to develop: simply edit the above lines of code to change the contents of md_before and md_after, at least to validate that if md_before was set to empty string, the rest of the expected behaviour you target would work :)

For more comfort (but this is optional), you may wish to create a debug configuration in your IDE, so that you can place breakpoints. Here is a recipe with Pycharm : #54 (comment)

@schlegelp
Copy link

I have no clue how receptive the mkdocs material folks are to accommodate downstream projects? Option 1 could potentially break things if people use ---- somewhere else in their documents.

Option 3 would probably be the path of least resistance. I agree it could potentially be brittle but the header syntax feels pretty mature.

I can see two ways of implementing this:

  1. Try to extract headers from the .py file and insert at the beginning of md_before
  2. Piggy back on the existing # mkdocs_gallery_... syntax:
    examples/plot_00_test.py
    """
    Plotting Overview
    =================
    """
    ...  
    # mkdocs_gallery_page_title = "my title"
    # mkdocs_gallery_page_hide_toc = True
    

Pretty busy at the moment but if I get a chance I will try to have a crack at it!

@smarie
Copy link
Owner Author

smarie commented Sep 5, 2024

Nice ideas @schlegelp ! I like option 2, and it can even be made generic with a common prefix (everything after the option prefix would be considered a piece of metadata for mkdocs-material headers).

Ok no worries, let me know when you have the time ! At least doing a "fake" PoC manually and showing the expected result (I remember you mentioned hiding the toc) would be great I think, so that other users/contributors looking at this issue understand the interest of this feature

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

No branches or pull requests

3 participants
@smarie @schlegelp and others