##language:zh

-- 211.150.223.154 [<<DateTime(2004-09-13T00:11:26Z)>>]
<<TableOfContents>>
= PyTextile =
''PyTextile是一个Textile的Python实现模块''
== PyTextile介绍 ==
Python 下的包最初是由Mark Pilgrim完成的,地址在:[[http://diveintomark.org/archives/2003/03/19/pytextile|Mark pytextile]]

上面有下载链接。不过现在已经由他人来继续维护了,[[http://dealmeida.net/en/Projects/PyTextile/|pytextile]]。现在最新的版本为2.0.8。

有人在Mark的Blog评论中问:reStructuredText与Textile有什么不同呢?

Mark的回答是:

 * reStructuredText 是输出格式不确定(注:我理解是可以输出多种格式,如HTML,Tex,XML,PDF等),而Textile是为web显示专门设计的。 
 * reStructuredText有许多的选项是Textile缺乏的,如字段列表,定义列表,嵌套块引用等。 
 * Textile有几种reStructuredText没有的选项,如CODE, CITE, SUP之类的行内速记。可以将某些高位的ASCII码字符映射为HTML的数字实体。 
 * reStructured是为正式文档的特殊样式而设计的,它有脚注、参考书目引用、链接系统。而Textile是为象Blog和评论这种短的,不正式的文档而设计的。

Mark原文如下:

 * reStructuredText is designed to be output-format-agnostic; Textile is specifically designed for web display.

 * reStructuredText has many options that Textile lacks, such as field lists, definition lists, nested blockquotes, simple tables, and grid tables.

 * Textile has several options that reStructuredText lacks, such as inline shorthand for CODE, CITE, and SUP. Also, its ability to auto-map high-bit ASCII characters to HTML numeric entities (making it possible to cut-and-paste smart quotes without breaking validation).

 * reStructuredText is designed for a particular style of formal document: it has a system of cataloging footnotes, bibliographic citations, and hyperlinks. Textile is designed for shorter, more informal documents like blog posts and comments. 

我并未逐字翻译,还有一些自已的理解请见谅。

== PyTextile 安装及使用 ==

安装很简单,与一般的模块安装方法一样。

{{{
python setup.py install
}}}

使用示例:

{{{#!python
import textile
a = textile.Textiler(Text) #Text为要处理的文本
print a.process()
}}}

Textile可以自已将文档输出,将上面的Text设为:"tell me about textile."。然后执行后就是文档的Html文本了。拷贝下来,保存为html(或改下上面的示例,直接存为文件),在浏览器中就可以看了。

我就是这样用的,更复杂的还没有用到。不过,为了支持 NewEdit 使用我还是改了一下,派生了自已的MyTextiler派,以更很好地使用Unicode。

代码片段如下:

{{{#!python
    class MyTextiler(textile.Textiler):
        def process(self, head_offset=textile.HEAD_OFFSET):
            self.head_offset = head_offset
        
            # Process each block.
            self.blocks = self.split_text()
        
            text = []
            for [function, captures] in self.blocks:
                text.append(function(**captures))
        
            text = '\n\n'.join(text)
        
            # Add titles to footnotes.
            text = self.footnotes(text)
        
#           # Convert to desired output.
#           if encoding != 'unicode':
#               text = unicode(text, encoding)
#           if output != 'unicode':
#               text = text.encode(output, 'xmlcharrefreplace')
        
            return text
}}}

上面对unicode的判断注释掉了是因为NewEdit中全部是Unicode,这样不再需要进行编码转换了,如果要保存文件的话,是要进行编辑转换的。那么应该把上面的注释去掉。并不存在'unicode'编码,这里只是为了指明是否是unicode编码而使用。

== PyTextile 文档及翻译 ==
现在有英文的文档,是用Textile生成的,翻译一点点来,有兴趣地也贡献啊。

* [[PyTextileDoc]]

== 下载 ==

为了方便大家使用,先在这里放一个最新的版本。[[attachment:textile-2.0.8.tar.gz]]

== 讨论 ==