2

I am using MkDocs with the codehilite markdown extension

I would like to enable code snippet line numbers only for specific snippets.

If I set

markdown_extensions:
  - codehilite:
      linenums: true

in my mkdocs.yml, this will enable line numbers for all code snippets.

I see that it is possible to activate line numbers for specific snippets by using the shebang language specifier together with double indentation:

#!python
""" Bubble sort """
def bubble_sort(items):
    for i in range(len(items)):
        for j in range(len(items) - 1 - i):
            if items[j] > items[j + 1]:
                items[j], items[j + 1] = items[j + 1], items[j]

However, I prefer using backticks (```) for designating code.

Is there a way to enable line numbers for specific code listings when using backticks?

Waylan
  • 37,164
  • 12
  • 83
  • 109
Thomas Kainrad
  • 2,542
  • 21
  • 26

1 Answers1

2

No, this feature is not supported by the fenced code blocks extension of Python-Markdown. Only the global linenums setting of the codehilite extension is used for fenced code blocks.

Of course, you always could fork the extension and alter the behavior to match your needs, so long as you do so within the confines of the relevant license.

Waylan
  • 37,164
  • 12
  • 83
  • 109
  • Thanks for the clarification. I guess I can live without it. Thinking that there might be a way I can not think of was just making me a little uneasy ;) – Thomas Kainrad Apr 12 '19 at 19:41