一组模板标记和过滤器,用于在django模板中使用重新构造的文本。
django-rstif的Python项目详细描述
警告
Django Rstify没有在积极开发中!请看一下它的继任者django markup。https://github.com/bartTC/django-markup
django rstify-django模板的重组文本筛选器
django rstify是一组模板过滤器,可以方便地从 restructured text到html。除了这个基本功能之外,这个应用程序 允许您使用pygments突出显示文本中的源代码片段 图书馆。
提示
django已经提供了一个简单的restructured text filter。如果你 不需要这个应用程序中的附加组件,我建议使用core版本。
安装
有几种安装此应用程序的方法:
从我的git存储库中签出最新版本:
git clone git://github.com/bartTC/django-rstify.git
Then either put the directory ^{tt1}$ into your pythonpath or switch to ^{tt2}$ and do ^{tt3}$.
使用“简易安装”安装此应用程序:
easy_install django-rstify
最后,将rstify放入django项目中的INSTALLED_APPS设置中。
如何在模板中使用它
要将重新构造的文本从对象转换为html,只需应用rstify 过滤:
{% load rstify_tags %} {{ entry.content|rstify }}
如果要转换内联内容,请使用filtertemplateTag在以下位置:
{% load rstify_tags %} {% filter rstify %} This is some *restructured text*. {% endfilter %}
如何在源代码中使用它
在代码中应用此筛选器很容易:
>>> from rstify import rstify >>> >>> print rstify('This is *restructured text*.') <p>This is <em>restructured text</em>.</p>
初始标题级别
默认情况下,重新构造的文本中的初始标题变为<h1>in HTML:
>>> header = ''' ... ================ ... This is a Header ... ================ ... ''' >>> print rstify(header) <div class="section"> <h1><a id="this-is-a-header" name="this-is-a-header">This is a Header</a></h1> </div>
可以通过将initial_header_level设置为 1到6:
>>> print rstify(header, initial_header_level=3) <div class="section"> <h3><a id="this-is-a-header" name="this-is-a-header">This is a Header</a></h3> </div>
在模板中,只需将其设置为rstifyfilter的第一个选项:
{{ entry.content|rstify:"3" }}
语法突出显示
django rstify使用pygments库提供语法突出显示。突出显示 部分重组文本,只需将其放入sourcecode指令:
Here is some text. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer porttitor nulla sed dui. Aenean lorem mi, tincidunt et, porttitor nec, condimentum venenatis, felis. Maecenas ornare blandit leo. .. sourcecode:: python def foo(bar): return bar*2 Continue with text. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer porttitor nulla sed dui. Aenean lorem mi, tincidunt et, porttitor nec, condimentum venenatis, felis. Maecenas ornare blandit leo.
pygments提供了一堆highlighter(也称为lexer),只需替换 python使用您选择的lexer。这是一套完整的available lexers。 阅读pygments styles如何使用css为输出着色。
许可证
此应用程序是根据New BSD License授权的。有关详细信息,请参见LICENSE。 django rstify与pygments指令捆绑在一起,pygments指令在BSD License下发布。 有关详细信息,请参见rstify/pygments_directive.py。