2013-08-09 5 views
5

reStructuredTextで書かれ、SphinxでHTMLにレンダリングされるプログラミング言語のドキュメントプロジェクトについては、文字列(すべての文字列関数)、Web(すべてWeb関連の関数)、List(リスト処理に関係するもの)など。関数はいくつかのグループのメンバーになることができるので、ブログ記事と同じように、何らかの方法でタグを追加したい。reStructuredTextにSphinxでブログスタイルタグを追加する方法

タグを追加するためにSphinx拡張機能(またはドメインを使用する方法など)があった場合、すべてのタグの概要、すべてのタグの概要、相互参照各機能ページの下部にあります。これは実現可能なのか、もしそうなら、どのように?

例:

--------- 
substring 
--------- 

**substring (**\ *<string,number>* **text,** *number* **start,** *number* **end*)** 

Description 
----------- 

Returns the substring of string ``text`` between integer positions ``start`` and position ``end``. The first character in the string is numbered 0. The last character returned by ``substring`` is the character before position ``end``. Optionally ``end`` can be left out, which means the returned string will end at the last position of ``text``. 

Example 
------- 

- 

    Executing the following code: 

    :: 

     log(substring("Welcome to our site!", 0, 7)); 
     log(substring("Welcome to our site!", 0)); 

    will print: 

    :: 

     Welcome 
     Welcome to our site! 

Tags 
---- 

String 

答えて

4

私はいくつかのカスタム前処理およびカスタムディレクティブでこれを解決してきました。私の個人的なウェブサイトは私のウェブログと同様にスフィンクスで作られています。ウェブログはタグを意味します。

まず、私がこのように使用カスタムスフィンクスディレクティブ「タグ」:

My blog entry header 
==================== 

.. tags:: python, django 

Bla bla bla bla 

ブログのエントリがあるので、ディレクティブ自体は作品の形式../../tags/python.html、の相対リンクの束に自分自身を変換常にyyyy/mm/dd/ディレクトリにあります。

小さな前処理スクリプト私はSphinxメイクファイルから呼び出します。このスクリプトは単にtags/TAGNAME.txtファイルを生成します。 Sphinxはそれを通常のSphinxファイルとして処理するので、有効な再構成されたテキストを生成するだけで済みます。たとえば、

python 
###### 

.. toctree:: 
    :maxdepth: 1 

    2013-08-23 Praise for github pull requests <../2013/08/23/praise-for-pull-requests.txt> 
    2013-08-21 How to say ``[:]`` programmatically in Python <../2013/08/21/programmatical-all-range.txt> 
    2013-08-15 Handy tracebacks instead of uninformative segfaults <../2013/08/15/handy-tracebacks-with-faulthandler.txt> 

したがって、タグファイルを生成し、可能な限り多くの標準的なスフィンクスの振る舞いを再利用することがコアの考えです。 (私はindex.txt,yyyy/index.txt,yyyy/mm/index.txtなどと同じアプローチを使用しています)。あなたはスフィンクスのインデックス機能を利用することができますhttps://github.com/reinout/reinout.vanrees.org/blob/master/rvo/weblog.py

+0

ねえ、答えのためのおかげで、我々はそれが望んでいたとして、これが機能するかどうかを確認する必要があります。しかし、非常に有望に見えます。 – titusn

6

はケースで、あなたは、いくつかのサンプルコードが必要です。

レクリエーション:

.. index:: BNF, grammar, syntax, notation 

Some rest goes here. 

はconf.py:

html_use_index = True 
+0

うわー、これはさらに有望ですね!とても簡単。これを試さなければならないが、すでにそれを投票した。 – titusn

関連する問題