mkdocs: Indented code block not transformed
I want to place a code block in a numbered list. Stack Overflow has the answer, but when I indent the backticks, they’re not picked up by the parser, and are simply rendered as text. If the backticks are not indented, the numbering restarts.
The following works on GitHub but not MkDocs.
-
Foo
def hello_world(): pass more -
Bar
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 16 (8 by maintainers)
Commits related to this issue
- MkDocs test This is a first attempt to use MkDocs to publish documentation. There is currently a problem with the pages generated by MkDocs, as indented code blocks within bulleted lists are not par... — committed to dregad/ADOdb by dregad 9 years ago
- Documentation on restoring CF databases We'd like to know what to do if we lose some or all data from our persistent Cloud Foundry environments. Here we add a new guide on how to restore data from ou... — committed to alphagov/paas-team-manual by deleted user 7 years ago
- Documentation on restoring CF databases We'd like to know what to do if we lose some or all data from our persistent Cloud Foundry environments. Here we add a new guide on how to restore data from ou... — committed to alphagov/paas-team-manual by deleted user 7 years ago
- Documentation on restoring CF databases We'd like to know what to do if we lose some or all data from our persistent Cloud Foundry environments. Here we add a new guide on how to restore data from ou... — committed to alphagov/paas-team-manual by deleted user 7 years ago
So to build on/clarify @geerlingguy’s solution (which is what worked for me with mkdocs 0.17.3):
Here’s a example (I’ve replaced spaces with periods to make it clear)
You could use this: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/.
It supports indented, fenced code blocks in a fairly same manner.
It’s been mentioned in this thread that https://facelessuser.github.io/pymdown-extensions/extensions/superfences/ allows for indented fenced code. This would be the better way.
After all this time, is there a better way to handle this? This seems to ignore blocks above and lose the syntax coloring.
@jsaintro While this solution does allow for indenting and continued numbering to occur you are not able to set the code style.
I think it originated even before Github, maybe I am wrong, but I don’t see why the three bactics is a problem. It doesn’t matter if it isn’t universal unless your docs have to be parsed by everything universally. My MkDoc docs are used just for MkDocs, so having a syntax that is Python Markdown specific isn’t a problem for me. I’ve personally found backtics to be easier to visualize in lists for me.
With that said, I did write a Python Markdown extension to allow triple backtic code blocks to work in lists properly: http://facelessuser.github.io/pymdown-extensions/extensions/superfences/. Now I realize it doesn’t come as a standalone extension, but as a group of extensions, but you can enable only what you want. I also realize some people just prefer using white space, or maybe they parse the same document with multiple parsers for different reasons, and I understand that as well. If people are looking for workarounds, maybe this will be a suitable one for some.
So… if you just want to show a code block inside a list, you have to get the right number of spaces, with a space in between the previous line as well, for example:
https://github.com/geerlingguy/drupal-vm/commit/2152f645186b22277add0a7e99e892a5c0a79203
Which renders as:
http://docs.drupalvm.com/en/latest/extras/behat/#setting-up-behat-for-your-project
(see https://github.com/geerlingguy/drupal-vm/issues/280)