0

Can automatic sequential figure numbers be assigned in MkDocs? Something similar is also needed for code blocks to be numbered independently of the figures.

[![CC-BY-SA_icon](/images/CC-BY-SA_icon.png "Attribution 4.0 International (CC BY 4.0)"){: style="width:150px"}](https://creativecommons.org/licenses/by/4.0/)

Figure 1: Creative Commons license 4.0
flywire
  • 1,155
  • 1
  • 14
  • 38

2 Answers2

1

As far as I know there's no built-in way of achieving your goal. As long as MkDocs allows you to use Markdown extensions, you could use one of these in order to number your figures. But alas, there's also no plugin for figure numbering that I'm aware of.

One possibility to at least number your images would be to extend yafg (a Markdown extension allowing you to automatically create <figure> and <figcaption> tags) to support figure numbering. I'm the author of it and would gladly provide that feature if needed. Just let me know.

Still, this wouldn't fulfill your need for code listing numbering. Alas, I cannot provide any help in this regard.

I know that this is rather a comment than a full-fledged answer but since I don't have enough reputation, I'm not allowed to comment. Thus, please excuse the brevity of the answer.

Ferruck
  • 190
  • 1
  • 3
  • I searched mkdocs [extensions](https://github.com/Python-Markdown/markdown/wiki/Third-Party-Extensions) and couldn't find any that did this so I agree with your answer. Autonumbering is a fundamental service in a document processor. https://www.mkdocs.org/#getting-help – flywire Jun 18 '20 at 23:05
  • I had a closer look at the docs and indeed you can [use Markdown extensions](https://www.mkdocs.org/user-guide/configuration/#markdown_extensions). I'll have a look into adding the feature to yafg, but cannot give any ETA. – Ferruck Jun 19 '20 at 06:34
  • The answer needs updating since you have now fully implemented that feature in [yafg](https://pypi.org/project/yafg/). – flywire Jul 19 '20 at 03:31
1

I've forked yafg into caption to extend the functionality to other content types. It is a python markdown extension, used by many platforms including MkDocs, with a range of settings for flexibility.

flywire
  • 1,155
  • 1
  • 14
  • 38