Generally, you don’t have to know read here. Please read yogosyu extension.


Module user_order_index_patch

The Sphinx extension to fix generating genindex.html for sortorder.

copyright:© 2011-2015 by Suzumizaki-Kimitaka(about Additional works)
license:2-clause BSD.

This is the extension for Sphinx.

This extension hacks sphinx.environment.BuildEnvironment.create_index(). No roles, directives, domains or etc. will be added.


Determine sort order used in this module

Parameters:cfg (sphinx.config.Config) – you can give from Sphinx with app.config, builder.config etc.
Return type:None

Sort the index entries

Parameters:entry (composited) – the element to sort. entry[0] is the name of it.
Return type:str(Python 3) or unicode(Python 2)
Returns:the comparable string to sort.

Called by my_env_buildenv_create_index()

  • entry[0] is the name of the entry
  • entry[1] is a tuple
    • entry[1][0] is a list of the urls include filename, extension and anchor to the entry.
    • entry[1][1] is the dict of subwords.

the entries are generated by sphinx.environment.BuildEnvironment.add_entry() defined inside sphinx.environment.BuildEnvironment.create_index(). (also means inside my_env_buildenv_create_index())


Group the entries by letter.

Parameters:item (sortkey_content_pair) – the tuple (sortkey, content)
Return type:str(Python 3) or unicode(Python 2)
Returns:the group name in which (k, v) entry belongs.

Called by my_env_buildenv_create_index().

See note written in the document of keyfunc().

user_ordered_index_patch.my_env_buildenv_create_index(self, builder, group_entries=True, _fixre=<_sre.SRE_Pattern object>)

Hack function to alter sphinx.environment.BuildEnvironment.create_index

In real, this function is almost same as sphinx.environment.BuildEnvironment.create_index() except:

  • keyfunc and keyfunc2 are not inner function
  • setup _name_to_yomi dictionary at first
  • both python 2.7.6 and python 3.3 compatible

Extend the Sphinx as we want, called from the Sphinx

Parameters:app (sphinx.application.Sphinx) – the object to add builder or something.

Return sort-key or given string if not found one

Parameters:s (str_or_unicode) – the string refer to one of entry
Return type:str(Python 3) or unicode(Python 2)
Returns:the sort-key refer to the entry or just s if sort-key not found