使用sphinx将structuredtext转换为html的夹层应用程序
mezzanine-meze的Python项目详细描述
meze将Sphinx味道添加到Mezzanine。你可以写博客文章 在reStructuredText中的页面,并通过sphinx将它们转换为html。
用法示例
有关用法示例,请参见:http://ahmetbakan.com/blog/category/meze/
要求
Sphinx是转换structuredText源所必需的。
安装
您可以使用easy_install或pip:
easy_install -U mezzanine-meze pip install mezzanine-meze
或者从https://pypi.python.org/pypi/mezzanine-meze下载包 并使用setup.py安装。
快速启动
在项目settings.py文件中进行以下更改:
将“meze”添加到INSTALLED_APPS:
INSTALLED_APPS = ( ... 'meze', )
将source和convert字段插入到 mezzanine.blog.models.BlogPost和 mezzanine.pages.models.RichTextPage.source型号:
help_text = ("Source in reStructuredText format will be converted to " "HTML and result will replace content field.") EXTRA_MODEL_FIELDS = ( # Enable Meze for blog posts ("mezzanine.blog.models.BlogPost.source", "TextField", (), {"blank": True, "help_text": help_text}), ("mezzanine.blog.models.BlogPost.convert", "BooleanField", ("Convert source",), {"default": True}), # Enable Meze for rich text pages ("mezzanine.pages.models.RichTextPage.source", "TextField", (), {"blank": True, "help_text": help_text}), ("mezzanine.pages.models.RichTextPage.convert", "BooleanField", ("Convert source",), {"default": True}), ) del help_text
如果在创建数据库之后已经开始使用meze,则可能需要 迁移。参见夹层文档中的现场注入caveats。
更新settings.py文件。
添加MEZE_SETTINGS:
MEZE_SETTINGS = { 'workdir': os.path.join(PROJECT_ROOT, 'meze_workdir'), }
显示默认值。您将需要对workdir的写访问权限。
为狮身人面像添加configuration选项:
SPHINX_CONF = """ project = u'' copyright = u'' version = '0' release = '0' master_doc = 'index' pygments_style = 'sphinx' html_theme = 'default' html_sidebars = {'**': []} html_domain_indices = False html_use_index = False html_show_sourcelink = False html_add_permalinks = None source_suffix = '.rst' intersphinx_mapping = {'python': ('http://docs.python.org/', None)} extlinks = {'wiki': ('http://en.wikipedia.org/wiki/%s', ''),} extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.extlinks'] """
此文件写入mezeworkdir。
sphinx使用Pygments进行语法突出显示,因此需要 将pygments.css文件添加到模板:
{% compress css %} ... <link rel="stylesheet" href="{% static "meze/css/meze.css" %}"> <link rel="stylesheet" href="{% static "meze/css/pygments.css" %}"> ...
如果您正在编写python代码片段,还可以添加copybutton.js 文件,启用代码的复制友好显示选项:
{% compress js %} ... <script src="{% static "meze/js/copybutton.js" %}"></script> ...
它是如何工作的?
meze通过创建一个简单的 配置文件(conf.py)。
structuredtext文件被写入workdir,html文件被构建 使用sphinx,html文件的内容存储在数据库中。
更改
V0.3(2014年1月10日)
- Moved static files to meze folder.
- Added static files to setup.py.
V0.2.2(2013年10月11日)
- Searching images in both ^{tt19}$ and ^{tt20}$ folders.
- Improved revising image sources in HTML to avoid exceptions when an image file is not found.
V0.2.1(2013年7月17日)
- Fixed a bug in Meze class that prevented changes in Sphinx configuration to take place.
V0.2(2013年7月12日)
- Improved handling of image files.
v0.1(2013年7月11日)
- First release.