oprypin / mkdocs-literate-nav

MkDocs plugin to specify the navigation in Markdown instead of YAML
https://oprypin.github.io/mkdocs-literate-nav
MIT License
73 stars 8 forks source link

No generation if indentation is 2 spaces? #14

Closed a4z closed 1 year ago

a4z commented 1 year ago

Hi,

It seems I do not get the site map when the markdown file I use is indented 2 spaces. Only 4 works. What is unfortunate since this conflicts with some auto-format rules I have.

Is there a way to make it work with 2 spaces?

like this

* [Home](index.md)
  * [About](about.md)

instead of

* [Home](index.md)
    * [About](about.md)

?

a4z commented 1 year ago

Additional info: Markdownlint, expects 2 spaces https://github.com/DavidAnson/markdownlint/blob/v0.26.2/doc/Rules.md#md007

oprypin commented 1 year ago

The original Markdown specification requires lists to be indented by 4 spaces. If there are fewer spaces, it is not counted as indentation.

So first off, I sure hope that this linter can be changed so it doesn't recommend broken Markdown instead of correct Markdown.

Example for markdownlint: https://github.com/mkdocs/mkdocs/blob/56b235a8ad43f2300d17f87e6fa4de7a3d764397/.markdownlintrc#L14


MkDocs uses Python-Markdown which closely follows this original specification.

So, if you put such a list into a normal Markdown file within MkDocs, it will also be considered a flat list - not indented. So, you already have a problem with MkDocs regardless of this plugin. Just try it and see.


mkdocs-literate-nav doesn't parse Markdown, it uses exactly what MkDocs parsed. So, if you solve the issue you're having with MkDocs overall, it will also solve the issue for this plugin.


To solve this for MkDocs overall, I believe this plugin will do the trick: https://github.com/radude/mdx_truly_sane_lists

markdown_extensions:
  - mdx_truly_sane_lists
a4z commented 1 year ago

lot of valuable information, thank you!

a4z commented 1 year ago

using mdx_truly_sane_lists and 2 spaces makes the navigation.md rendered correctly, but the navigation is still messed up.

there seems to be no real solution, except, to keep the indent on 4 spaces and add a linter config to enforce that

oprypin commented 1 year ago

Oh, sorry. So what I said is wrong 😞

mkdocs-literate-nav doesn't parse Markdown, it uses exactly what MkDocs parsed. So, if you solve the issue you're having with MkDocs overall, it will also solve the issue for this plugin.

Instead, it just uses Python-Markdown without any extensions.

https://github.com/oprypin/mkdocs-literate-nav/blob/2ee23c431e93049369d1f3d22cf78e333298559e/mkdocs_literate_nav/parser.py#L54

I could do a change to actually make it work like I said, but not sure what's best.

a4z commented 1 year ago

mdx_truly_sane_lists seems to be super nice and helpful. It fixes some docs I have imported, where no one will ever have the energy to reformat them. It would be awesome if it could be used, also in the nav section and have a consistent style throughout the project

oprypin commented 1 year ago

Thanks for the productive discussion. I have opened a pull request that does this. Likely to be released tomorrow.

I even discovered that Python-Markdown actually has configurable indentation, but it's impossible to specify it in MkDocs itself.

a4z commented 1 year ago

Thank you for following up on the topic and for the fast reaction! So great getting that feature in such a short time.

I even discovered that Python-Markdown actually has configurable indentation, but it's impossible to specify it in MkDocs itself.

Do you think this should be reported to mkdocs?

oprypin commented 1 year ago

Well I'm keeping track of this for mkdocs myself. I think in the end it's actually not such a useful config in the general case because https://github.com/Python-Markdown/markdown/blob/4dab9a7436357173fad08a0f4e67a63daaaa15a6/docs/index.md?plain=1#L93

this will affect indentation for all aspects of the syntax (including root level code blocks).

-doesn't seem like something I'd want to encourage