以wiki格式发布rst文档。

wikir的Python项目详细描述


Summary

wikir(发音为“wicker”)将reStructuredText文档转换为各种wiki格式。目前,Google Code Wiki Syntax是目标,但在可能的情况下保持与Moin Moin Wiki SyntaxTrac Wiki Syntax的兼容性。

Installation

easy_install wikir

或者查看subversion repository中的开发版本。

How Much reStructuredText Is Supported?

不是很多!由于RST syntax很大,而Google Code Wiki Syntax很小,因此rst可能永远不会得到完全支持。但是,如果遇到不受支持的rst指令,请submit an issue,并包括rst的片段以及您认为它应该如何在wiki语法中显示。

如果可能的话,还要提交一个失败的测试,测试您希望支持的新语法。通过运行以下命令(需要nose),可以看到所有当前测试和实现的rst语法元素:

nosetests -v ./wikir/tests/test_syntax.py -a '!deferred'

删除-a '!deferred'以查看那些仍然需要实现的。欣然接受的补丁;)

Using Wikir In Your Project

The publish_wiki Command

安装wikir后,同一台计算机上所有启用setuptools的项目都将生成一个新命令publish_wiki。setuptools项目是一个包含setup.py文件的项目,如下所示:

from setuptools import setup
setup(
    name='MyModule',
    version='0.999',
    # ...etc...
)

命令用法:

$ python setup.py publish_wiki --help
| Common commands: (see '--help-commands' for more)
|
|   setup.py build      will build the package underneath 'build/'
|   setup.py install    will install the package
|
| Global options:
|   --verbose (-v)  run verbosely (default)
|   --quiet (-q)    run quietly (turns verbosity off)
|   --dry-run (-n)  don't actually do anything
|   --help (-h)     show detailed help message
|
| Options for 'publish_wiki' command:
|   --source (-s)  path to RST source.  if a python module, the top-most
|                  docstring will be used as the source
|
| usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
|    or: setup.py --help [cmd1 cmd2 ...]
|    or: setup.py --help-commands
|    or: setup.py cmd --help
|

Publishing RST To Wiki

下面是将以rst格式编写的模块docstring发布为wiki格式的示例:

$ cd examples/basic
$ cat ./akimbo/__init__.py
| '''
| Welcome To Akimbo
| =================
|
| A Python module for akimbo'ing.
|
| This could live on `Google Code`_ if it wanted to.
|
| .. _Google Code: http://code.google.com/hosting/
|
| '''
$ python setup.py publish_wiki --source=./akimbo/__init__.py
| = Welcome To Akimbo =
|
| A Python module for akimbo'ing.
|
| This could live on [http://code.google.com/hosting/ Google Code] if it wanted to.
|

Using Custom RST Directives

wikir提供了一个入口点,以防需要注册custom RST directive。下面是一个例子:

$ cd examples/custom_directives
$ python setup.py -q develop
$ cat setup.py
| from setuptools import setup
| setup(
|     name = 'Foozilate',
|     entry_points = {
|         'wikir.rst_directives': [
|             'foozilate = foozilate.directives:foozilate'
|         ]
|     },
|     description = "A mysterious package that aids in foozilation")
$ cat ./README.txt
| This is the documentation for foozilate, which requires a custom directive called ``foozilate``.  All it does is wrap some tags around the input.
|
| .. foozilate::
|     this should be foozilated
$ python setup.py publish_wiki --source ./README.txt
| This is the documentation for foozilate, which requires a custom directive called `foozilate`.  All it does is wrap some tags around the input.
|
| --foozilated-- this should be foozilated --foozilated--
|
$ python setup.py -q develop --uninstall

注意

如果希望使用标准docutils安装来生成自定义指令,则应避免将其放入docstring中。例如,您的rst docstrings可以由The Cheeseshop或其他文档生成器(如pydoctor)自动解析。

入口点的左侧定义了指令名,右侧指定了指令函数的路径。在发布任何RST之前,都会向docutils注册

The wikir command

如果不想通过setup.py使用wikir,可以使用为您安装的命令行脚本wikir

命令usge:

$ wikir --help
| Usage: wikir [options] path/to/module.py
|        wikir [options] path/to/file.txt
|
| Publish RST documents in Wiki format
|
| 1. finds the top-most docstring of module.py, parses as RST, and prints Wiki format to STDOUT
| 2. parses file.txt (or a file with any other extension) as RST and prints Wiki format to STDOUT
|
| Options:
|   -h, --help  show this help message and exit

可以将以RST格式编写的模块docstring发布为Wiki格式,如下所示:

$ cd examples/basic
$ cat ./akimbo/__init__.py
| '''
| Welcome To Akimbo
| =================
|
| A Python module for akimbo'ing.
|
| This could live on `Google Code`_ if it wanted to.
|
| .. _Google Code: http://code.google.com/hosting/
|
| '''
$ wikir ./akimbo/__init__.py
| = Welcome To Akimbo =
|
| A Python module for akimbo'ing.
|
| This could live on [http://code.google.com/hosting/ Google Code] if it wanted to.
|

…并且您可以将以rst格式编写的任何文档发布为wiki格式,如下所示:

$ cd examples/basic
$ cat ./README.txt
| ========================
| Documentation for Akimbo
| ========================
|
| .. contents:: :local:
|
| What is it?
| ===========
|
| A Python module for akimbo'ing.
|
| Where does it live?
| ===================
|
| Akimbo could live on `Google Code`_ if it wanted to.
|
| .. _Google Code: http://code.google.com/hosting/
$ wikir ./README.txt
| = Documentation for Akimbo =
|
|   * What is it?
|   * Where does it live?
|
|
| = What is it? =
|
| A Python module for akimbo'ing.
|
| = Where does it live? =
|
| Akimbo could live on [http://code.google.com/hosting/ Google Code] if it wanted to.
|

Using Wikir Programatically

>>> from wikir import publish_string
>>> print publish_string('''
... My RST Document
... ===============
...
... For `Google Code`_!
...
... .. _Google Code: http://code.google.com/
... ''')
= My RST Document =
<BLANKLINE>
For [http://code.google.com/ Google Code]!
<BLANKLINE>
<BLANKLINE>
>>>

Credits

这项工作基于我在nose repository(Jason Pellerin)、Ian Bicking’s docutils sandboxMatthew Gilbert’s docutils sandbox周围搜索时发现的代码感谢Kent S. Johnson的帮助和反馈

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java在JSP中添加自定义隐式对象   java MasterMindResource泄漏?   不同的c#java结果加密   java为什么安卓 studio显示“constraintlayout中缺少约束”错误?   java Make Logback将日志打印到文件中   java如何在Google应用程序引擎中设置日期时间?   jeditorpane如何阻止java HTMLEditorKit自动关闭我的标记   返回到Activity onCreate()时,不会调用java函数   java为什么我在这个对象上得到一个NullPointerException?   在java中,如何使用包含数组的参数调用图形方法?   java如何在Play framework 2应用程序中存储Akka参与者列表?   ssh使用java将文件从一个solaris 9复制到另一个solaris 9   网络Java服务器正在等待客户端响应   java Spring mvc从formBackingObject()重定向到页面   java Spark:JavaRDD<Tuple2>到javapairdd<>   java如何动态调用基类中由字符串值指定的子类方法?