mkdocstrings / griffe

Signatures for entire Python programs. Extract the structure, the frame, the skeleton of your project, to generate API documentation or find breaking changes in your API.
https://mkdocstrings.github.io/griffe
ISC License
319 stars 44 forks source link

Google-style `Example:` `>>>` code blocks not rendering correctly #201

Closed glenn-jocher closed 1 year ago

glenn-jocher commented 1 year ago

Describe the bug Google-style Example: >>> code blocks not rendering correctly in mkdocs using mkdocsmaterial with mkdocstrings.

Original socstring

Screenshot 2023-08-20 at 17 19 23

Mkdocs serve results

Screenshot 2023-08-20 at 17 14 10

My plugins section of mkdocs.yaml looks like this:

plugins:
  - search
  - mkdocstrings:
      enabled: true
      default_handler: python
      handlers:
        python:
          options:
            docstring_style: google
            show_root_heading: true
            show_source: true
$ mkdocs serve
INFO     -  Building documentation...
INFO     -  Cleaning site directory
WARNING  -  Both index.md and README.md found. Skipping README.md from /Users/glennjocher/PycharmProjects/ultralytics/docs
INFO     -  Documentation built in 47.42 seconds

To Reproduce

Build docs with this example function:

class RTDETRTrainer:
    """
    A class extending the DetectionTrainer class for training based on an RT-DETR detection model.

    Notes:
        - F.grid_sample used in rt-detr does not support the `deterministic=True` argument.
        - AMP training can lead to NaN outputs and may produce errors during bipartite graph matching.

    Example:
        >>> from ultralytics.models.rtdetr.train import RTDETRTrainer
        >>> args = dict(model='rtdetr-l.yaml', data='coco8.yaml', imgsz=640, epochs=3)
        >>> trainer = RTDETRTrainer(overrides=args)
        >>> trainer.train()
    """

Expected behavior

Expect code to render correctly with python highlights.

System (please complete the following information):

pawamoy commented 1 year ago

Thanks for the report!

PyCon code blocks are only recognized in Examples sections (plural), not in Example ones (which are parsed and rendered as admonitions). This is documented here: https://mkdocstrings.github.io/griffe/docstrings/#examples.

In the future such code blocks will be recognized anywhere thanks to a Markdown extension. This is in our backlog, therefore I'll close this issue :slightly_smiling_face: