Welcome to Flask RSTPages’s documentation!

Flask-RSTPages adds support for reStructuredText to your Flask application, allowing to convert a reStructuredText file to html. Source code is rendered via Pygments.

Installation

Install the extension with one of the following commands:

$ easy_install Flask-RSTPages

or alternatively if you have pip installed:

$ pip install Flask-RSTPages

How to Use

To get started you must construct a RSTPages object with your Flask instance:

from flask.ext.rstpages import RSTPages
pages = RSTPages(app)

Then, you can use the RSTPages.get() method to convert your reStructuredText file to html:

@app.route('/<path:page>/')
def get_page(page):
    html = pages.get(page)
    return render_template("page.html", page=html)

The RSTPages.get() method returns an object with title and body attributes.

Configuration

Flask-RSTPages accepts the following configuration values.

RSTPAGES_SRC
Path to the directory where to look for page files. Defaults to pages.
RSTPAGES_VIEW_FUNCTION
The view function used to route pages. This is used to support the :doc:`page` markup of Sphinx to cross-reference documents. Defaults to get_rstpage.
RSTPAGES_RST_SETTINGS
Dict with configuration for the docutils html4css1 writer. Defaults to {'initial_header_level': 2}.

API Reference

class flask_rstpages.RSTPages(app=None)

reStructuredText to html renderer

Parameters:app (Flask instance) – your application. Can be omited if you call init_app() later.
get(page)

Convert a reStructuredText file to html

Return a rstDocument object with the html title and body.

Parameters:page (path) – path to a reStructuredText file
init_app(app)

Initialize an application

Changelog

Version 0.2

Released on 2012-12-13.

Add a setting to configure the docutils html writer.

Version 0.1

Released on 2012-11-03.

First public release.

Fork me on GitHub