daizutabi / mkapi

A plugin for MkDocs to generate API documentation
https://daizutabi.github.io/mkapi/
MIT License
95 stars 19 forks source link

[Enhancement] Add Node header into the table of content? #3

Closed hcoohb closed 7 months ago

hcoohb commented 4 years ago

Hi,

First, thanks for allowing me to make beautiful API docs so easily!!

This is more a feature suggestion and I am not sure of the internal, so I don't know if it is possible. But could we have the option to add the main nodes to the toc? So If I use ![mkapi](package.module.Class), then that would also add the Class methods in the toc ?

That would be terrific

daizutabi commented 4 years ago

I'm not sure but if my understanding is correct, MkDocs builds the toc from Markdown's header statement (#, ##, ###, etc.). On the other hand, MkApi uses nested div tags to represent tree structure of Node. I think adding header is potentially possible but some survey is needed to understand how MkDocs builds the toc.

daizutabi commented 4 years ago

I think this is not the exact feature you hope, but now MkApi creates Classes, Functions, and Methods sections at module and class levels. These sections work as a kind of toc.

img
daizutabi commented 4 years ago

In Version 0.8.4, if you use page mode, MkApi creates toc in nav.

img2

(Readthedocs theme)

hcoohb commented 4 years ago

Thanks a lot for that, I can confirm that with material theme, the TOC is also being created in page mode!

For non page mode, I found a way to make it work, although it is a bit of a hack. For example if we have a class in a markdown doc:

![mkapi](pi_lib.Connection)

Then we can just add at the end:

##   { #pi_lib.Connection data-toc-label='Connection' }
###   { #pi_lib.Connection.get_root data-toc-label='get_root()' }
###   { #pi_lib.Connection.get_webid data-toc-label='get_webid()' }

This uses the fact that we can rename an entry to the toc. Then if we do not even want to display the space for those blank headers, we can just hide them in a custom css:

h2[id^=pi_lib\.Connection], h3[id^=pi_lib\.Connection] {
    display:none;
}

(assuming no other header in other pages would match the css selector)

It works great for my usecase

daizutabi commented 4 years ago

You can also use "Heading mode" to create toc for non page mode.

## ![mkapi](pi_lib.Connection)

I found a bug in the heading mode and fixed it in Version 1.0.10, so please update the package to use the method above.