sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.61k stars 2.13k forks source link

toctree globbing uses lexicographical instead of natural sorting #3828

Open jessetan opened 7 years ago

jessetan commented 7 years ago

When using a toctree with the glob option, the filenames in the list are sorted using Python's sorted(), which does lexicographical sorting. An example result would be:

This is because in lexicographical sorting 1 < 2, hence item10 will come before item2. The sorting differs from what operating systems typically do, which would be:

This order makes more sense for humans.

The easiest way to implement this would be to add a new option to the toctree directive (e.g. :natsort:) that replaces sorted() with natsorted() from the Natsorted module. Just changing the behavior without an option is possible but will generate a different order for some document. I can make a PR for this, but only if there are no objections that:

  1. An additional pip requirement is added
  2. This only applies to globbed filenames, not actual document titles (see #1430).
Sarcasm commented 5 years ago

Would be a nice addition, for things like release notes, where one might want to have one .rst file per version, right now I'm listing the files manually in the natural order for that.

tk0miya commented 4 years ago

+1: Reasonable.

chadnorvell commented 9 months ago

Is there any objection to moving forward with this? It would a useful improvement for my team too.