繁体   English   中英

如何使用 Sphinx 在 reStructuredText 中添加博客样式标签

[英]How to add blog style tags in reStructuredText with Sphinx

对于用 reStructuredText 编写并使用 Sphinx 渲染为 HTML 的编程语言文档项目,我想将我的函数分组到逻辑组中,例如:String(所有字符串函数)、Web(所有与 Web 相关的函数)、List(任何与列表有关的函数)处理)等。现在,由于函数可以是多个组的成员,我想以某种方式添加标签,就像您添加博客文章一样。

如果有一个 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

您可以利用 sphinx 的索引功能。

休息:

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

Some rest goes here.

配置文件:

html_use_index = True

我已经通过一些自定义预处理和自定义指令解决了这个问题。 我的个人网站是用 Sphinx 制作的,我的博客也是。 博客意味着标签。

首先是我使用的自定义 Sphinx 指令“标签”:

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>

所以核心思想是生成标签文件并尽可能多地重用常规的 Sphinx 行为。 (我对index.txtyyyy/index.txtyyyy/mm/index.txt等使用相同的方法)。

如果您需要一些示例代码: https : //github.com/reinout/reinout.vanrees.org/blob/master/rvo/weblog.py

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM