使用sphinx将structuredtext转换为html的夹层应用程序

mezzanine-meze的Python项目详细描述


meze将Sphinx味道添加到Mezzanine。你可以写博客文章 在reStructuredText中的页面,并通过sphinx将它们转换为html。

用法示例

有关用法示例,请参见:http://ahmetbakan.com/blog/category/meze/

要求

Sphinx是转换structuredText源所必需的。

安装

您可以使用easy_installpip

easy_install -U mezzanine-meze
pip install mezzanine-meze

或者从https://pypi.python.org/pypi/mezzanine-meze下载包 并使用setup.py安装。

快速启动

在项目settings.py文件中进行以下更改:

  1. 将“meze”添加到INSTALLED_APPS

    INSTALLED_APPS = (
        ...
        'meze',
    )
    
  2. sourceconvert字段插入到 mezzanine.blog.models.BlogPostmezzanine.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

  3. 更新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

  4. 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.

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

推荐PyPI第三方库


热门话题
java如何在jetty请求日志中添加milliscond字段?   java在使用Scanner类从文件读取信息时遇到问题   为什么。类不适用于泛型类型?   SQLite插入上的java空指针异常   java能告诉我们Guava缓存是在禁用统计数据的情况下构建的吗?   java在应用程序中使用常量   java无法使用AutoIT和Selenium Webdriver在所需位置/文件夹保存图像   java如何在jtable中更新jprogress栏   java是比较给定日期和当前日期(在给定时区中没有时间段)的最佳方法   安卓代码中的java错误   java无法访问实体类中的字段   java如何在tomcat中处理三个JDBC连接池?   java无法使用Spring Security保护AngularJS页面   如何在没有TCP/IP协议栈的情况下用Java发送以太帧