Skip to main content

KanaText class extends the functionality of Text class.

Project description

extends the functionality of the Text class. any person, who use index/glossary directives with Japanse Kanji, is to be so happy.

conf.py

First of all, add sphinxcontrib-kana_text to sphinx extension list in conf.py

extensions = ['sphinxcontrib.kana_text']
#html_kana_text_on_genindex = False
#html_kana_text_use_own_indexer = 'large'

rst file

then use index directive, glossary directive, index role and kana role.

You can specify the follwings:

.. index:: ようご|用語^21
.. glossary::

   ようごいち|用語壱^212
     用語1の説明。

And you can also use index/kana role.

build

finally, build your sphinx project:

$ make kana

take a look at genindex.html.

genindex.html

{# genindex.html #}
{%- extends "layout.html" %}
{% set title = _('Index') %}

{% macro kana_entry(kname) %}
  {%- if kname is string -%}
  {{ kname|e }}
  {%- else %}
  {%- for isruby, val in kname -%}
    {%- if isruby -%}
    <ruby><rb>{{ val[0]|e }}</rb><rp>(</rp>
    <rt>{{ val[1]|e }}</rt><rp>)<rp>
    </ruby>
    {%- else %}
    {{ val|e }}
    {%- endif %}
  {%- endfor %}
  {%- endif %}
{% endmacro %}

{% macro indexentries(firstname, links) %}
  {%- if links -%}
    <a href="{{ links[0][1] }}">
    {%- if links[0][0] %}<strong>{% endif -%}
    {{ kana_entry(firstname) }}
    {%- if links[0][0] %}</strong>{% endif -%}
    </a>

    {%- for ismain, link in links[1:] -%}
      , <a href="{{ link }}">{% if ismain %}<strong>{% endif -%}
      [{{ loop.index }}]
      {%- if ismain %}</strong>{% endif -%}
      </a>
    {%- endfor %}
  {%- else %}
    {{ kana_entry(firstname) }}
  {%- endif %}
{% endmacro %}

{% block body %}

<h1 id="index">{{ _('Index') }}</h1>

<div class="genindex-jumpbox">
 {% for key, dummy in genindexentries -%}
 <a href="#{{ key }}"><strong>{{ key }}</strong></a>
 {% if not loop.last %}| {% endif %}
 {%- endfor %}
</div>

{%- for key, entries in genindexentries %}
<h2 id="{{ key }}">{{ key }}</h2>
<table style="width: 100%" class="indextable genindextable"><tr>
  {%- for column in entries|slice_index(2) if column %}
  <td style="width: 33%; vertical-align: top;"><ul>
    {%- for entryname, (links, subitems, _) in column %}
      <li>{{ indexentries(entryname, links) }}
      {%- if subitems %}
      <ul>
      {%- for subentryname, subentrylinks in subitems %}
        <li>{{ indexentries(subentryname, subentrylinks) }}</li>
      {%- endfor %}
      </ul>
      {%- endif -%}</li>
    {%- endfor %}
  </ul></td>
  {%- endfor %}
</tr></table>
{% endfor %}

{% endblock %}

{% block sidebarrel %}
{% if split_index %}
   <h4>{{ _('Index') }}</h4>
   <p>{% for key, dummy in genindexentries -%}
   <a href="{{ pathto('genindex-' + key) }}"><strong>{{ key }}</strong></a>
     {% if not loop.last %}| {% endif %}
   {%- endfor %}</p>

   <p><a href="{{ pathto('genindex-all') }}"><strong>{{ _('Full index on one page') }}</strong></a></p>
{% endif %}
   {{ super() }}
{% endblock %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sphinxcontrib.kana_text-0.17.5.tar.gz (18.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page