一组模板标记和过滤器,用于在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版本

安装

有几种安装此应用程序的方法:

  1. 从我的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}$.
  1. 使用“简易安装”安装此应用程序:

    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

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

推荐PyPI第三方库


热门话题
java我能在这个程序中更好地使用内存吗?   为什么我的Java while循环迭代了一半   java IntelliJ IDEA不在构建时复制资源   socket仅在Java TCP服务器输出上检查客户端断开连接   java游戏物理摩擦   java片段onClick调用方法   symja数学分析器中无法识别java Abs[x]   java在使用泛型时创建二进制搜索树类的实例?   java在外键约束表上的添加和删除   语法java表达式的含义,如果有条件   java创建内联对象并作为参数传递   是否有相当于Redis排序集(zset)的Java数据结构   java找不到适合的方法(无参数)   音频文件操作给定字节帧的音量Java   Eclipse4不以JavaWebStart启动   java如何使用org在JSON对象中获取嵌套的键元素。json?   java与Jackson的反序列化:“org.codehaus.Jackson.map.JsonMappingException:无法反序列化[projectname]的实例。”   字符串的Java正则表达式   spring集成上的java检测缺火指令