pdoc icon indicating copy to clipboard operation
pdoc copied to clipboard

Apply Python syntax highlighting to all code blocks by default

Open michael1006 opened this issue 10 months ago • 1 comments

Problem Description

Code blocks are not syntax-highlighted in Python by default. For example, compare:

    ```
    def test():
        pass
    ```

    ```py
    def test():
        pass
    ```

This generates:

Image

It can also be seen that the Python-highlighted code block has different margins.

Further, when using indentation to indicate code, according to the Google format, there is no way to specify syntax highlighting at all. It is off. E.g.:

def test():
    """
    A docstring in Google format.

    Here is a code block:

        # This example code can't be syntax-highlighted
        foo = bar
    """

Proposal

Since this project is intended for Python, it would make sense for all code blocks to be syntax highlighted by default.

It would also make sense for margins to be consistent.

But most importantly, when using indentation to indicate code in the Google format, it seems most important to syntax highlight by default, since there isn't any way of enabling it manually, the way it can be done with Markdown.

Also, if there are markdown code blocks that shouldn't have highlighting (e.g. terminal output), one solution could be to specify them as text, a language code supported on GitHub

Alternatives

If syntax highlighting isn't enabled by default for Markdown, to do it at least for Google-style indented code.

michael1006 avatar Feb 12 '25 16:02 michael1006

Sounds all very reasonable to me, happy to take PRs! 😃

mhils avatar Feb 12 '25 20:02 mhils